From 5d510a38d1dc5c99b709f223462269b95795641a Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 12 Oct 2021 17:18:52 +1300 Subject: [PATCH] API phpunit 9 support --- composer.json | 2 +- tests/BaseElementTest.php | 8 ++++---- tests/ElementControllerTest.php | 2 +- tests/ElementalAreaTest.php | 4 ++-- tests/GraphQL/AddElementToAreaMutationTest.php | 8 ++------ .../Legacy/AddElementToAreaMutationTest.php | 8 ++------ tests/Reports/ElementsInUseReportTest.php | 12 ++++++------ tests/Tasks/MigrateContentToElementTest.php | 18 +++++++++--------- 8 files changed, 27 insertions(+), 35 deletions(-) diff --git a/composer.json b/composer.json index 59d047418..4874ea98f 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "silverstripe/vendor-plugin": "^1" }, "require-dev": { - "silverstripe/recipe-testing": "1.x-dev" + "silverstripe/recipe-testing": "dev-two" }, "suggest": { "silverstripe/elemental-blocks": "Adds a set of common SilverStripe content block types", diff --git a/tests/BaseElementTest.php b/tests/BaseElementTest.php index d489509d2..7d829c5a0 100644 --- a/tests/BaseElementTest.php +++ b/tests/BaseElementTest.php @@ -107,7 +107,7 @@ public function testLink() { $element = $this->objFromFixture(ElementContent::class, 'content1'); - $this->assertContains($element->getPage()->Link(), $element->Link()); + $this->assertStringContainsString($element->getPage()->Link(), $element->Link()); } public function testGetEditLink() @@ -118,14 +118,14 @@ public function testGetEditLink() $element = $this->objFromFixture(ElementContent::class, 'content1'); $editLink = $element->getEditLink(); - $this->assertContains('http://example.com', $editLink, 'Link should be absolute'); - $this->assertContains('pages/edit', $editLink, 'Link should contain reference to the page'); + $this->assertStringContainsString('http://example.com', $editLink, 'Link should be absolute'); + $this->assertStringContainsString('pages/edit', $editLink, 'Link should contain reference to the page'); } public function testGetIcon() { $element = new ElementContent(); - $this->assertContains('class="font-icon-block-content"', $element->getIcon()); + $this->assertStringContainsString('class="font-icon-block-content"', $element->getIcon()); Config::modify()->set(ElementContent::class, 'icon', ''); $this->assertEmpty($element->getIcon()); diff --git a/tests/ElementControllerTest.php b/tests/ElementControllerTest.php index d26fc867b..4841a9388 100644 --- a/tests/ElementControllerTest.php +++ b/tests/ElementControllerTest.php @@ -40,6 +40,6 @@ public function testForTemplate() $this->logInWithPermission('ADMIN'); $controller = new TestElementController($element); - $this->assertContains('Hello Test', $controller->forTemplate()); + $this->assertStringContainsString('Hello Test', $controller->forTemplate()); } } diff --git a/tests/ElementalAreaTest.php b/tests/ElementalAreaTest.php index 91edd8287..f5949cce8 100644 --- a/tests/ElementalAreaTest.php +++ b/tests/ElementalAreaTest.php @@ -85,8 +85,8 @@ public function testForTemplate() { $area = $this->objFromFixture(ElementalArea::class, 'area1'); - $this->assertContains('Hello Test', $area->forTemplate()); - $this->assertContains('Hello Test 2', $area->forTemplate()); + $this->assertStringContainsString('Hello Test', $area->forTemplate()); + $this->assertStringContainsString('Hello Test 2', $area->forTemplate()); } public function testCanBePublished() diff --git a/tests/GraphQL/AddElementToAreaMutationTest.php b/tests/GraphQL/AddElementToAreaMutationTest.php index c4eda5e60..262cbeede 100644 --- a/tests/GraphQL/AddElementToAreaMutationTest.php +++ b/tests/GraphQL/AddElementToAreaMutationTest.php @@ -50,20 +50,16 @@ public function testAddingBlocksInOrder() $this->assertIdsInOrder([$five, $one, $three, $two, $four], 'The fifth element is added first, after ID 0'); } - /** - * @expectedException InvalidArgumentException - */ public function testBadElementalArea() { + $this->expectException(InvalidArgumentException::class); $areaID = $this->objFromFixture(ElementalArea::class, 'one')->ID; $this->runMutation(TestElement::class, $areaID + 1); } - /** - * @expectedException InvalidArgumentException - */ public function testOrderingByWrongElementalArea() { + $this->expectException(InvalidArgumentException::class); $firstArea = ElementalArea::get()->first(); $elementInFirstArea = TestElement::create(); $firstArea->Elements()->add($elementInFirstArea); diff --git a/tests/GraphQL/Legacy/AddElementToAreaMutationTest.php b/tests/GraphQL/Legacy/AddElementToAreaMutationTest.php index 8755f520c..de9e786e3 100644 --- a/tests/GraphQL/Legacy/AddElementToAreaMutationTest.php +++ b/tests/GraphQL/Legacy/AddElementToAreaMutationTest.php @@ -51,20 +51,16 @@ public function testAddingBlocksInOrder() $this->assertIdsInOrder([$five, $one, $three, $two, $four], 'The fifth element is added first, after ID 0'); } - /** - * @expectedException InvalidArgumentException - */ public function testBadElementalArea() { + $this->expectException(InvalidArgumentException::class); $areaID = $this->objFromFixture(ElementalArea::class, 'one')->ID; $this->runMutation(TestElement::class, $areaID + 1); } - /** - * @expectedException InvalidArgumentException - */ public function testOrderingByWrongElementalArea() { + $this->expectException(InvalidArgumentException::class); $firstArea = ElementalArea::get()->first(); $elementInFirstArea = TestElement::create(); $firstArea->Elements()->add($elementInFirstArea); diff --git a/tests/Reports/ElementsInUseReportTest.php b/tests/Reports/ElementsInUseReportTest.php index bb52a274c..ff4c5d501 100644 --- a/tests/Reports/ElementsInUseReportTest.php +++ b/tests/Reports/ElementsInUseReportTest.php @@ -53,18 +53,18 @@ public function testReportShowsElementsInUse() $result = (string) $this->get('admin/reports/show/DNADesign-Elemental-Reports-ElementsInUseReport')->getBody(); - $this->assertContains('Content blocks in use', $result, 'Title is displayed'); + $this->assertStringContainsString('Content blocks in use', $result, 'Title is displayed'); - $this->assertContains( + $this->assertStringContainsString( 'data-class="DNADesign\\Elemental\\Models\\ElementContent"', $result, 'Report contains content elements (bundled with elemental)' ); - $this->assertContains('HTML text block', $result, 'Content element "nice" type is shown'); + $this->assertStringContainsString('HTML text block', $result, 'Content element "nice" type is shown'); - $this->assertContains('My special content block', $result, 'Fixtured content element is shown'); - $this->assertContains('Stubby Stub', $result, 'Fixtured stub element is shown'); + $this->assertStringContainsString('My special content block', $result, 'Fixtured content element is shown'); + $this->assertStringContainsString('Stubby Stub', $result, 'Fixtured stub element is shown'); } public function testSourceRecords() @@ -87,7 +87,7 @@ public function testElementsAssociatedToPagesHaveEditLink() $castros = $records->first(); $this->assertNotNull($castros, 'Fixtured Castros page exists'); $this->assertTrue($castros->hasField('EditLink')); - $this->assertContains( + $this->assertStringContainsString( (string) $this->idFromFixture(TestPage::class, 'castros_home'), $castros->EditLink, 'Correct owner page ID is in edit link' diff --git a/tests/Tasks/MigrateContentToElementTest.php b/tests/Tasks/MigrateContentToElementTest.php index 08d32a0a3..3d58a92aa 100644 --- a/tests/Tasks/MigrateContentToElementTest.php +++ b/tests/Tasks/MigrateContentToElementTest.php @@ -46,7 +46,7 @@ public function testContentIsMigratedFromPagesToNewElements() $task->run(new HTTPRequest('GET', '')); $output = ob_get_clean(); - $this->assertContains('Finished migrating 1 pages\' content', $output); + $this->assertStringContainsString('Finished migrating 1 pages\' content', $output); // Get the page that should've been updated and the content should be removed $page = $this->objFromFixture(TestPage::class, 'page3'); @@ -76,20 +76,20 @@ public function testContentIsNotClearedWhenConfigured() $task->run(new HTTPRequest('GET', '')); $output = ob_get_clean(); - $this->assertContains('Finished migrating 1 pages\' content', $output); + $this->assertStringContainsString('Finished migrating 1 pages\' content', $output); $page = $this->objFromFixture(TestPage::class, 'page3'); - $this->assertContains('This is page 3', $page->Content, 'Content is not removed from the page'); + $this->assertStringContainsString('This is page 3', $page->Content, 'Content is not removed from the page'); $element = $page->ElementalArea->Elements()->first(); - $this->assertContains('This is page 3', $element->HTML, 'Content is still added to a new element'); + $this->assertStringContainsString('This is page 3', $element->HTML, 'Content is still added to a new element'); // Run the task again and assert the page is not picked up again ob_start(); $task->run(new HTTPRequest('GET', '')); $output = ob_get_clean(); - $this->assertContains('Finished migrating 0 pages\' content', $output); + $this->assertStringContainsString('Finished migrating 0 pages\' content', $output); $page = $this->objFromFixture(TestPage::class, 'page3'); $this->assertCount(1, $page->ElementalArea->Elements()); } @@ -105,7 +105,7 @@ public function testTargetElementConfigurationIsRespected() $task->run(new HTTPRequest('GET', '')); $output = ob_get_clean(); - $this->assertContains('Finished migrating 1 pages\' content', $output); + $this->assertStringContainsString('Finished migrating 1 pages\' content', $output); // Get the page that should've been updated and the content should be removed $element = $this->objFromFixture(TestPage::class, 'page3')->ElementalArea->Elements()->first(); @@ -129,7 +129,7 @@ public function testPublishingConfigurationIsRespected() $task->run(new HTTPRequest('GET', '')); $output = ob_get_clean(); - $this->assertContains('Finished migrating 1 pages\' content', $output); + $this->assertStringContainsString('Finished migrating 1 pages\' content', $output); // Get the page that should've been updated and the content should be removed $page = $this->objFromFixture(TestPage::class, 'page3'); @@ -156,7 +156,7 @@ public function testPagesThatWereNotPublishedAreNotPublishedDuringThisTask() $task->run(new HTTPRequest('GET', '')); $output = ob_get_clean(); - $this->assertContains('Finished migrating 1 pages\' content', $output); + $this->assertStringContainsString('Finished migrating 1 pages\' content', $output); // Get the page that should've been updated and the content should be removed /** @var TestPage&Versioned $page */ @@ -191,7 +191,7 @@ public function testIgnoredClassesContentIsNotCleared() $task->run(new HTTPRequest('GET', '')); $output = ob_get_clean(); - $this->assertContains('Finished migrating 0 pages\' content', $output); + $this->assertStringContainsString('Finished migrating 0 pages\' content', $output); // Get the page and confirm its content has not been altered. $page = $this->objFromFixture(TestPage::class, 'page3');