Merge pull request #2694 from creative-commoners/pulls/4/sapphire-test-nine

API phpunit9 support
This commit is contained in:
Steve Boyd 2021-10-28 11:26:30 +13:00 committed by GitHub
commit e7c49faab2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 84 additions and 82 deletions

View File

@ -21,15 +21,15 @@
"require": { "require": {
"silverstripe/admin": "^1.9@dev", "silverstripe/admin": "^1.9@dev",
"silverstripe/campaign-admin": "^1.7@dev", "silverstripe/campaign-admin": "^1.7@dev",
"silverstripe/framework": "^4.7@dev", "silverstripe/framework": "^4.10",
"silverstripe/reports": "^4.7@dev", "silverstripe/reports": "^4.7@dev",
"silverstripe/siteconfig": "^4.7@dev", "silverstripe/siteconfig": "^4.7@dev",
"silverstripe/versioned": "^1.7@dev", "silverstripe/versioned": "^1.7@dev",
"silverstripe/vendor-plugin": "^1.0", "silverstripe/vendor-plugin": "^1.0",
"php": "^7.1 || ^8" "php": "^7.3 || ^8.0"
}, },
"require-dev": { "require-dev": {
"sminnee/phpunit": "^5.7", "phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3" "squizlabs/php_codesniffer": "^3"
}, },
"extra": { "extra": {

View File

@ -1,9 +1,9 @@
<phpunit bootstrap="tests/bootstrap.php" colors="true"> <phpunit bootstrap="tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="Default"> <testsuite name="Default">
<directory>tests</directory> <directory>tests</directory>
</testsuite> </testsuite>
</testsuites>
<filter> <filter>
<whitelist addUncoveredFilesFromWhitelist="true"> <whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">.</directory> <directory suffix=".php">.</directory>

View File

@ -5,6 +5,7 @@ namespace SilverStripe\CMS\Tests\Behaviour;
use Behat\Behat\Hook\Scope\BeforeScenarioScope; use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Mink\Element\DocumentElement; use Behat\Mink\Element\DocumentElement;
use Behat\Mink\Element\NodeElement; use Behat\Mink\Element\NodeElement;
use PHPUnit\Framework\Assert;
use SilverStripe\BehatExtension\Context\BasicContext; use SilverStripe\BehatExtension\Context\BasicContext;
use SilverStripe\BehatExtension\Context\FixtureContext as BehatFixtureContext; use SilverStripe\BehatExtension\Context\FixtureContext as BehatFixtureContext;
use SilverStripe\CMS\Model\RedirectorPage; use SilverStripe\CMS\Model\RedirectorPage;
@ -90,7 +91,7 @@ class FixtureContext extends BehatFixtureContext
$page = $this->getMainContext()->getSession()->getPage(); $page = $this->getMainContext()->getSession()->getPage();
$element = $page->find('css', $selector); $element = $page->find('css', $selector);
assertNotNull($element, sprintf('Element %s not found', $selector)); Assert::assertNotNull($element, sprintf('Element %s not found', $selector));
} }
/** /**
@ -109,7 +110,7 @@ class FixtureContext extends BehatFixtureContext
'radio', 'radio',
$this->getMainContext()->getXpathEscaper()->escapeLiteral($radioLabel) $this->getMainContext()->getXpathEscaper()->escapeLiteral($radioLabel)
]); ]);
assertNotNull($radioButton); Assert::assertNotNull($radioButton);
assertEquals($value, $radioButton->getAttribute($attribute)); Assert::assertEquals($value, $radioButton->getAttribute($attribute));
} }
} }

View File

@ -3,6 +3,7 @@
namespace SilverStripe\CMS\Tests\Behaviour; namespace SilverStripe\CMS\Tests\Behaviour;
use Page; use Page;
use PHPUnit\Framework\Assert;
use SilverStripe\BehatExtension\Context\LoginContext as BehatLoginContext; use SilverStripe\BehatExtension\Context\LoginContext as BehatLoginContext;
class LoginContext extends BehatLoginContext class LoginContext extends BehatLoginContext
@ -20,16 +21,16 @@ class LoginContext extends BehatLoginContext
{ {
// Reset permission cache // Reset permission cache
$page = Page::get()->First(); $page = Page::get()->First();
assertNotNull($page, 'A page exists'); Assert::assertNotNull($page, 'A page exists');
$email = "{$permCode}@example.org"; $email = "{$permCode}@example.org";
$password = 'Password!456'; $password = 'Password!456';
$member = $this->generateMemberWithPermission($email, $password, $permCode); $member = $this->generateMemberWithPermission($email, $password, $permCode);
$canEdit = strstr($negative, 'not') ? false : true; $canEdit = strstr($negative, 'not') ? false : true;
if ($canEdit) { if ($canEdit) {
assertTrue($page->canEdit($member), 'The member can edit this page'); Assert::assertTrue($page->canEdit($member), 'The member can edit this page');
} else { } else {
assertFalse($page->canEdit($member), 'The member cannot edit this page'); Assert::assertFalse($page->canEdit($member), 'The member cannot edit this page');
} }
} }
} }

View File

@ -19,7 +19,7 @@ class CMSBatchActionsTest extends SapphireTest
protected static $fixture_file = 'CMSBatchActionsTest.yml'; protected static $fixture_file = 'CMSBatchActionsTest.yml';
public function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@ -32,7 +32,7 @@ class CMSMainTest extends FunctionalTest
protected static $orig = []; protected static $orig = [];
public function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -128,7 +128,7 @@ class CMSMainTest extends FunctionalTest
$this->logInAs('admin'); $this->logInAs('admin');
$response = $this->get('admin/pages/publishall?confirm=1'); $response = $this->get('admin/pages/publishall?confirm=1');
$this->assertContains( $this->assertStringContainsString(
'Done: Published 30 pages', 'Done: Published 30 pages',
$response->getBody() $response->getBody()
); );
@ -218,7 +218,7 @@ class CMSMainTest extends FunctionalTest
$this->assertTrue($livePage->canDelete()); $this->assertTrue($livePage->canDelete());
// Check that the 'restore' button exists as a simple way of checking that the correct page is returned. // Check that the 'restore' button exists as a simple way of checking that the correct page is returned.
$this->assertRegExp('/<button type="submit"[^>]+name="action_(restore|revert)"/i', $response->getBody()); $this->assertMatchesRegularExpression('/<button type="submit"[^>]+name="action_(restore|revert)"/i', $response->getBody());
} }
/** /**
@ -306,7 +306,7 @@ class CMSMainTest extends FunctionalTest
$location = $response->getHeader('X-ControllerURL'); $location = $response->getHeader('X-ControllerURL');
$this->assertNotEmpty($location, 'Must be a redirect on success'); $this->assertNotEmpty($location, 'Must be a redirect on success');
$this->assertContains('/show/', $location, 'Must redirect to /show/ the new page'); $this->assertStringContainsString('/show/', $location, 'Must redirect to /show/ the new page');
$this->logOut(); $this->logOut();
$this->autoFollowRedirection = $origFollow; $this->autoFollowRedirection = $origFollow;

View File

@ -28,7 +28,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest
CMSPageHistoryControllerTest\HistoryController::class, CMSPageHistoryControllerTest\HistoryController::class,
]; ];
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -73,7 +73,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest
$this->assertEquals($this->page->ID, $form->Fields()->dataFieldByName('ID')->Value()); $this->assertEquals($this->page->ID, $form->Fields()->dataFieldByName('ID')->Value());
$this->assertEquals($this->versionPublishCheck2, $form->Fields()->dataFieldByName('Version')->Value()); $this->assertEquals($this->versionPublishCheck2, $form->Fields()->dataFieldByName('Version')->Value());
$this->assertContains( $this->assertStringContainsString(
'Currently viewing the latest version', 'Currently viewing the latest version',
$form->Fields()->fieldByName('Root.Main.CurrentlyViewingMessage')->getContent() $form->Fields()->fieldByName('Root.Main.CurrentlyViewingMessage')->getContent()
); );
@ -84,19 +84,19 @@ class CMSPageHistoryControllerTest extends FunctionalTest
$this->assertEquals($this->page->ID, $form->Fields()->dataFieldByName('ID')->Value()); $this->assertEquals($this->page->ID, $form->Fields()->dataFieldByName('ID')->Value());
$this->assertEquals($this->versionPublishCheck, $form->Fields()->dataFieldByName('Version')->Value()); $this->assertEquals($this->versionPublishCheck, $form->Fields()->dataFieldByName('Version')->Value());
$this->assertContains( $this->assertStringContainsString(
sprintf("Currently viewing version %s.", $this->versionPublishCheck), sprintf("Currently viewing version %s.", $this->versionPublishCheck),
$form->Fields()->fieldByName('Root.Main.CurrentlyViewingMessage')->getContent() $form->Fields()->fieldByName('Root.Main.CurrentlyViewingMessage')->getContent()
); );
// check that compare mode updates the message // check that compare mode updates the message
$form = $controller->getEditForm($this->page->ID, null, $this->versionPublishCheck, $this->versionPublishCheck2); $form = $controller->getEditForm($this->page->ID, null, $this->versionPublishCheck, $this->versionPublishCheck2);
$this->assertContains( $this->assertStringContainsString(
sprintf("Comparing versions %s", $this->versionPublishCheck), sprintf("Comparing versions %s", $this->versionPublishCheck),
$form->Fields()->fieldByName('Root.Main.CurrentlyViewingMessage')->getContent() $form->Fields()->fieldByName('Root.Main.CurrentlyViewingMessage')->getContent()
); );
$this->assertContains( $this->assertStringContainsString(
sprintf("and %s", $this->versionPublishCheck2), sprintf("and %s", $this->versionPublishCheck2),
$form->Fields()->fieldByName('Root.Main.CurrentlyViewingMessage')->getContent() $form->Fields()->fieldByName('Root.Main.CurrentlyViewingMessage')->getContent()
); );
@ -142,12 +142,12 @@ class CMSPageHistoryControllerTest extends FunctionalTest
$i = 0; $i = 0;
foreach ($rows as $tr) { foreach ($rows as $tr) {
// data-link must be present for the javascript to load new // data-link must be present for the javascript to load new
$this->assertContains($expected[$i]['status'], (string) $tr->attributes()->class); $this->assertStringContainsString($expected[$i]['status'], (string) $tr->attributes()->class);
$i++; $i++;
} }
// test highlighting // test highlighting
$this->assertContains('active', (string) $rows[0]->attributes()->class); $this->assertStringContainsString('active', (string) $rows[0]->attributes()->class);
$this->assertThat((string) $rows[1]->attributes()->class, $this->logicalNot($this->stringContains('active'))); $this->assertThat((string) $rows[1]->attributes()->class, $this->logicalNot($this->stringContains('active')));
} }
@ -157,7 +157,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest
$checkbox = $this->cssParser()->getBySelector('#Form_VersionsForm_ShowUnpublished'); $checkbox = $this->cssParser()->getBySelector('#Form_VersionsForm_ShowUnpublished');
$this->assertThat($checkbox[0], $this->logicalNot($this->isNull())); $this->assertThat($checkbox[0], $this->logicalNot($this->isNull()));
$checked = $checkbox[0]->attributes()->checked; $checked = $checkbox[0]->attributes()->checked ?: '';
$this->assertThat($checked, $this->logicalNot($this->stringContains('checked'))); $this->assertThat($checked, $this->logicalNot($this->stringContains('checked')));
@ -187,7 +187,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest
$field = $newList->dataFieldByName('field'); $field = $newList->dataFieldByName('field');
$this->assertTrue($field instanceof HTMLReadonlyField); $this->assertTrue($field instanceof HTMLReadonlyField);
$this->assertContains('<ins>', $field->forTemplate()); $this->assertStringContainsString('<ins>', $field->forTemplate());
$groupField = $newList->fieldByName('group'); $groupField = $newList->fieldByName('group');
$this->assertTrue($groupField instanceof FieldGroup); $this->assertTrue($groupField instanceof FieldGroup);

View File

@ -39,7 +39,7 @@ class ContentControllerPermissionsTest extends FunctionalTest
} }
// should redirect to login // should redirect to login
$this->assertEquals($response->getStatusCode(), 302, 'Redirects to login page when not logged in for draft stage'); $this->assertEquals($response->getStatusCode(), 302, 'Redirects to login page when not logged in for draft stage');
$this->assertContains( $this->assertStringContainsString(
Config::inst()->get('SilverStripe\\Security\\Security', 'login_url'), Config::inst()->get('SilverStripe\\Security\\Security', 'login_url'),
$response->getHeader('Location') $response->getHeader('Location')
); );

View File

@ -31,7 +31,7 @@ class ContentControllerSearchExtensionTest extends SapphireTest
$this->assertEquals([ File::class ], $form->getClassesToSearch()); $this->assertEquals([ File::class ], $form->getClassesToSearch());
} }
public static function setUpBeforeClass() public static function setUpBeforeClass(): void
{ {
parent::setUpBeforeClass(); parent::setUpBeforeClass();
FulltextSearchable::enable(File::class); FulltextSearchable::enable(File::class);
@ -42,7 +42,7 @@ class ContentControllerSearchExtensionTest extends SapphireTest
* properly at the end of the test. This becomes apparent when a later test tries to * properly at the end of the test. This becomes apparent when a later test tries to
* ALTER TABLE File and add fulltext indexes with the InnoDB table type. * ALTER TABLE File and add fulltext indexes with the InnoDB table type.
*/ */
public static function tearDownAfterClass() public static function tearDownAfterClass(): void
{ {
File::remove_extension(FulltextSearchable::class); File::remove_extension(FulltextSearchable::class);
parent::tearDownAfterClass(); parent::tearDownAfterClass();

View File

@ -24,7 +24,7 @@ class ContentControllerTest extends FunctionalTest
ContentControllerTestPageWithoutController::class, ContentControllerTestPageWithoutController::class,
]; ];
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -148,7 +148,7 @@ class ContentControllerTest extends FunctionalTest
$link = $page->RelativeLink(); $link = $page->RelativeLink();
$response = $this->get($link); $response = $this->get($link);
$this->assertContains( $this->assertStringContainsString(
sprintf('<a href="%s">Testlink</a>', $linkedPage->Link()), sprintf('<a href="%s">Testlink</a>', $linkedPage->Link()),
$response->getBody(), $response->getBody(),
'"sitetree_link" shortcodes get parsed properly' '"sitetree_link" shortcodes get parsed properly'

View File

@ -17,12 +17,12 @@ class LeftAndMainPageIconsExtensionTest extends SapphireTest
{ {
$extension = new LeftAndMainPageIconsExtension(); $extension = new LeftAndMainPageIconsExtension();
$css = $extension->generatePageIconsCss(); $css = $extension->generatePageIconsCss();
$this->assertNotContains('some invalid string', $css); $this->assertStringNotContainsString('some invalid string', $css);
$this->assertContains( $this->assertStringContainsString(
'tests/php/Controllers/LeftAndMainPageIconsExtensionTest/icon_b.jpg?m=', 'tests/php/Controllers/LeftAndMainPageIconsExtensionTest/icon_b.jpg?m=',
$css $css
); );
$this->assertContains( $this->assertStringContainsString(
'tests/php/Controllers/LeftAndMainPageIconsExtensionTest/icon_c.jpg?m=', 'tests/php/Controllers/LeftAndMainPageIconsExtensionTest/icon_c.jpg?m=',
$css $css
); );

View File

@ -25,7 +25,7 @@ class ModelAsControllerTest extends FunctionalTest
* This setup will enable nested-urls for this test and resets the state * This setup will enable nested-urls for this test and resets the state
* after the tests have been performed. * after the tests have been performed.
*/ */
public function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
Config::modify()->set(SiteTree::class, 'nested_urls', true); Config::modify()->set(SiteTree::class, 'nested_urls', true);

View File

@ -13,7 +13,7 @@ use SilverStripe\GraphQL\Schema\SchemaConfig;
class LinkablePluginTest extends SapphireTest class LinkablePluginTest extends SapphireTest
{ {
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@ -14,7 +14,7 @@ class RedirectorPageTest extends FunctionalTest
protected $autoFollowRedirection = false; protected $autoFollowRedirection = false;
public function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
Director::config()->update('alternate_base_url', 'http://www.mysite.com/'); Director::config()->update('alternate_base_url', 'http://www.mysite.com/');
@ -42,13 +42,13 @@ class RedirectorPageTest extends FunctionalTest
/* An error message will be shown if you visit it */ /* An error message will be shown if you visit it */
$content = $this->get(Director::makeRelative($page1->Link()))->getBody(); $content = $this->get(Director::makeRelative($page1->Link()))->getBody();
$this->assertContains('message-setupWithoutRedirect', $content); $this->assertStringContainsString('message-setupWithoutRedirect', $content);
/* This also applies for internal links */ /* This also applies for internal links */
$page2 = $this->objFromFixture(RedirectorPage::class, 'badinternal'); $page2 = $this->objFromFixture(RedirectorPage::class, 'badinternal');
$this->assertEquals('/bad-internal/', $page2->Link()); $this->assertEquals('/bad-internal/', $page2->Link());
$content = $this->get(Director::makeRelative($page2->Link()))->getBody(); $content = $this->get(Director::makeRelative($page2->Link()))->getBody();
$this->assertContains('message-setupWithoutRedirect', $content); $this->assertStringContainsString('message-setupWithoutRedirect', $content);
} }
public function testReflexiveAndTransitiveInternalRedirectors() public function testReflexiveAndTransitiveInternalRedirectors()
@ -57,7 +57,7 @@ class RedirectorPageTest extends FunctionalTest
$page = $this->objFromFixture(RedirectorPage::class, 'reflexive'); $page = $this->objFromFixture(RedirectorPage::class, 'reflexive');
$this->assertEquals('/reflexive/', $page->Link()); $this->assertEquals('/reflexive/', $page->Link());
$content = $this->get(Director::makeRelative($page->Link()))->getBody(); $content = $this->get(Director::makeRelative($page->Link()))->getBody();
$this->assertContains('message-setupWithoutRedirect', $content); $this->assertStringContainsString('message-setupWithoutRedirect', $content);
/* Transitive redirectors are those that point to another redirector page. They should send people to the URLSegment /* Transitive redirectors are those that point to another redirector page. They should send people to the URLSegment
* of the destination page - the middle-stop, so to speak. That should redirect to the final destination */ * of the destination page - the middle-stop, so to speak. That should redirect to the final destination */

View File

@ -26,7 +26,7 @@ class SiteTreeBacklinksTest extends SapphireTest
SiteTreeBacklinksTestContentObject::class, SiteTreeBacklinksTestContentObject::class,
]; ];
public function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -286,6 +286,6 @@ class SiteTreeBacklinksTest extends SapphireTest
$content = $gridField->getColumnContent($list->first(), 'Title'); $content = $gridField->getColumnContent($list->first(), 'Title');
$this->assertContains('Untitled Backlink test content object', $content); $this->assertStringContainsString('Untitled Backlink test content object', $content);
} }
} }

View File

@ -25,7 +25,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest
NotPageObject::class, NotPageObject::class,
]; ];
public function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -34,7 +34,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
} }
public function tearDown() protected function tearDown(): void
{ {
TestAssetStore::reset(); TestAssetStore::reset();
parent::tearDown(); parent::tearDown();

View File

@ -16,7 +16,7 @@ class SiteTreeHTMLEditorFieldTest extends FunctionalTest
{ {
protected static $fixture_file = 'SiteTreeHTMLEditorFieldTest.yml'; protected static $fixture_file = 'SiteTreeHTMLEditorFieldTest.yml';
public function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
TestAssetStore::activate('SiteTreeHTMLEditorFieldTest'); TestAssetStore::activate('SiteTreeHTMLEditorFieldTest');
@ -37,7 +37,7 @@ class SiteTreeHTMLEditorFieldTest extends FunctionalTest
} }
} }
public function tearDown() protected function tearDown(): void
{ {
TestAssetStore::reset(); TestAssetStore::reset();
parent::tearDown(); parent::tearDown();

View File

@ -11,7 +11,7 @@ use SilverStripe\View\Parsers\HTMLValue;
class SiteTreeLinkTrackingTest extends SapphireTest class SiteTreeLinkTrackingTest extends SapphireTest
{ {
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
Director::config()->set('alternate_base_url', 'http://www.mysite.com/'); Director::config()->set('alternate_base_url', 'http://www.mysite.com/');

View File

@ -25,7 +25,7 @@ class SiteTreePermissionsTest extends FunctionalTest
SiteTree::class => [SiteTreeSubsites::class], SiteTree::class => [SiteTreeSubsites::class],
]; ];
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -63,7 +63,7 @@ class SiteTreePermissionsTest extends FunctionalTest
$response = $responseException->getResponse(); $response = $responseException->getResponse();
} }
$this->assertEquals($response->getStatusCode(), '302'); $this->assertEquals($response->getStatusCode(), '302');
$this->assertContains( $this->assertStringContainsString(
Security::config()->get('login_url'), Security::config()->get('login_url'),
$response->getHeader('Location') $response->getHeader('Location')
); );

View File

@ -1289,7 +1289,7 @@ class SiteTreeTest extends SapphireTest
try { try {
$notRootPage->write(); $notRootPage->write();
} catch (ValidationException $e) { } catch (ValidationException $e) {
$this->assertContains('is not allowed on the root level', $e->getMessage()); $this->assertStringContainsString('is not allowed on the root level', $e->getMessage());
$isDetected = true; $isDetected = true;
} }
@ -1302,8 +1302,8 @@ class SiteTreeTest extends SapphireTest
{ {
$node = new SiteTreeTest_StageStatusInherit(); $node = new SiteTreeTest_StageStatusInherit();
$treeTitle = $node->getTreeTitle(); $treeTitle = $node->getTreeTitle();
$this->assertContains('InheritedTitle', $treeTitle); $this->assertStringContainsString('InheritedTitle', $treeTitle);
$this->assertContains('inherited-class', $treeTitle); $this->assertStringContainsString('inherited-class', $treeTitle);
} }
public function testMenuTitleIsUnsetWhenEqualsTitle() public function testMenuTitleIsUnsetWhenEqualsTitle()
@ -1336,8 +1336,8 @@ class SiteTreeTest extends SapphireTest
$page = new SiteTreeTest_PageNode(); $page = new SiteTreeTest_PageNode();
$meta = $page->MetaTags(); $meta = $page->MetaTags();
$this->assertContains('meta name="generator"', $meta, 'Should include generator tag'); $this->assertStringContainsString('meta name="generator"', $meta, 'Should include generator tag');
$this->assertContains( $this->assertStringContainsString(
'content="SilverStripe - https://www.silverstripe.org', 'content="SilverStripe - https://www.silverstripe.org',
$meta, $meta,
'Should contain default meta generator info' 'Should contain default meta generator info'
@ -1346,7 +1346,7 @@ class SiteTreeTest extends SapphireTest
// test proper escaping of quotes in attribute value // test proper escaping of quotes in attribute value
Config::modify()->set(SiteTree::class, 'meta_generator', 'Generator with "quotes" in it'); Config::modify()->set(SiteTree::class, 'meta_generator', 'Generator with "quotes" in it');
$meta = $page->MetaTags(); $meta = $page->MetaTags();
$this->assertContains( $this->assertStringContainsString(
'content="Generator with &quot;quotes&quot; in it', 'content="Generator with &quot;quotes&quot; in it',
$meta, $meta,
'test proper escaping of values from Config' 'test proper escaping of values from Config'
@ -1355,7 +1355,7 @@ class SiteTreeTest extends SapphireTest
// test empty generator - no tag should appear at all // test empty generator - no tag should appear at all
Config::modify()->set(SiteTree::class, 'meta_generator', ''); Config::modify()->set(SiteTree::class, 'meta_generator', '');
$meta = $page->MetaTags(); $meta = $page->MetaTags();
$this->assertNotContains( $this->assertStringNotContainsString(
'meta name="generator"', 'meta name="generator"',
$meta, $meta,
'test blank value means no tag generated' 'test blank value means no tag generated'
@ -1394,19 +1394,19 @@ class SiteTreeTest extends SapphireTest
// Test with title // Test with title
$meta = $page->MetaTags(); $meta = $page->MetaTags();
$charset = Config::inst()->get(ContentNegotiator::class, 'encoding'); $charset = Config::inst()->get(ContentNegotiator::class, 'encoding');
$this->assertContains('<meta http-equiv="Content-Type" content="text/html; charset='.$charset.'"', $meta); $this->assertStringContainsString('<meta http-equiv="Content-Type" content="text/html; charset='.$charset.'"', $meta);
$this->assertContains('<meta name="description" content="The &lt;br /&gt; and &lt;br&gt; tags"', $meta); $this->assertStringContainsString('<meta name="description" content="The &lt;br /&gt; and &lt;br&gt; tags"', $meta);
$this->assertContains('<link rel="canonical" href="http://www.mysite.com/html-and-xml"', $meta); $this->assertStringContainsString('<link rel="canonical" href="http://www.mysite.com/html-and-xml"', $meta);
$this->assertContains('<meta name="x-page-id" content="'.$page->ID.'"', $meta); $this->assertStringContainsString('<meta name="x-page-id" content="'.$page->ID.'"', $meta);
$this->assertContains('<meta name="x-cms-edit-link" content="'.$page->CMSEditLink().'"', $meta); $this->assertStringContainsString('<meta name="x-cms-edit-link" content="'.$page->CMSEditLink().'"', $meta);
$this->assertContains('<title>HTML &amp; XML</title>', $meta); $this->assertStringContainsString('<title>HTML &amp; XML</title>', $meta);
// Test without title // Test without title
$meta = $page->MetaTags(false); $meta = $page->MetaTags(false);
$this->assertNotContains('<title>', $meta); $this->assertStringNotContainsString('<title>', $meta);
$meta = $page->MetaTags('false'); $meta = $page->MetaTags('false');
$this->assertNotContains('<title>', $meta); $this->assertStringNotContainsString('<title>', $meta);
} }
public function testMetaComponents() public function testMetaComponents()

View File

@ -46,7 +46,7 @@ class VirtualPageTest extends FunctionalTest
] ]
]; ];
public function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -477,7 +477,7 @@ class VirtualPageTest extends FunctionalTest
try { try {
$virtual->write(); $virtual->write();
} catch (ValidationException $e) { } catch (ValidationException $e) {
$this->assertContains('is not allowed on the root level', $e->getMessage()); $this->assertStringContainsString('is not allowed on the root level', $e->getMessage());
$isDetected = true; $isDetected = true;
} }
@ -603,7 +603,7 @@ class VirtualPageTest extends FunctionalTest
try { try {
$childVirtualPage->write(); $childVirtualPage->write();
} catch (ValidationException $e) { } catch (ValidationException $e) {
$this->assertContains('not allowed as child of this parent page', $e->getMessage()); $this->assertStringContainsString('not allowed as child of this parent page', $e->getMessage());
$isDetected = true; $isDetected = true;
} }
@ -644,8 +644,8 @@ class VirtualPageTest extends FunctionalTest
$response = $this->get($vp->Link()); $response = $this->get($vp->Link());
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertContains('TestContent', $response->getBody()); $this->assertStringContainsString('TestContent', $response->getBody());
$this->assertNotContains('NotThisContent', $response->getBody()); $this->assertStringNotContainsString('NotThisContent', $response->getBody());
// VirtualPageTest_ClassB doesn't have an associated controller for // VirtualPageTest_ClassB doesn't have an associated controller for
// ModelAsController::controller_for() to find // ModelAsController::controller_for() to find
@ -661,7 +661,7 @@ class VirtualPageTest extends FunctionalTest
$response = $this->get($vp->Link()); $response = $this->get($vp->Link());
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertContains('Test Page B', $response->getBody()); $this->assertStringContainsString('Test Page B', $response->getBody());
}); });
} }

View File

@ -24,7 +24,7 @@ class CmsReportsTest extends SapphireTest
private static $daysAgo = 14; private static $daysAgo = 14;
public function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@ -28,7 +28,7 @@ class CMSMainSearchFormTest extends FunctionalTest
$this->assertEquals(count($titles), 1); $this->assertEquals(count($titles), 1);
// For some reason the title gets split into two lines // For some reason the title gets split into two lines
$this->assertContains('Page 1', $titles[0]); $this->assertStringContainsString('Page 1', $titles[0]);
} }
protected function getPageTitles() protected function getPageTitles()

View File

@ -18,7 +18,7 @@ class DatabaseSearchEngineTest extends SapphireTest
*/ */
protected $usesTransactions = false; protected $usesTransactions = false;
public static function setUpBeforeClass() public static function setUpBeforeClass(): void
{ {
parent::setUpBeforeClass(); parent::setUpBeforeClass();

View File

@ -57,7 +57,7 @@ class ZZZSearchFormTest extends FunctionalTest
} }
} }
public static function setUpBeforeClass() public static function setUpBeforeClass(): void
{ {
// HACK Postgres doesn't refresh TSearch indexes when the schema changes after CREATE TABLE // HACK Postgres doesn't refresh TSearch indexes when the schema changes after CREATE TABLE
// MySQL will need a different table type // MySQL will need a different table type
@ -69,7 +69,7 @@ class ZZZSearchFormTest extends FunctionalTest
parent::setUpBeforeClass(); parent::setUpBeforeClass();
} }
public function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -110,7 +110,7 @@ class ZZZSearchFormTest extends FunctionalTest
$sf->setTemplate('BlankPage'); $sf->setTemplate('BlankPage');
$this->assertContains( $this->assertStringContainsString(
'<body class="SearchForm Form BlankPage">', '<body class="SearchForm Form BlankPage">',
$sf->forTemplate() $sf->forTemplate()
); );

View File

@ -14,7 +14,7 @@ class MigrateSiteTreeLinkingTaskTest extends SapphireTest
protected static $use_draft_site = true; protected static $use_draft_site = true;
public static function setUpBeforeClass() public static function setUpBeforeClass(): void
{ {
parent::setUpBeforeClass(); parent::setUpBeforeClass();
@ -34,7 +34,7 @@ class MigrateSiteTreeLinkingTaskTest extends SapphireTest
}); });
} }
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -59,7 +59,7 @@ class MigrateSiteTreeLinkingTaskTest extends SapphireTest
DB::quiet(false); DB::quiet(false);
$task = new MigrateSiteTreeLinkingTask(); $task = new MigrateSiteTreeLinkingTask();
$task->run(null); $task->run(null);
$this->assertContains( $this->assertStringContainsString(
"Migrated page links on 5 Pages", "Migrated page links on 5 Pages",
ob_get_contents(), ob_get_contents(),
'Rewritten links are correctly reported' 'Rewritten links are correctly reported'

View File

@ -38,7 +38,7 @@ class RemoveOrphanedPagesTaskTest extends FunctionalTest
{ {
protected static $fixture_file = 'RemoveOrphanedPagesTaskTest.yml'; protected static $fixture_file = 'RemoveOrphanedPagesTaskTest.yml';
public function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();