upgrade tests

This commit is contained in:
Werner M. Krauß 2017-05-24 15:25:34 +02:00
parent ef602abe47
commit 2295501587
11 changed files with 100 additions and 69 deletions

View File

@ -1,6 +1,8 @@
<?php <?php
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
use SilverStripe\Subsites\Model\Subsite;
class BaseSubsiteTest extends SapphireTest { class BaseSubsiteTest extends SapphireTest {
function setUp() { function setUp() {

View File

@ -3,17 +3,20 @@
use SilverStripe\Assets\File; use SilverStripe\Assets\File;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Assets\Folder; use SilverStripe\Assets\Folder;
use SilverStripe\Subsites\Extensions\FileSubsites;
use SilverStripe\Subsites\Model\Subsite;
class FileSubsitesTest extends BaseSubsiteTest { class FileSubsitesTest extends BaseSubsiteTest {
static $fixture_file = 'subsites/tests/SubsiteTest.yml'; static $fixture_file = 'subsites/tests/SubsiteTest.yml';
function testTrivialFeatures() { function testTrivialFeatures() {
$this->assertTrue(is_array(singleton('FileSubsites')->extraStatics())); $this->assertTrue(is_array(singleton(FileSubsites::class)->extraStatics()));
$file = new File(); $file = new File();
$file->Name = 'FileTitle'; $file->Name = 'FileTitle';
$file->Title = 'FileTitle'; $file->Title = 'FileTitle';
$this->assertEquals(' * FileTitle', $file->alternateTreeTitle()); $this->assertEquals(' * FileTitle', $file->alternateTreeTitle());
$file->SubsiteID = $this->objFromFixture('Subsite', 'domaintest1')->ID; $file->SubsiteID = $this->objFromFixture(Subsite::class, 'domaintest1')->ID;
$this->assertEquals('FileTitle', $file->getTreeTitle()); $this->assertEquals('FileTitle', $file->getTreeTitle());
$this->assertTrue(singleton('SilverStripe\\Assets\\Folder')->getCMSFields() instanceof FieldList); $this->assertTrue(singleton('SilverStripe\\Assets\\Folder')->getCMSFields() instanceof FieldList);
Subsite::changeSubsite(1); Subsite::changeSubsite(1);
@ -23,7 +26,7 @@ class FileSubsitesTest extends BaseSubsiteTest {
function testWritingSubsiteID() { function testWritingSubsiteID() {
$this->objFromFixture('SilverStripe\\Security\\Member', 'admin')->logIn(); $this->objFromFixture('SilverStripe\\Security\\Member', 'admin')->logIn();
$subsite = $this->objFromFixture('Subsite', 'domaintest1'); $subsite = $this->objFromFixture(Subsite::class, 'domaintest1');
FileSubsites::$default_root_folders_global = true; FileSubsites::$default_root_folders_global = true;
Subsite::changeSubsite(0); Subsite::changeSubsite(0);

View File

@ -2,15 +2,18 @@
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Security\Group; use SilverStripe\Security\Group;
use SilverStripe\Subsites\Extensions\GroupSubsites;
use SilverStripe\Subsites\Model\Subsite;
class GroupSubsitesTest extends BaseSubsiteTest { class GroupSubsitesTest extends BaseSubsiteTest {
static $fixture_file = 'subsites/tests/SubsiteTest.yml'; static $fixture_file = 'subsites/tests/SubsiteTest.yml';
protected $requireDefaultRecordsFrom = array('GroupSubsites'); protected $requireDefaultRecordsFrom = array(GroupSubsites::class);
function testTrivialFeatures() { function testTrivialFeatures() {
$this->assertTrue(is_array(singleton('GroupSubsites')->extraStatics())); $this->assertTrue(is_array(singleton(GroupSubsites::class)->extraStatics()));
$this->assertTrue(is_array(singleton('GroupSubsites')->providePermissions())); $this->assertTrue(is_array(singleton(GroupSubsites::class)->providePermissions()));
$this->assertTrue(singleton('SilverStripe\\Security\\Group')->getCMSFields() instanceof FieldList); $this->assertTrue(singleton('SilverStripe\\Security\\Group')->getCMSFields() instanceof FieldList);
} }
@ -21,8 +24,8 @@ class GroupSubsitesTest extends BaseSubsiteTest {
$this->assertEquals($group->getTreeTitle(), 'The A Team <i>(global group)</i>'); $this->assertEquals($group->getTreeTitle(), 'The A Team <i>(global group)</i>');
$group->AccessAllSubsites = false; $group->AccessAllSubsites = false;
$group->write(); $group->write();
$group->Subsites()->add($this->objFromFixture('Subsite', 'domaintest1')); $group->Subsites()->add($this->objFromFixture(Subsite::class, 'domaintest1'));
$group->Subsites()->add($this->objFromFixture('Subsite', 'domaintest2')); $group->Subsites()->add($this->objFromFixture(Subsite::class, 'domaintest2'));
$this->assertEquals($group->getTreeTitle(), 'The A Team <i>(Test 1, Test 2)</i>'); $this->assertEquals($group->getTreeTitle(), 'The A Team <i>(Test 1, Test 2)</i>');
} }
} }

View File

@ -3,6 +3,9 @@
use SilverStripe\Admin\LeftAndMain; use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\FunctionalTest; use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\AssetAdmin\Controller\AssetAdmin;
class LeftAndMainSubsitesTest extends FunctionalTest { class LeftAndMainSubsitesTest extends FunctionalTest {
@ -28,7 +31,7 @@ class LeftAndMainSubsitesTest extends FunctionalTest {
array('Title' =>'Subsite1 Template') array('Title' =>'Subsite1 Template')
), $subsites, 'Lists member-accessible sites for the accessible controller.'); ), $subsites, 'Lists member-accessible sites for the accessible controller.');
$assetadmin = singleton('AssetAdmin'); $assetadmin = singleton(AssetAdmin::class);
$subsites = $assetadmin->sectionSites(true, "Main site", $member); $subsites = $assetadmin->sectionSites(true, "Main site", $member);
$this->assertDOSEquals(array(), $subsites, 'Does not list any sites for forbidden controller.'); $this->assertDOSEquals(array(), $subsites, 'Does not list any sites for forbidden controller.');
@ -46,9 +49,9 @@ class LeftAndMainSubsitesTest extends FunctionalTest {
$this->loginAs($admin); $this->loginAs($admin);
$ids = array(); $ids = array();
$subsite1 = $this->objFromFixture('Subsite', 'domaintest1'); $subsite1 = $this->objFromFixture(Subsite::class, 'domaintest1');
$subsite2 = $this->objFromFixture('Subsite', 'domaintest2'); $subsite2 = $this->objFromFixture(Subsite::class, 'domaintest2');
$subsite3 = $this->objFromFixture('Subsite', 'domaintest3'); $subsite3 = $this->objFromFixture(Subsite::class, 'domaintest3');
$ids[] = $subsite1->ID; $ids[] = $subsite1->ID;
$ids[] = $subsite2->ID; $ids[] = $subsite2->ID;

View File

@ -1,15 +1,18 @@
<?php <?php
use SilverStripe\SiteConfig\SiteConfig; use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Subsites\Extensions\SiteConfigSubsites;
class SiteConfigSubsitesTest extends BaseSubsiteTest { class SiteConfigSubsitesTest extends BaseSubsiteTest {
static $fixture_file = 'subsites/tests/SubsiteTest.yml'; static $fixture_file = 'subsites/tests/SubsiteTest.yml';
function testEachSubsiteHasAUniqueSiteConfig() { function testEachSubsiteHasAUniqueSiteConfig() {
$subsite1 = $this->objFromFixture('Subsite', 'domaintest1'); $subsite1 = $this->objFromFixture(Subsite::class, 'domaintest1');
$subsite2 = $this->objFromFixture('Subsite', 'domaintest2'); $subsite2 = $this->objFromFixture(Subsite::class, 'domaintest2');
$this->assertTrue(is_array(singleton('SiteConfigSubsites')->extraStatics())); $this->assertTrue(is_array(singleton(SiteConfigSubsites::class)->extraStatics()));
Subsite::changeSubsite(0); Subsite::changeSubsite(0);
$sc = SiteConfig::current_site_config(); $sc = SiteConfig::current_site_config();

View File

@ -8,6 +8,10 @@ use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\Core\Convert; use SilverStripe\Core\Convert;
use SilverStripe\Dev\TestOnly; use SilverStripe\Dev\TestOnly;
use SilverStripe\CMS\Model\ErrorPage; use SilverStripe\CMS\Model\ErrorPage;
use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Subsites\Pages\SubsitesVirtualPage;
use SilverStripe\Subsites\Extensions\SiteTreeSubsites;
class SiteTreeSubsitesTest extends BaseSubsiteTest { class SiteTreeSubsitesTest extends BaseSubsiteTest {
@ -24,8 +28,8 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest {
); );
function testPagesInDifferentSubsitesCanShareURLSegment() { function testPagesInDifferentSubsitesCanShareURLSegment() {
$subsiteMain = $this->objFromFixture('Subsite', 'main'); $subsiteMain = $this->objFromFixture(Subsite::class, 'main');
$subsite1 = $this->objFromFixture('Subsite', 'subsite1'); $subsite1 = $this->objFromFixture(Subsite::class, 'subsite1');
$pageMain = new SiteTree(); $pageMain = new SiteTree();
$pageMain->URLSegment = 'testpage'; $pageMain->URLSegment = 'testpage';
@ -57,12 +61,12 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest {
$this->assertTrue(singleton('SilverStripe\\CMS\\Model\\SiteTree')->getSiteConfig() instanceof SiteConfig); $this->assertTrue(singleton('SilverStripe\\CMS\\Model\\SiteTree')->getSiteConfig() instanceof SiteConfig);
// The following assert is breaking in Translatable. // The following assert is breaking in Translatable.
$this->assertTrue(singleton('SilverStripe\\CMS\\Model\\SiteTree')->getCMSFields() instanceof FieldList); $this->assertTrue(singleton('SilverStripe\\CMS\\Model\\SiteTree')->getCMSFields() instanceof FieldList);
$this->assertTrue(singleton('SubsitesVirtualPage')->getCMSFields() instanceof FieldList); $this->assertTrue(singleton(SubsitesVirtualPage::class)->getCMSFields() instanceof FieldList);
$this->assertTrue(is_array(singleton('SiteTreeSubsites')->extraStatics())); $this->assertTrue(is_array(singleton(SiteTreeSubsites::class)->extraStatics()));
} }
function testErrorPageLocations() { function testErrorPageLocations() {
$subsite1 = $this->objFromFixture('Subsite', 'domaintest1'); $subsite1 = $this->objFromFixture(Subsite::class, 'domaintest1');
Subsite::changeSubsite($subsite1->ID); Subsite::changeSubsite($subsite1->ID);
$path = SiteTreeSubsitesTest_ErrorPage::get_error_filename_spy(500); $path = SiteTreeSubsitesTest_ErrorPage::get_error_filename_spy(500);
@ -78,8 +82,8 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest {
$mainpage = $this->objFromFixture('Page', 'home'); $mainpage = $this->objFromFixture('Page', 'home');
$subsite1page = $this->objFromFixture('Page', 'subsite1_home'); $subsite1page = $this->objFromFixture('Page', 'subsite1_home');
$subsite2page = $this->objFromFixture('Page', 'subsite2_home'); $subsite2page = $this->objFromFixture('Page', 'subsite2_home');
$subsite1 = $this->objFromFixture('Subsite', 'subsite1'); $subsite1 = $this->objFromFixture(Subsite::class, 'subsite1');
$subsite2 = $this->objFromFixture('Subsite', 'subsite2'); $subsite2 = $this->objFromFixture(Subsite::class, 'subsite2');
// Cant pass member as arguments to canEdit() because of GroupSubsites // Cant pass member as arguments to canEdit() because of GroupSubsites
Session::set("loggedInAs", $admin->ID); Session::set("loggedInAs", $admin->ID);
@ -116,8 +120,8 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest {
*/ */
function testTwoPagesWithSameURLOnDifferentSubsites() { function testTwoPagesWithSameURLOnDifferentSubsites() {
// Set up a couple of pages with the same URL on different subsites // Set up a couple of pages with the same URL on different subsites
$s1 = $this->objFromFixture('Subsite','domaintest1'); $s1 = $this->objFromFixture(Subsite::class,'domaintest1');
$s2 = $this->objFromFixture('Subsite','domaintest2'); $s2 = $this->objFromFixture(Subsite::class,'domaintest2');
$p1 = new SiteTree(); $p1 = new SiteTree();
$p1->Title = $p1->URLSegment = "test-page"; $p1->Title = $p1->URLSegment = "test-page";
@ -145,8 +149,8 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest {
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'editor'); $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'editor');
Session::set("loggedInAs", $editor->ID); Session::set("loggedInAs", $editor->ID);
$s1 = $this->objFromFixture('Subsite','domaintest1'); $s1 = $this->objFromFixture(Subsite::class,'domaintest1');
$s2 = $this->objFromFixture('Subsite','domaintest2'); $s2 = $this->objFromFixture(Subsite::class,'domaintest2');
$page = singleton('SilverStripe\\CMS\\Model\\SiteTree'); $page = singleton('SilverStripe\\CMS\\Model\\SiteTree');
$s1->PageTypeBlacklist = 'SiteTreeSubsitesTest_ClassA,ErrorPage'; $s1->PageTypeBlacklist = 'SiteTreeSubsitesTest_ClassA,ErrorPage';
@ -184,8 +188,8 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest {
$cmsmain = new CMSMain(); $cmsmain = new CMSMain();
$s1 = $this->objFromFixture('Subsite','domaintest1'); $s1 = $this->objFromFixture(Subsite::class,'domaintest1');
$s2 = $this->objFromFixture('Subsite','domaintest2'); $s2 = $this->objFromFixture(Subsite::class,'domaintest2');
$s1->PageTypeBlacklist = 'SiteTreeSubsitesTest_ClassA,ErrorPage'; $s1->PageTypeBlacklist = 'SiteTreeSubsitesTest_ClassA,ErrorPage';
$s1->write(); $s1->write();

View File

@ -3,6 +3,9 @@
use SilverStripe\Control\Session; use SilverStripe\Control\Session;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\FunctionalTest; use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Subsites\Controller\SubsiteXHRController;
class SubsiteAdminFunctionalTest extends FunctionalTest { class SubsiteAdminFunctionalTest extends FunctionalTest {
static $fixture_file = 'subsites/tests/SubsiteTest.yml'; static $fixture_file = 'subsites/tests/SubsiteTest.yml';
@ -30,11 +33,11 @@ class SubsiteAdminFunctionalTest extends FunctionalTest {
$response = $this->getAndFollowAll('admin/pages/?SubsiteID=0'); $response = $this->getAndFollowAll('admin/pages/?SubsiteID=0');
$this->assertRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), 'Admin is disallowed'); $this->assertRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), 'Admin is disallowed');
$subsite1 = $this->objFromFixture('Subsite', 'subsite1'); $subsite1 = $this->objFromFixture(Subsite::class, 'subsite1');
$response = $this->getAndFollowAll("admin/pages/?SubsiteID={$subsite1->ID}"); $response = $this->getAndFollowAll("admin/pages/?SubsiteID={$subsite1->ID}");
$this->assertRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), 'Admin is disallowed'); $this->assertRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), 'Admin is disallowed');
$response = $this->getAndFollowAll('SubsiteXHRController'); $response = $this->getAndFollowAll(SubsiteXHRController::class);
$this->assertRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), $this->assertRegExp('#^Security/login.*#', $this->mainSession->lastUrl(),
'SubsiteXHRController is disallowed'); 'SubsiteXHRController is disallowed');
} }
@ -50,12 +53,12 @@ class SubsiteAdminFunctionalTest extends FunctionalTest {
$this->assertEquals(Subsite::currentSubsiteID(), '0', 'Can access main site.'); $this->assertEquals(Subsite::currentSubsiteID(), '0', 'Can access main site.');
$this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section'); $this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section');
$subsite1 = $this->objFromFixture('Subsite', 'subsite1'); $subsite1 = $this->objFromFixture(Subsite::class, 'subsite1');
$this->getAndFollowAll("admin/pages/?SubsiteID={$subsite1->ID}"); $this->getAndFollowAll("admin/pages/?SubsiteID={$subsite1->ID}");
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1->ID, 'Can access other subsite.'); $this->assertEquals(Subsite::currentSubsiteID(), $subsite1->ID, 'Can access other subsite.');
$this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section'); $this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section');
$response = $this->getAndFollowAll('SubsiteXHRController'); $response = $this->getAndFollowAll(SubsiteXHRController::class);
$this->assertNotRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), $this->assertNotRegExp('#^Security/login.*#', $this->mainSession->lastUrl(),
'SubsiteXHRController is reachable'); 'SubsiteXHRController is reachable');
} }
@ -100,12 +103,12 @@ class SubsiteAdminFunctionalTest extends FunctionalTest {
$this->assertEquals(Subsite::currentSubsiteID(), '0', 'Can access main site.'); $this->assertEquals(Subsite::currentSubsiteID(), '0', 'Can access main site.');
$this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section'); $this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section');
$subsite1 = $this->objFromFixture('Subsite', 'subsite1'); $subsite1 = $this->objFromFixture(Subsite::class, 'subsite1');
$this->getAndFollowAll("admin/pages/?SubsiteID={$subsite1->ID}"); $this->getAndFollowAll("admin/pages/?SubsiteID={$subsite1->ID}");
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1->ID, 'Can access other subsite.'); $this->assertEquals(Subsite::currentSubsiteID(), $subsite1->ID, 'Can access other subsite.');
$this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section'); $this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section');
$response = $this->getAndFollowAll('SubsiteXHRController'); $response = $this->getAndFollowAll(SubsiteXHRController::class);
$this->assertNotRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), $this->assertNotRegExp('#^Security/login.*#', $this->mainSession->lastUrl(),
'SubsiteXHRController is reachable'); 'SubsiteXHRController is reachable');
} }
@ -117,7 +120,7 @@ class SubsiteAdminFunctionalTest extends FunctionalTest {
$member = $this->objFromFixture('SilverStripe\\Security\\Member', 'subsite1member'); $member = $this->objFromFixture('SilverStripe\\Security\\Member', 'subsite1member');
Session::set("loggedInAs", $member->ID); Session::set("loggedInAs", $member->ID);
$subsite1 = $this->objFromFixture('Subsite', 'subsite1'); $subsite1 = $this->objFromFixture(Subsite::class, 'subsite1');
// Check allowed URL. // Check allowed URL.
$this->getAndFollowAll("admin/pages/?SubsiteID={$subsite1->ID}"); $this->getAndFollowAll("admin/pages/?SubsiteID={$subsite1->ID}");
@ -140,7 +143,7 @@ class SubsiteAdminFunctionalTest extends FunctionalTest {
$this->assertNotRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), 'Is not denied access'); $this->assertNotRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), 'Is not denied access');
// Check the standalone XHR controller. // Check the standalone XHR controller.
$response = $this->getAndFollowAll('SubsiteXHRController'); $response = $this->getAndFollowAll(SubsiteXHRController::class);
$this->assertNotRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), $this->assertNotRegExp('#^Security/login.*#', $this->mainSession->lastUrl(),
'SubsiteXHRController is reachable'); 'SubsiteXHRController is reachable');
} }

View File

@ -3,6 +3,8 @@
use SilverStripe\Control\Session; use SilverStripe\Control\Session;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
use SilverStripe\CMS\Controllers\CMSMain; use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\Subsites\Model\Subsite;
class SubsiteAdminTest extends BaseSubsiteTest { class SubsiteAdminTest extends BaseSubsiteTest {
static $fixture_file = 'subsites/tests/SubsiteTest.yml'; static $fixture_file = 'subsites/tests/SubsiteTest.yml';
@ -18,7 +20,7 @@ class SubsiteAdminTest extends BaseSubsiteTest {
*/ */
function testBasicView() { function testBasicView() {
Subsite::$write_hostmap = false; Subsite::$write_hostmap = false;
$subsite1ID = $this->objFromFixture('Subsite','domaintest1')->ID; $subsite1ID = $this->objFromFixture(Subsite::class,'domaintest1')->ID;
// Open the admin area logged in as admin // Open the admin area logged in as admin
$response1 = Director::test('admin/subsites/', null, $this->adminLoggedInSession()); $response1 = Director::test('admin/subsites/', null, $this->adminLoggedInSession());
@ -44,9 +46,9 @@ class SubsiteAdminTest extends BaseSubsiteTest {
} }
$this->assertArrayHasKey(0, $ids, "Main site accessible"); $this->assertArrayHasKey(0, $ids, "Main site accessible");
$this->assertArrayHasKey($this->idFromFixture('Subsite','main'), $ids, "Site with no groups inaccesible"); $this->assertArrayHasKey($this->idFromFixture(Subsite::class,'main'), $ids, "Site with no groups inaccesible");
$this->assertArrayHasKey($this->idFromFixture('Subsite','subsite1'), $ids, "Subsite1 Template inaccessible"); $this->assertArrayHasKey($this->idFromFixture(Subsite::class,'subsite1'), $ids, "Subsite1 Template inaccessible");
$this->assertArrayHasKey($this->idFromFixture('Subsite','subsite2'), $ids, "Subsite2 Template inaccessible"); $this->assertArrayHasKey($this->idFromFixture(Subsite::class,'subsite2'), $ids, "Subsite2 Template inaccessible");
} }

View File

@ -2,6 +2,9 @@
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Subsites\Model\SubsiteDomain;
class SubsiteTest extends BaseSubsiteTest { class SubsiteTest extends BaseSubsiteTest {
@ -27,7 +30,7 @@ class SubsiteTest extends BaseSubsiteTest {
Subsite::$write_hostmap = false; Subsite::$write_hostmap = false;
// Create the instance // Create the instance
$template = $this->objFromFixture('Subsite', 'main'); $template = $this->objFromFixture(Subsite::class, 'main');
// Test that changeSubsite is working // Test that changeSubsite is working
Subsite::changeSubsite($template->ID); Subsite::changeSubsite($template->ID);
@ -65,8 +68,8 @@ class SubsiteTest extends BaseSubsiteTest {
*/ */
function testDomainLookup() { function testDomainLookup() {
// Clear existing fixtures // Clear existing fixtures
foreach(DataObject::get('Subsite') as $subsite) $subsite->delete(); foreach(DataObject::get(Subsite::class) as $subsite) $subsite->delete();
foreach(DataObject::get('SubsiteDomain') as $domain) $domain->delete(); foreach(DataObject::get(SubsiteDomain::class) as $domain) $domain->delete();
// Much more expressive than YML in this case // Much more expressive than YML in this case
$subsite1 = $this->createSubsiteWithDomains(array( $subsite1 = $this->createSubsiteWithDomains(array(
@ -135,8 +138,8 @@ class SubsiteTest extends BaseSubsiteTest {
function testStrictSubdomainMatching() { function testStrictSubdomainMatching() {
// Clear existing fixtures // Clear existing fixtures
foreach(DataObject::get('Subsite') as $subsite) $subsite->delete(); foreach(DataObject::get(Subsite::class) as $subsite) $subsite->delete();
foreach(DataObject::get('SubsiteDomain') as $domain) $domain->delete(); foreach(DataObject::get(SubsiteDomain::class) as $domain) $domain->delete();
// Much more expressive than YML in this case // Much more expressive than YML in this case
$subsite1 = $this->createSubsiteWithDomains(array( $subsite1 = $this->createSubsiteWithDomains(array(
@ -224,23 +227,23 @@ class SubsiteTest extends BaseSubsiteTest {
*/ */
function testDefaultDomain() { function testDefaultDomain() {
$this->assertEquals('one.example.org', $this->assertEquals('one.example.org',
$this->objFromFixture('Subsite','domaintest1')->domain()); $this->objFromFixture(Subsite::class,'domaintest1')->domain());
$this->assertEquals('two.mysite.com', $this->assertEquals('two.mysite.com',
$this->objFromFixture('Subsite','domaintest2')->domain()); $this->objFromFixture(Subsite::class,'domaintest2')->domain());
$originalHTTPHost = $_SERVER['HTTP_HOST']; $originalHTTPHost = $_SERVER['HTTP_HOST'];
$_SERVER['HTTP_HOST'] = "www.example.org"; $_SERVER['HTTP_HOST'] = "www.example.org";
$this->assertEquals('three.example.org', $this->assertEquals('three.example.org',
$this->objFromFixture('Subsite','domaintest3')->domain()); $this->objFromFixture(Subsite::class,'domaintest3')->domain());
$_SERVER['HTTP_HOST'] = "mysite.example.org"; $_SERVER['HTTP_HOST'] = "mysite.example.org";
$this->assertEquals('three.mysite.example.org', $this->assertEquals('three.mysite.example.org',
$this->objFromFixture('Subsite','domaintest3')->domain()); $this->objFromFixture(Subsite::class,'domaintest3')->domain());
$this->assertEquals($_SERVER['HTTP_HOST'], singleton('Subsite')->PrimaryDomain); $this->assertEquals($_SERVER['HTTP_HOST'], singleton(Subsite::class)->PrimaryDomain);
$this->assertEquals('http://'.$_SERVER['HTTP_HOST'].Director::baseURL(), singleton('Subsite')->absoluteBaseURL()); $this->assertEquals('http://'.$_SERVER['HTTP_HOST'].Director::baseURL(), singleton(Subsite::class)->absoluteBaseURL());
$_SERVER['HTTP_HOST'] = $originalHTTPHost; $_SERVER['HTTP_HOST'] = $originalHTTPHost;
} }
@ -339,7 +342,7 @@ class SubsiteTest extends BaseSubsiteTest {
function testDuplicateSubsite() { function testDuplicateSubsite() {
// get subsite1 & create page // get subsite1 & create page
$subsite1 = $this->objFromFixture('Subsite','domaintest1'); $subsite1 = $this->objFromFixture(Subsite::class,'domaintest1');
$subsite1->activate(); $subsite1->activate();
$page1 = new Page(); $page1 = new Page();
$page1->Title = 'MyAwesomePage'; $page1->Title = 'MyAwesomePage';

View File

@ -1,4 +1,4 @@
Subsite: SilverStripe\Subsites\Model\Subsite:
main: main:
Title: 'Template' Title: 'Template'
subsite1: subsite1:
@ -11,7 +11,7 @@ Subsite:
Title: 'Test 2' Title: 'Test 2'
domaintest3: domaintest3:
Title: 'Test 3' Title: 'Test 3'
SubsiteDomain: SilverStripe\Subsites\Model\SubsiteDomain:
subsite1: subsite1:
SubsiteID: =>Subsite.subsite1 SubsiteID: =>Subsite.subsite1
Domain: 'subsite1.*' Domain: 'subsite1.*'

View File

@ -3,7 +3,12 @@
use SilverStripe\Assets\Filesystem; use SilverStripe\Assets\Filesystem;
use SilverStripe\ORM\DB; use SilverStripe\ORM\DB;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\Versioning\Versioned;
use SilverStripe\Assets\Tests\Storage\AssetStoreTest\TestAssetStore;
use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Subsites\Pages\SubsitesVirtualPage;
use SilverStripe\Versioned\Versioned;
class SubsitesVirtualPageTest extends BaseSubsiteTest { class SubsitesVirtualPageTest extends BaseSubsiteTest {
static $fixture_file = array( static $fixture_file = array(
@ -15,13 +20,13 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest {
parent::setUp(); parent::setUp();
// Set backend root to /DataDifferencerTest // Set backend root to /DataDifferencerTest
AssetStoreTest_SpyStore::activate('SubsitesVirtualPageTest'); TestAssetStore::activate('SubsitesVirtualPageTest');
// Create a test files for each of the fixture references // Create a test files for each of the fixture references
$file = $this->objFromFixture('SilverStripe\\Assets\\File', 'file1'); $file = $this->objFromFixture('SilverStripe\\Assets\\File', 'file1');
$page = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'page1'); $page = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'page1');
$fromPath = __DIR__ . '/testscript-test-file.pdf'; $fromPath = __DIR__ . '/testscript-test-file.pdf';
$destPath = AssetStoreTest_SpyStore::getLocalPath($file); $destPath = TestAssetStore::getLocalPath($file);
Filesystem::makeFolder(dirname($destPath)); Filesystem::makeFolder(dirname($destPath));
copy($fromPath, $destPath); copy($fromPath, $destPath);
@ -31,7 +36,7 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest {
} }
public function tearDown() { public function tearDown() {
AssetStoreTest_SpyStore::reset(); TestAssetStore::reset();
parent::tearDown(); parent::tearDown();
} }
@ -39,7 +44,7 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest {
function testVirtualPageFromAnotherSubsite() { function testVirtualPageFromAnotherSubsite() {
Subsite::$write_hostmap = false; Subsite::$write_hostmap = false;
$subsite = $this->objFromFixture('Subsite', 'subsite2'); $subsite = $this->objFromFixture(Subsite::class, 'subsite2');
Subsite::changeSubsite($subsite->ID); Subsite::changeSubsite($subsite->ID);
Subsite::$disable_subsite_filter = false; Subsite::$disable_subsite_filter = false;
@ -152,7 +157,7 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest {
$this->assertTrue($p->ExistsOnLive); $this->assertTrue($p->ExistsOnLive);
// change to subsite // change to subsite
$subsite = $this->objFromFixture('Subsite', 'subsite2'); $subsite = $this->objFromFixture(Subsite::class, 'subsite2');
Subsite::changeSubsite($subsite->ID); Subsite::changeSubsite($subsite->ID);
Subsite::$disable_subsite_filter = false; Subsite::$disable_subsite_filter = false;
@ -187,19 +192,19 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest {
Config::modify()->set('StaticPublisher', 'disable_realtime', true); Config::modify()->set('StaticPublisher', 'disable_realtime', true);
// Go to main site, get parent page // Go to main site, get parent page
$subsite = $this->objFromFixture('Subsite', 'main'); $subsite = $this->objFromFixture(Subsite::class, 'main');
Subsite::changeSubsite($subsite->ID); Subsite::changeSubsite($subsite->ID);
$page = $this->objFromFixture('Page', 'importantpage'); $page = $this->objFromFixture('Page', 'importantpage');
// Create two SVPs on other subsites // Create two SVPs on other subsites
$subsite = $this->objFromFixture('Subsite', 'subsite1'); $subsite = $this->objFromFixture(Subsite::class, 'subsite1');
Subsite::changeSubsite($subsite->ID); Subsite::changeSubsite($subsite->ID);
$vp1 = new SubsitesVirtualPage(); $vp1 = new SubsitesVirtualPage();
$vp1->CopyContentFromID = $page->ID; $vp1->CopyContentFromID = $page->ID;
$vp1->write(); $vp1->write();
$vp1->doPublish(); $vp1->doPublish();
$subsite = $this->objFromFixture('Subsite', 'subsite2'); $subsite = $this->objFromFixture(Subsite::class, 'subsite2');
Subsite::changeSubsite($subsite->ID); Subsite::changeSubsite($subsite->ID);
$vp2 = new SubsitesVirtualPage(); $vp2 = new SubsitesVirtualPage();
$vp2->CopyContentFromID = $page->ID; $vp2->CopyContentFromID = $page->ID;
@ -207,18 +212,18 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest {
$vp2->doPublish(); $vp2->doPublish();
// Switch back to main site, unpublish source // Switch back to main site, unpublish source
$subsite = $this->objFromFixture('Subsite', 'main'); $subsite = $this->objFromFixture(Subsite::class, 'main');
Subsite::changeSubsite($subsite->ID); Subsite::changeSubsite($subsite->ID);
$page = $this->objFromFixture('Page', 'importantpage'); $page = $this->objFromFixture('Page', 'importantpage');
$page->doUnpublish(); $page->doUnpublish();
Subsite::changeSubsite($vp1->SubsiteID); Subsite::changeSubsite($vp1->SubsiteID);
$onLive = Versioned::get_one_by_stage('SubsitesVirtualPage', 'Live', "\"SiteTree_Live\".\"ID\" = ".$vp1->ID); $onLive = Versioned::get_one_by_stage(SubsitesVirtualPage::class, 'Live', "\"SiteTree_Live\".\"ID\" = ".$vp1->ID);
$this->assertNull($onLive, 'SVP has been removed from live'); $this->assertNull($onLive, 'SVP has been removed from live');
$subsite = $this->objFromFixture('Subsite', 'subsite2'); $subsite = $this->objFromFixture(Subsite::class, 'subsite2');
Subsite::changeSubsite($vp2->SubsiteID); Subsite::changeSubsite($vp2->SubsiteID);
$onLive = Versioned::get_one_by_stage('SubsitesVirtualPage', 'Live', "\"SiteTree_Live\".\"ID\" = ".$vp2->ID); $onLive = Versioned::get_one_by_stage(SubsitesVirtualPage::class, 'Live', "\"SiteTree_Live\".\"ID\" = ".$vp2->ID);
$this->assertNull($onLive, 'SVP has been removed from live'); $this->assertNull($onLive, 'SVP has been removed from live');
} }
@ -228,8 +233,8 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest {
*/ */
function testSubsiteVirtualPageCanHaveSameUrlsegmentAsOtherSubsite() { function testSubsiteVirtualPageCanHaveSameUrlsegmentAsOtherSubsite() {
Subsite::$write_hostmap = false; Subsite::$write_hostmap = false;
$subsite1 = $this->objFromFixture('Subsite', 'subsite1'); $subsite1 = $this->objFromFixture(Subsite::class, 'subsite1');
$subsite2 = $this->objFromFixture('Subsite', 'subsite2'); $subsite2 = $this->objFromFixture(Subsite::class, 'subsite2');
Subsite::changeSubsite($subsite1->ID); Subsite::changeSubsite($subsite1->ID);
$subsite1Page = $this->objFromFixture('Page', 'subsite1_staff'); $subsite1Page = $this->objFromFixture('Page', 'subsite1_staff');