Merge pull request #471 from creative-commoners/pulls/2/sapphire-test-nine

API phpunit 9 support
This commit is contained in:
Maxime Rainville 2021-11-01 22:29:34 +13:00 committed by GitHub
commit 5049a5e13c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 60 additions and 38 deletions

View File

@ -5,5 +5,4 @@ import:
env:
global:
- COMPOSER_ROOT_VERSION="2.x-dev"
- BEHAT_SUITE="@subsites"

View File

@ -15,7 +15,8 @@
}
],
"require": {
"silverstripe/framework": "^4.4@dev",
"php": "^7.3 || ^8.0",
"silverstripe/framework": "^4.10",
"silverstripe/cms": "^4.4@dev",
"silverstripe/admin": "^1.4@dev",
"silverstripe/asset-admin": "^1.4@dev",
@ -23,7 +24,7 @@
"silverstripe/versioned": "^1.4@dev"
},
"require-dev": {
"sminnee/phpunit": "^5.7",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.0"
},
"autoload": {

View File

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

View File

@ -9,7 +9,7 @@ use SilverStripe\Subsites\State\SubsiteState;
class BaseSubsiteTest extends SapphireTest
{
protected function setUp()
protected function setUp(): void
{
parent::setUp();

View File

@ -15,8 +15,8 @@ class GroupSubsitesTest extends BaseSubsiteTest
public function testTrivialFeatures()
{
$this->assertInternalType('array', singleton(GroupSubsites::class)->extraStatics());
$this->assertInternalType('array', singleton(GroupSubsites::class)->providePermissions());
$this->assertIsArray(singleton(GroupSubsites::class)->extraStatics());
$this->assertIsArray(singleton(GroupSubsites::class)->providePermissions());
$this->assertInstanceOf(FieldList::class, singleton(Group::class)->getCMSFields());
}

View File

@ -19,14 +19,14 @@ class InitStateMiddlewareTest extends BaseSubsiteTest
*/
protected $origServer = [];
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->origServer = $_SERVER;
}
protected function tearDown()
protected function tearDown(): void
{
$_SERVER = $this->origServer;

View File

@ -18,7 +18,7 @@ class ThemeResolverTest extends SapphireTest
SSViewer::DEFAULT_THEME,
];
protected function setUp()
protected function setUp(): void
{
parent::setUp();

View File

@ -42,7 +42,7 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
],
];
protected function setUp()
protected function setUp(): void
{
// We have our own home page fixtures, prevent the default one being created in this test suite.
Config::modify()->set(SiteTree::class, 'create_default_pages', false);

View File

@ -14,7 +14,7 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
protected $autoFollowRedirection = false;
protected function setUp()
protected function setUp(): void
{
parent::setUp();
// Ensure all pages are published
@ -48,14 +48,18 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
$this->logOut();
$response = $this->getAndFollowAll('admin/pages/?SubsiteID=0');
$this->assertContains('Security/login', $this->mainSession->lastUrl(), 'Admin is disallowed');
$this->assertStringContainsString('Security/login', $this->mainSession->lastUrl(), 'Admin is disallowed');
$subsite1 = $this->objFromFixture(Subsite::class, 'subsite1');
$response = $this->getAndFollowAll("admin/pages/?SubsiteID={$subsite1->ID}");
$this->assertContains('Security/login', $this->mainSession->lastUrl(), 'Admin is disallowed');
$this->assertStringContainsString('Security/login', $this->mainSession->lastUrl(), 'Admin is disallowed');
$response = $this->getAndFollowAll('admin/subsite_xhr');
$this->assertContains('Security/login', $this->mainSession->lastUrl(), 'SubsiteXHRController is disallowed');
$this->assertStringContainsString(
'Security/login',
$this->mainSession->lastUrl(),
'SubsiteXHRController is disallowed'
);
}
/**
@ -67,17 +71,21 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
$this->getAndFollowAll('admin/pages/?SubsiteID=0');
$this->assertEquals(0, $this->session()->get('SubsiteID'), 'Can access main site.');
$this->assertContains('admin/pages', $this->mainSession->lastUrl(), 'Lands on the correct section');
$this->assertStringContainsString('admin/pages', $this->mainSession->lastUrl(), 'Lands on the correct section');
$subsite1 = $this->objFromFixture(Subsite::class, 'subsite1');
$this->getAndFollowAll("admin/pages/?SubsiteID={$subsite1->ID}");
// Check the session manually, since the state is unique to the request, not this test
$this->assertEquals($subsite1->ID, $this->session()->get('SubsiteID'), 'Can access other subsite.');
$this->assertContains('admin/pages', $this->mainSession->lastUrl(), 'Lands on the correct section');
$this->assertStringContainsString('admin/pages', $this->mainSession->lastUrl(), 'Lands on the correct section');
$response = $this->getAndFollowAll('admin/subsite_xhr');
$this->assertNotContains('Security/login', $this->mainSession->lastUrl(), 'SubsiteXHRController is reachable');
$this->assertStringNotContainsString(
'Security/login',
$this->mainSession->lastUrl(),
'SubsiteXHRController is reachable'
);
}
public function testAdminIsRedirectedToObjectsSubsite()
@ -92,7 +100,7 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
$response = $this->get("admin/pages/edit/show/$subsite1Home->ID");
$this->assertEquals(302, $response->getStatusCode());
$this->assertContains(
$this->assertStringContainsString(
'admin/pages/edit/show/' . $subsite1Home->ID . '?SubsiteID=' . $subsite1Home->SubsiteID,
$response->getHeader('Location')
);
@ -102,7 +110,7 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
$response = $this->get("admin/pages/edit/show/$subsite1Home->ID");
$this->assertEquals(302, $response->getStatusCode());
$this->assertContains(
$this->assertStringContainsString(
'admin/pages/edit/show/' . $subsite1Home->ID . '?SubsiteID=' . $subsite1Home->SubsiteID,
$response->getHeader('Location')
);
@ -122,15 +130,19 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
$this->get('admin/pages/?SubsiteID=0');
$this->assertEquals(0, $this->session()->get('SubsiteID'), 'Can access main site.');
$this->assertContains('admin/pages', $this->mainSession->lastUrl(), 'Lands on the correct section');
$this->assertStringContainsString('admin/pages', $this->mainSession->lastUrl(), 'Lands on the correct section');
$subsite1 = $this->objFromFixture(Subsite::class, 'subsite1');
$this->get("admin/pages/?SubsiteID={$subsite1->ID}");
$this->assertEquals($subsite1->ID, $this->session()->get('SubsiteID'), 'Can access other subsite.');
$this->assertContains('admin/pages', $this->mainSession->lastUrl(), 'Lands on the correct section');
$this->assertStringContainsString('admin/pages', $this->mainSession->lastUrl(), 'Lands on the correct section');
$response = $this->get('admin/subsite_xhr');
$this->assertNotContains('Security/login', $this->mainSession->lastUrl(), 'SubsiteXHRController is reachable');
$this->assertStringNotContainsString(
'Security/login',
$this->mainSession->lastUrl(),
'SubsiteXHRController is reachable'
);
}
/**
@ -146,7 +158,11 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
// Check allowed URL.
$this->getAndFollowAll("admin/pages/?SubsiteID={$subsite1->ID}");
$this->assertEquals($subsite1->ID, $this->session()->get('SubsiteID'), 'Can access own subsite.');
$this->assertContains('admin/pages', $this->mainSession->lastUrl(), 'Can access permitted section.');
$this->assertStringContainsString(
'admin/pages',
$this->mainSession->lastUrl(),
'Can access permitted section.'
);
// Check forbidden section in allowed subsite.
$this->getAndFollowAll("admin/assets/?SubsiteID={$subsite1->ID}");
@ -172,10 +188,14 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
$subsite1->ID,
'Is redirected to first permitted subsite.'
);
$this->assertNotContains('Security/login', $this->mainSession->lastUrl(), 'Is not denied access');
$this->assertStringNotContainsString('Security/login', $this->mainSession->lastUrl(), 'Is not denied access');
// Check the standalone XHR controller.
$response = $this->getAndFollowAll('admin/subsite_xhr');
$this->assertNotContains('Security/login', $this->mainSession->lastUrl(), 'SubsiteXHRController is reachable');
$this->assertStringNotContainsString(
'Security/login',
$this->mainSession->lastUrl(),
'SubsiteXHRController is reachable'
);
}
}

View File

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

View File

@ -26,7 +26,7 @@ class SubsiteTest extends BaseSubsiteTest
*/
protected $origServer = [];
protected function setUp()
protected function setUp(): void
{
parent::setUp();
@ -38,7 +38,7 @@ class SubsiteTest extends BaseSubsiteTest
$this->origServer = $_SERVER;
}
protected function tearDown()
protected function tearDown(): void
{
$_SERVER = $this->origServer;

View File

@ -36,12 +36,12 @@ class SubsiteXHRControllerTest extends FunctionalTest
$this->assertEquals(200, $result->getStatusCode());
// SilverStripe 4.0-4.2: text/json. >=4.3: application/json
$this->assertContains('json', $result->getHeader('Content-Type'));
$this->assertStringContainsString('json', $result->getHeader('Content-Type'));
$body = $result->getBody();
$this->assertContains('Main site', $body);
$this->assertContains('Test 1', $body);
$this->assertContains('Test 2', $body);
$this->assertContains('Test 3', $body);
$this->assertStringContainsString('Main site', $body);
$this->assertStringContainsString('Test 1', $body);
$this->assertStringContainsString('Test 2', $body);
$this->assertStringContainsString('Test 3', $body);
}
}

View File

@ -21,7 +21,7 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest
'SubsitesVirtualPageTest.yml',
];
protected function setUp()
protected function setUp(): void
{
parent::setUp();
@ -43,7 +43,7 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest
$page->write();
}
public function tearDown()
protected function tearDown(): void
{
TestAssetStore::reset();
parent::tearDown();