Skip to content

Commit

Permalink
API phpunit 9 support
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Oct 19, 2021
1 parent de38165 commit adfef67
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 39 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"prefer-stable": true,
"require": {
"php": "^7.1 || ^8.0",
"silverstripe/framework": "^4.10@dev",
"silverstripe/cms": "^4.7@dev",
"silverstripe/admin": "^1.7@dev",
"silverstripe/versioned": "^1.7@dev",
Expand All @@ -26,7 +27,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",
Expand Down
9 changes: 5 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
<testsuite name="Default">
<directory>tests</directory>
</testsuite>

<testsuites>
<testsuite name="Default">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
Expand Down
8 changes: 4 additions & 4 deletions tests/BaseElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion tests/ElementControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
4 changes: 2 additions & 2 deletions tests/ElementalAreaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 2 additions & 6 deletions tests/GraphQL/AddElementToAreaMutationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 2 additions & 6 deletions tests/GraphQL/Legacy/AddElementToAreaMutationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions tests/Reports/ElementsInUseReportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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'
Expand Down
18 changes: 9 additions & 9 deletions tests/Tasks/MigrateContentToElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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());
}
Expand All @@ -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();
Expand All @@ -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');
Expand All @@ -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 */
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit adfef67

Please sign in to comment.