Commit 37a54000 authored by catch's avatar catch
Browse files

Issue #3138078 by mondrake, larowlan, longwave, xjm: [D9.3 beta - w/c Nov 8,...

Issue #3138078 by mondrake, larowlan, longwave, xjm: [D9.3 beta - w/c Nov 8, 2021] Add a 'void' return typehint to custom assert* methods

(cherry picked from commit 92836c43)
parent 2eec3dc4
......@@ -57,8 +57,10 @@ public function testActions() {
* The expected Action type.
* @param array $configuration
* The expected Action configuration.
*
* @internal
*/
protected function assertEntity($id, $label, $type, $configuration) {
protected function assertEntity(string $id, string $label, string $type, array $configuration): void {
$action = Action::load($id);
$this->assertInstanceOf(Action::class, $action);
......
......@@ -57,8 +57,10 @@ public function testActions() {
* The expected Action type.
* @param array $configuration
* The expected Action configuration.
*
* @internal
*/
protected function assertEntity($id, $label, $type, $configuration) {
protected function assertEntity(string $id, string $label, string $type, array $configuration): void {
$action = Action::load($id);
$this->assertInstanceOf(Action::class, $action);
......
......@@ -327,7 +327,10 @@ public function testBigPipeMultiOccurrencePlaceholders() {
$this->assertSession()->responseNotContains('The count is 3.');
}
protected function assertBigPipeResponseHeadersPresent() {
/**
* @internal
*/
protected function assertBigPipeResponseHeadersPresent(): void {
// Check that Cache-Control header set to "private".
$this->assertSession()->responseHeaderContains('Cache-Control', 'private');
$this->assertSession()->responseHeaderEquals('Surrogate-Control', 'no-store, content="BigPipe/1.0"');
......@@ -340,8 +343,10 @@ protected function assertBigPipeResponseHeadersPresent() {
* @param array $expected_big_pipe_nojs_placeholders
* Keys: BigPipe no-JS placeholder markup. Values: expected replacement
* markup.
*
* @internal
*/
protected function assertBigPipeNoJsPlaceholders(array $expected_big_pipe_nojs_placeholders) {
protected function assertBigPipeNoJsPlaceholders(array $expected_big_pipe_nojs_placeholders): void {
$this->assertSetsEqual(array_keys($expected_big_pipe_nojs_placeholders), array_map('rawurldecode', explode(' ', $this->getSession()->getResponseHeader('BigPipe-Test-No-Js-Placeholders'))));
foreach ($expected_big_pipe_nojs_placeholders as $big_pipe_nojs_placeholder => $expected_replacement) {
// Checking whether the replacement for the BigPipe no-JS placeholder
......@@ -361,8 +366,10 @@ protected function assertBigPipeNoJsPlaceholders(array $expected_big_pipe_nojs_p
* @param array $expected_big_pipe_placeholder_stream_order
* Keys: BigPipe placeholder IDs. Values: expected AJAX response. Keys are
* defined in the order that they are expected to be rendered & streamed.
*
* @internal
*/
protected function assertBigPipePlaceholders(array $expected_big_pipe_placeholders, array $expected_big_pipe_placeholder_stream_order) {
protected function assertBigPipePlaceholders(array $expected_big_pipe_placeholders, array $expected_big_pipe_placeholder_stream_order): void {
$this->assertSetsEqual(array_keys($expected_big_pipe_placeholders), explode(' ', $this->getSession()->getResponseHeader('BigPipe-Test-Placeholders')));
$placeholder_positions = [];
$placeholder_replacement_positions = [];
......@@ -437,36 +444,49 @@ protected function getTestCases($has_session = TRUE) {
/**
* Asserts whether arrays A and B are equal, when treated as sets.
*
* @todo This method is broken. Fix it in
* https://www.drupal.org/project/drupal/issues/3144926
*
* @internal
*/
protected function assertSetsEqual(array $a, array $b) {
return count($a) == count($b) && !array_diff_assoc($a, $b);
protected function assertSetsEqual(array $a, array $b): void {
$result = count($a) == count($b) && !array_diff_assoc($a, $b);
}
/**
* Asserts whether a BigPipe no-JS cookie exists or not.
*
* @internal
*/
protected function assertBigPipeNoJsCookieExists($expected) {
protected function assertBigPipeNoJsCookieExists(string $expected): void {
$this->assertCookieExists('big_pipe_nojs', $expected, 'BigPipe no-JS');
}
/**
* Asserts whether a session cookie exists or not.
*
* @internal
*/
protected function assertSessionCookieExists($expected) {
protected function assertSessionCookieExists(string $expected): void {
$this->assertCookieExists($this->getSessionName(), $expected, 'Session');
}
/**
* Asserts whether a cookie exists on the client or not.
*
* @internal
*/
protected function assertCookieExists($cookie_name, $expected, $cookie_label) {
protected function assertCookieExists(string $cookie_name, string $expected, string $cookie_label): void {
$this->assertEquals($expected, !empty($this->getSession()->getCookie($cookie_name)), $expected ? "$cookie_label cookie exists." : "$cookie_label cookie does not exist.");
}
/**
* Calls ::performMetaRefresh() and asserts the responses.
*
* @internal
*/
protected function assertBigPipeNoJsMetaRefreshRedirect() {
protected function assertBigPipeNoJsMetaRefreshRedirect(): void {
$original_url = $this->getSession()->getCurrentUrl();
// Disable automatic following of redirects by the HTTP client, so that this
......
......@@ -288,8 +288,10 @@ public function testBlockViewBuilderBuildAlter() {
* The expected cache tags.
* @param int $expected_max_age
* The expected max-age.
*
* @internal
*/
protected function assertBlockRenderedWithExpectedCacheability(array $expected_keys, array $expected_contexts, array $expected_tags, $expected_max_age) {
protected function assertBlockRenderedWithExpectedCacheability(array $expected_keys, array $expected_contexts, array $expected_tags, int $expected_max_age): void {
$required_cache_contexts = ['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'user.permissions'];
// Check that the expected cacheability metadata is present in:
......
......@@ -69,14 +69,16 @@ protected function setUp(): void {
* The display region.
* @param string $theme
* The theme.
* @param string $weight
* @param int $weight
* The block weight.
* @param array $settings
* (optional) The block settings.
* @param bool $status
* Whether the block is expected to be enabled or disabled.
*
* @internal
*/
public function assertEntity($id, $visibility, $region, $theme, $weight, array $settings = NULL, $status = TRUE) {
public function assertEntity(string $id, array $visibility, string $region, string $theme, int $weight, array $settings = NULL, bool $status = TRUE): void {
$block = Block::load($id);
$this->assertInstanceOf(Block::class, $block);
$this->assertSame($visibility, $block->getVisibility());
......
......@@ -73,7 +73,7 @@ protected function setUp(): void {
* The display region.
* @param string $theme
* The theme.
* @param string $weight
* @param int $weight
* The block weight.
* @param string $label
* The block label.
......@@ -81,8 +81,10 @@ protected function setUp(): void {
* The block label display setting.
* @param bool $status
* Whether the block is expected to be enabled or disabled.
*
* @internal
*/
public function assertEntity($id, $plugin_id, array $roles, $pages, $region, $theme, $weight, $label, $label_display, $status = TRUE) {
public function assertEntity(string $id, string $plugin_id, array $roles, string $pages, string $region, string $theme, int $weight, string $label, string $label_display, bool $status = TRUE): void {
$block = Block::load($id);
$this->assertInstanceOf(Block::class, $block);
/** @var \Drupal\block\BlockInterface $block */
......
......@@ -99,8 +99,10 @@ public function testFilters() {
* that translation should be shown on the given page.
* @param string $message
* Message suffix to display.
*
* @internal
*/
protected function assertPageCounts($path, $counts, $message) {
protected function assertPageCounts(string $path, array $counts, string $message): void {
// Get the text of the page.
$this->drupalGet($path);
$text = $this->getTextContent();
......
......@@ -59,8 +59,10 @@ public function testBlockContentViewTypeArgument() {
*
* @param array $expected_ids
* An array of block_content IDs.
*
* @internal
*/
protected function assertIds(array $expected_ids = []) {
protected function assertIds(array $expected_ids = []): void {
$result = $this->xpath('//span[@class="field-content"]');
$ids = [];
foreach ($result as $element) {
......
......@@ -38,8 +38,10 @@ protected function setUp(): void {
* The entity ID.
* @param string $component_id
* The ID of the display component.
*
* @internal
*/
protected function assertDisplay($id, $component_id) {
protected function assertDisplay(string $id, string $component_id): void {
$component = EntityViewDisplay::load($id)->getComponent($component_id);
$this->assertIsArray($component);
$this->assertSame('hidden', $component['label']);
......
......@@ -38,8 +38,10 @@ protected function setUp(): void {
* The entity ID.
* @param string $component_id
* The ID of the form component.
*
* @internal
*/
protected function assertDisplay($id, $component_id) {
protected function assertDisplay(string $id, string $component_id): void {
$component = EntityFormDisplay::load($id)->getComponent($component_id);
$this->assertIsArray($component);
$this->assertSame('text_textarea_with_summary', $component['type']);
......
......@@ -143,9 +143,11 @@ public function testBookOrdering() {
* @throws \Behat\Mink\Exception\ExpectationException
* When any of the given string is not found.
*
* @internal
*
* @todo Remove this once https://www.drupal.org/node/2817657 is committed.
*/
protected function assertOrderInPage(array $items) {
protected function assertOrderInPage(array $items): void {
$session = $this->getSession();
$text = $session->getPage()->getHtml();
$strings = [];
......
......@@ -289,6 +289,8 @@ protected function setCurrentLanguage(string $langcode): void {
* A book tree item.
* @param string $langcode
* The language code for the requested translation.
*
* @internal
*/
protected function assertBookItemIsCorrectlyTranslated(array $item, string $langcode): void {
$this->assertNodeLinkIsCorrectlyTranslated($item['original_link']['nid'], $item['title'], $item['url'], $langcode);
......@@ -305,6 +307,8 @@ protected function assertBookItemIsCorrectlyTranslated(array $item, string $lang
* The URL being tested.
* @param string $langcode
* The language code.
*
* @internal
*/
protected function assertNodeLinkIsCorrectlyTranslated(int $nid, string $title, Url $url, string $langcode): void {
$node = Node::load($nid);
......@@ -324,8 +328,10 @@ protected function assertNodeLinkIsCorrectlyTranslated(int $nid, string $title,
* The node ID.
* @param string $indent
* The indentation before the actual table of contents label.
*
* @internal
*/
protected function assertToCEntryIsCorrectlyTranslated(array $toc, string $langcode, int $nid, string $indent) {
protected function assertToCEntryIsCorrectlyTranslated(array $toc, string $langcode, int $nid, string $indent): void {
$node = Node::load($nid);
$node_label = $node->getTranslation($langcode)->label();
$this->assertSame($indent . ' ' . $node_label, $toc[$nid]);
......
......@@ -473,8 +473,10 @@ public function testExternalStylesheets() {
* @param string $langcode
* Language code to assert for. Defaults to French. That is the default
* language set in this assertion.
*
* @internal
*/
protected function assertCKEditorLanguage($langcode = 'fr') {
protected function assertCKEditorLanguage(string $langcode = 'fr'): void {
// Set French as the site default language.
ConfigurableLanguage::createFromLangcode('fr')->save();
$this->config('system.site')->set('default_langcode', 'fr')->save();
......
......@@ -664,11 +664,13 @@ public function testViewMode() {
*
* @param string $attribute
* The attribute to check.
* @param mixed $value
* @param string|null $value
* Either a string value or if NULL, asserts that <drupal-media> element
* doesn't have the attribute.
*
* @internal
*/
protected function assertSourceAttributeSame($attribute, $value) {
protected function assertSourceAttributeSame(string $attribute, ?string $value): void {
$dom = $this->getEditorDataAsDom();
$drupal_media = (new \DOMXPath($dom))->query('//drupal-media');
$this->assertNotEmpty($drupal_media);
......
......@@ -210,8 +210,10 @@ public function testCommentOrderingThreading() {
* An array of comments, must be of the type CommentInterface.
* @param array $expected_order
* An array of keys from $comments describing the expected order.
*
* @internal
*/
public function assertCommentOrder(array $comments, array $expected_order) {
public function assertCommentOrder(array $comments, array $expected_order): void {
$expected_cids = [];
// First, rekey the expected order by cid.
......
......@@ -131,8 +131,10 @@ public function testCommentThreading() {
* The comment ID to check.
* @param int $pid
* The expected parent comment ID.
*
* @internal
*/
protected function assertParentLink($cid, $pid) {
protected function assertParentLink(int $cid, int $pid): void {
// This pattern matches a markup structure like:
// @code
// <a id="comment-2"></a>
......@@ -152,8 +154,10 @@ protected function assertParentLink($cid, $pid) {
*
* @param int $cid
* The comment ID to check.
*
* @internal
*/
protected function assertNoParentLink($cid) {
protected function assertNoParentLink(int $cid): void {
// This pattern matches a markup structure like:
// @code
// <a id="comment-2"></a>
......
......@@ -108,8 +108,10 @@ public function testFilters() {
* that translation should be shown on the given page.
* @param string $message
* Message suffix to display.
*
* @internal
*/
protected function assertPageCounts($path, $counts, $message) {
protected function assertPageCounts(string $path, array $counts, string $message): void {
// Get the text of the page.
$this->drupalGet($path);
$text = $this->getTextContent();
......
......@@ -189,8 +189,10 @@ public function testValidation() {
* The field that violates the maximum length.
* @param int $length
* Number of characters that was exceeded.
*
* @internal
*/
protected function assertLengthViolation(CommentInterface $comment, $field_name, $length) {
protected function assertLengthViolation(CommentInterface $comment, string $field_name, int $length): void {
$violations = $comment->validate();
$this->assertCount(1, $violations, "Violation found when $field_name is too long.");
$this->assertEquals("{$field_name}.0.value", $violations[0]->getPropertyPath());
......
......@@ -41,8 +41,10 @@ protected function setUp(): void {
* The entity ID.
* @param string $component_id
* The ID of the display component.
*
* @internal
*/
protected function assertDisplay($id, $component_id) {
protected function assertDisplay(string $id, string $component_id): void {
$component = EntityViewDisplay::load($id)->getComponent($component_id);
$this->assertIsArray($component);
$this->assertSame('hidden', $component['label']);
......
......@@ -35,8 +35,10 @@ protected function setUp(): void {
*
* @param string $id
* The entity form display ID.
*
* @internal
*/
protected function assertSubjectVisible($id) {
protected function assertSubjectVisible(string $id): void {
$component = EntityFormDisplay::load($id)->getComponent('subject');
$this->assertIsArray($component);
$this->assertSame('string_textfield', $component['type']);
......@@ -48,8 +50,10 @@ protected function assertSubjectVisible($id) {
*
* @param string $id
* The entity form display ID.
*
* @internal
*/
protected function assertSubjectNotVisible($id) {
protected function assertSubjectNotVisible(string $id): void {
$component = EntityFormDisplay::load($id)->getComponent('subject');
$this->assertNull($component);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment