Found in #2506445: Replace !placeholder with @placeholder in t() and format_string() for non-URLs in tests
Part of #2506427: [meta] !placeholder causes strings to be escaped and makes the sanitization API harder to understand.

core/modules/block_content/src/Tests/BlockContentTypeTest.php uses !placeholder unnecessarily. Reorganise the test to actually click on the link and use the form and complete the testing of UI and API the test claims it does.

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new4 KB
dawehner’s picture

  1. diff --git a/core/modules/aggregator/src/Tests/UpdateFeedItemTest.php b/core/modules/aggregator/src/Tests/UpdateFeedItemTest.php
    index 0e94425..ea48f46 100644
    
    index 0e94425..ea48f46 100644
    --- a/core/modules/aggregator/src/Tests/UpdateFeedItemTest.php
    
    --- a/core/modules/aggregator/src/Tests/UpdateFeedItemTest.php
    +++ b/core/modules/aggregator/src/Tests/UpdateFeedItemTest.php
    
    +++ b/core/modules/aggregator/src/Tests/UpdateFeedItemTest.php
    @@ -37,7 +37,7 @@ public function testUpdateFeedItem() {
    
    @@ -37,7 +37,7 @@ public function testUpdateFeedItem() {
         );
     
         $this->drupalGet($edit['url[0][value]']);
    -    $this->assertResponse(array(200), format_string('URL !url is accessible', array('!url' => $edit['url[0][value]'])));
    +    $this->assertResponse(200);
     
    

    leaked in ....

  2. +++ b/core/modules/block_content/src/Tests/BlockContentTypeTest.php
    @@ -52,35 +52,39 @@ public function testBlockContentTypeCreation() {
    -    $this->assertRaw(t('You have not created any block types yet. Go to the <a href="!url">block type creation page</a> to add a new block type.', [
    -      '!url' => Url::fromRoute('block_content.type_add')->toString(),
    -    ]));
    ...
    +    $this->assertText('You have not created any block types yet');
    

    Agreed that checking the entire help text is poingless.

  3. +++ b/core/modules/block_content/src/Tests/BlockContentTypeTest.php
    @@ -52,35 +52,39 @@ public function testBlockContentTypeCreation() {
    +    $this->clickLink('block type creation page');
    

    Yeah we should better think about the separation of API and UI tests, this is a good step, IMHO

  4. +++ b/core/modules/block_content/src/Tests/BlockContentTypeTest.php
    @@ -52,35 +52,39 @@ public function testBlockContentTypeCreation() {
    +    $this->assertResponse(200, 'The new block type can be accessed at block/add.');
    

    Pointless message, IMHO

alexpott’s picture

StatusFileSize
new1.43 KB
new3.14 KB

Thanks @dawehner.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you @alexpott

xjm’s picture

Status: Reviewed & tested by the community » Fixed

This does indeed make it easier to understand the intent of each part of the test. Committed and pushed to 8.0.x. Thanks!

  • xjm committed db5cf54 on 8.0.x
    Issue #2568027 by alexpott, dawehner: Improve BlockContentTypeTest
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.