Follow up from #3128746: Replace assertions involving calls to strpos() with more accurate string assertions. There are a number of cases where we are using strstr() or stristr() to assert whether a string contains another string. We should replace these with assertStringContainsString()/assertStringNotContainsString() instead.
Found 8 occurrences:
grep -nri '\->assert.*stri\?str' core
core/modules/layout_builder/tests/src/FunctionalJavascript/BlockFormMessagesTest.php:108: $this->assertTrue(stristr($top_form_elements[0]->getText(), 'Title field is required.') !== FALSE);
core/modules/image/tests/src/Functional/ImageFieldDisplayTest.php:153: $this->assertTrue(strstr($this->drupalGetHeader('Cache-Control'), 'private') !== FALSE, 'Cache-Control header was sent.');
core/modules/system/tests/src/FunctionalJavascript/OffCanvasTest.php:61: $this->assertTrue(strstr($style, 'width: 555px;') !== FALSE, 'Dialog width respected.');
core/modules/system/tests/src/FunctionalJavascript/OffCanvasTest.php:65: $this->assertTrue(strstr($style, 'width: 555px;') === FALSE, 'Dialog width reset to default.');
core/modules/system/tests/src/FunctionalJavascript/OffCanvasTest.php:80: $this->assertTrue((bool) strstr($style, 'height: auto;'));
core/modules/system/tests/src/FunctionalJavascript/OffCanvasTest.php:83: $this->assertTrue((bool) strstr($style, 'height: 421px;'));
core/modules/settings_tray/tests/src/FunctionalJavascript/QuickEditIntegrationTest.php:154: $this->assertTrue(strstr($href, "/admin/structure/block/manage/custom/settings-tray?destination=$destination") !== FALSE);
core/modules/responsive_image/tests/src/Functional/ResponsiveImageFieldDisplayTest.php:265: $this->assertTrue(strstr($this->drupalGetHeader('Cache-Control'), 'private') !== FALSE, 'Cache-Control header was sent.');
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 3132778-5.patch | 839 bytes | quietone |
| #2 | 3132778-2.patch | 5.34 KB | kim.pepper |
Comments
Comment #2
kim.pepperPatch attached.
Comment #3
jungle@kim.pepper thank you!
Per @mondrake's comment here this was partially covered by #3131186: Replace assertions involving calls to drupalGetHeader() with session-based assertions, where possible, let' postpone this as well. :p
Comment #5
quietone commentedThere is one instance left.
Comment #7
daffie commentedThe changes in the patch look good.
I did not find any more occurrences of "strstr(" or "stristr(" in assertions.
For me it is RTBC.
Comment #9
catchCommitted/pushed to 9.3.x and cherry-picked to 9.2.x, thanks!