diff --git a/.travis.yml b/.travis.yml index c39d558d..9c43f4ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -61,7 +61,7 @@ before_script: - if [[ $BEHAT_TEST ]]; then (vendor/bin/serve --bootstrap-file tests/behat/serve-bootstrap.php &> artifacts/serve.log &); fi script: - - if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests flush=1; fi + - if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/php/ flush=1; fi - if [[ $BEHAT_TEST ]]; then vendor/bin/behat @cms; fi - if [[ $NPM_TEST ]]; then git diff-files --quiet -w --relative=client; fi - if [[ $NPM_TEST ]]; then git diff -w --no-color --relative=client; fi diff --git a/.upgrade.yml b/.upgrade.yml index e9039eb2..4038b207 100644 --- a/.upgrade.yml +++ b/.upgrade.yml @@ -76,5 +76,75 @@ mappings: URLSegmentField: SilverStripe\CMS\Forms\SiteTreeURLSegmentField CMSPagesController_Tools_ss: SilverStripe\CMS\Controllers\CMSPagesController LeftAndMain: SilverStripe\Admin\LeftAndMain + CMSBatchActionsTest: SilverStripe\CMS\Tests\CMSBatchActionsTest + CMSMainTest: SilverStripe\CMS\Tests\CMSMainTest + CMSMainTest_ClassA: SilverStripe\CMS\Tests\CMSMainTest_ClassA + CMSMainTest_ClassB: SilverStripe\CMS\Tests\CMSMainTest_ClassB + CMSMainTest_HiddenClass: SilverStripe\CMS\Tests\CMSMainTest_HiddenClass + CMSMainTest_NotRoot: SilverStripe\CMS\Tests\CMSMainTest_NotRoot + CMSPageHistoryControllerTest: SilverStripe\CMS\Tests\CMSPageHistoryControllerTest + CMSSiteTreeFilterTest: SilverStripe\CMS\Tests\CMSSiteTreeFilterTest + CMSTreeTest: SilverStripe\CMS\Tests\CMSTreeTest + ContentControllerPermissionsTest: SilverStripe\CMS\Tests\ContentControllerPermissionsTest + ContentControllerSearchExtensionTest: SilverStripe\CMS\Tests\ContentControllerSearchExtensionTest + ContentControllerTest: SilverStripe\CMS\Tests\ContentControllerTest + ContentControllerTest_Page: SilverStripe\CMS\Tests\ContentControllerTest_Page + ContentControllerTest_PageController: SilverStripe\CMS\Tests\ContentControllerTest_PageController + ContentControllerTestPage: SilverStripe\CMS\Tests\ContentControllerTestPage + ContentControllerTestPageController: SilverStripe\CMS\Tests\ContentControllerTestPageController + ContentControllerTestPageWithoutController: SilverStripe\CMS\Tests\ContentControllerTestPageWithoutController + ModelAsControllerTest: SilverStripe\CMS\Tests\ModelAsControllerTest + RootURLControllerTest: SilverStripe\CMS\Tests\RootURLControllerTest + SilverStripeNavigatorTest: SilverStripe\CMS\Tests\SilverStripeNavigatorTest + SilverStripeNavigatorTest_ProtectedTestItem: SilverStripe\CMS\Tests\SilverStripeNavigatorTest_ProtectedTestItem + SilverStripeNavigatorTest_TestItem: SilverStripe\CMS\Tests\SilverStripeNavigatorTest_TestItem + FileLinkTrackingTest: SilverStripe\CMS\Tests\FileLinkTrackingTest + RedirectorPageTest: SilverStripe\CMS\Tests\RedirectorPageTest + RedirectorPageTest_RedirectExtension: SilverStripe\CMS\Tests\RedirectorPageTest_RedirectExtension + SiteTreeActionsTest: SilverStripe\CMS\Tests\SiteTreeActionsTest + SiteTreeActionsTest_Page: SilverStripe\CMS\Tests\SiteTreeActionsTest_Page + SiteTreeBacklinksTest: SilverStripe\CMS\Tests\SiteTreeBacklinksTest + SiteTreeBacklinksTest_DOD: SilverStripe\CMS\Tests\SiteTreeBacklinksTest_DOD + SiteTreeBrokenLinksTest: SilverStripe\CMS\Tests\SiteTreeBrokenLinksTest + SiteTreeHTMLEditorFieldTest: SilverStripe\CMS\Tests\SiteTreeHTMLEditorFieldTest + SiteTreeLinkTrackingTest: SilverStripe\CMS\Tests\SiteTreeLinkTrackingTest + SiteTreePermissionsTest: SilverStripe\CMS\Tests\SiteTreePermissionsTest + SiteTreeTest: SilverStripe\CMS\Tests\SiteTreeTest + SiteTreeTest_AdminDenied: SilverStripe\CMS\Tests\SiteTreeTest_AdminDenied + SiteTreeTest_AdminDeniedExtension: SilverStripe\CMS\Tests\SiteTreeTest_AdminDeniedExtension + SiteTreeTest_ClassA: SilverStripe\CMS\Tests\SiteTreeTest_ClassA + SiteTreeTest_ClassB: SilverStripe\CMS\Tests\SiteTreeTest_ClassB + SiteTreeTest_ClassC: SilverStripe\CMS\Tests\SiteTreeTest_ClassC + SiteTreeTest_ClassCext: SilverStripe\CMS\Tests\SiteTreeTest_ClassCext + SiteTreeTest_ClassD: SilverStripe\CMS\Tests\SiteTreeTest_ClassD + SiteTreeTest_ClassE: SilverStripe\CMS\Tests\SiteTreeTest_ClassE + SiteTreeTest_Conflicted: SilverStripe\CMS\Tests\SiteTreeTest_Conflicted + SiteTreeTest_ConflictedController: SilverStripe\CMS\Tests\SiteTreeTest_ConflictedController + SiteTreeTest_DataObject: SilverStripe\CMS\Tests\SiteTreeTest_DataObject + SiteTreeTest_Extension: SilverStripe\CMS\Tests\SiteTreeTest_Extension + SiteTreeTest_ExtensionA: SilverStripe\CMS\Tests\SiteTreeTest_ExtensionA + SiteTreeTest_ExtensionB: SilverStripe\CMS\Tests\SiteTreeTest_ExtensionB + SiteTreeTest_LegacyControllerName: SilverStripe\CMS\Tests\SiteTreeTest_LegacyControllerName + SiteTreeTest_LegacyControllerName_Controller: SilverStripe\CMS\Tests\SiteTreeTest_LegacyControllerName_Controller + SiteTreeTest_NotRoot: SilverStripe\CMS\Tests\SiteTreeTest_NotRoot + SiteTreeTest_NullHtmlCleaner: SilverStripe\CMS\Tests\SiteTreeTest_NullHtmlCleaner + SiteTreeTest_PageNode: SilverStripe\CMS\Tests\SiteTreeTest_PageNode + SiteTreeTest_PageNodeController: SilverStripe\CMS\Tests\SiteTreeTest_PageNodeController + SiteTreeTest_StageStatusInherit: SilverStripe\CMS\Tests\SiteTreeTest_StageStatusInherit + VirtualPageTest: SilverStripe\CMS\Tests\VirtualPageTest + VirtualPageTest_ClassA: SilverStripe\CMS\Tests\VirtualPageTest_ClassA + VirtualPageTest_ClassAController: SilverStripe\CMS\Tests\VirtualPageTest_ClassAController + VirtualPageTest_ClassB: SilverStripe\CMS\Tests\VirtualPageTest_ClassB + VirtualPageTest_ClassC: SilverStripe\CMS\Tests\VirtualPageTest_ClassC + VirtualPageTest_NotRoot: SilverStripe\CMS\Tests\VirtualPageTest_NotRoot + VirtualPageTest_PageExtension: SilverStripe\CMS\Tests\VirtualPageTest_PageExtension + VirtualPageTest_PageWithAllowedChildren: SilverStripe\CMS\Tests\VirtualPageTest_PageWithAllowedChildren + VirtualPageTest_TestDBField: SilverStripe\CMS\Tests\VirtualPageTest_TestDBField + VirtualPageTest_VirtualPageSub: SilverStripe\CMS\Tests\VirtualPageTest_VirtualPageSub + CmsReportsTest: SilverStripe\CMS\Tests\CmsReportsTest + CMSMainSearchFormTest: SilverStripe\CMS\Tests\CMSMainSearchFormTest + ZZZSearchFormTest: SilverStripe\CMS\Tests\ZZZSearchFormTest + MigrateSiteTreeLinkingTaskTest: SilverStripe\CMS\Tests\MigrateSiteTreeLinkingTaskTest + RemoveOrphanedPagesTaskTest: SilverStripe\CMS\Tests\RemoveOrphanedPagesTaskTest excludedPaths: - '*/_config/legacy.yml' diff --git a/composer.json b/composer.json index 9a7a0cf3..a964d82d 100644 --- a/composer.json +++ b/composer.json @@ -40,14 +40,16 @@ } }, "scripts": { - "lint": "phpcs -s code/ tests/" + "lint": "phpcs -s code/ tests/php/ tests/behat/src/", + "lint-clean": "phpcbf code/ tests/php/ tests/behat/src/" }, "autoload": { "psr-4": { "SilverStripe\\CMS\\": "code/", + "SilverStripe\\CMS\\Tests\\": "code/php/", "SilverStripe\\CMS\\Tests\\Behaviour\\": "tests/behat/src/" } }, "prefer-stable": true, "minimum-stability": "dev" -} \ No newline at end of file +} diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 7ea013ab..0238f051 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -9,10 +9,6 @@ - - - - diff --git a/tests/controller/ContentControllerTestPage.php b/tests/controller/ContentControllerTestPage.php deleted file mode 100644 index 7208516a..00000000 --- a/tests/controller/ContentControllerTestPage.php +++ /dev/null @@ -1,8 +0,0 @@ -get(CacheInterface::class . '.CMSMain_SiteTreeHints'); // Login as user with root creation privileges - $user = $this->objFromFixture('SilverStripe\\Security\\Member', 'rootedituser'); + $user = $this->objFromFixture(Member::class, 'rootedituser'); Security::setCurrentUser($user); $cache->clear(); - $rawHints = singleton('SilverStripe\\CMS\\Controllers\\CMSMain')->SiteTreeHints(); + $rawHints = singleton(CMSMain::class)->SiteTreeHints(); $this->assertNotNull($rawHints); $rawHints = preg_replace('/^"(.*)"$/', '$1', Convert::xml2raw($rawHints)); @@ -65,25 +62,25 @@ class CMSMainTest extends FunctionalTest $this->assertArrayHasKey('All', $hints); $this->assertArrayHasKey( - 'CMSMainTest_ClassA', + CMSMainTest_ClassA::class, $hints['All'], 'Global list shows allowed classes' ); $this->assertArrayNotHasKey( - 'CMSMainTest_HiddenClass', + CMSMainTest_HiddenClass::class, $hints['All'], 'Global list does not list hidden classes' ); $this->assertNotContains( - 'CMSMainTest_ClassA', + CMSMainTest_ClassA::class, $hints['Root']['disallowedChildren'], 'Limits root classes' ); $this->assertContains( - 'CMSMainTest_NotRoot', + CMSMainTest_NotRoot::class, $hints['Root']['disallowedChildren'], 'Limits root classes' ); @@ -113,7 +110,7 @@ class CMSMainTest extends FunctionalTest // But it can create a ClassB $this->assertNotContains( - 'CMSMainTest_ClassB', + CMSMainTest_ClassB::class, $children, 'Limited parent omits explicitly allowed classes in disallowedChildren' ); @@ -126,7 +123,7 @@ class CMSMainTest extends FunctionalTest { $page1 = $this->objFromFixture(Page::class, "page1"); $page2 = $this->objFromFixture(Page::class, "page2"); - $this->session()->set('loggedInAs', $this->idFromFixture('SilverStripe\\Security\\Member', 'admin')); + $this->session()->set('loggedInAs', $this->idFromFixture(Member::class, 'admin')); $response = $this->get('admin/pages/publishall?confirm=1'); $this->assertContains( @@ -278,8 +275,8 @@ class CMSMainTest extends FunctionalTest $origFollow = $this->autoFollowRedirection; $this->autoFollowRedirection = false; - $cmsUser = $this->objFromFixture('SilverStripe\\Security\\Member', 'allcmssectionsuser'); - $rootEditUser = $this->objFromFixture('SilverStripe\\Security\\Member', 'rootedituser'); + $cmsUser = $this->objFromFixture(Member::class, 'allcmssectionsuser'); + $rootEditUser = $this->objFromFixture(Member::class, 'rootedituser'); // with insufficient permissions Security::setCurrentUser($cmsUser); @@ -332,7 +329,7 @@ class CMSMainTest extends FunctionalTest $origFollow = $this->autoFollowRedirection; $this->autoFollowRedirection = false; - $adminUser = $this->objFromFixture('SilverStripe\\Security\\Member', 'admin'); + $adminUser = $this->objFromFixture(Member::class, 'admin'); Security::setCurrentUser($adminUser); // Create toplevel page @@ -341,7 +338,7 @@ class CMSMainTest extends FunctionalTest 'admin/pages/add/AddForm', array( 'ParentID' => '0', - 'PageType' => 'CMSMainTest_ClassA', + 'PageType' => CMSMainTest_ClassA::class, 'Locale' => 'en_US', 'action_doAdd' => 1, 'ajax' => 1 @@ -361,7 +358,7 @@ class CMSMainTest extends FunctionalTest 'admin/pages/add/AddForm', array( 'ParentID' => $newPageId, - 'PageType' => 'CMSMainTest_ClassB', + 'PageType' => CMSMainTest_ClassB::class, 'Locale' => 'en_US', 'action_doAdd' => 1, 'ajax' => 1 @@ -407,7 +404,7 @@ class CMSMainTest extends FunctionalTest { $page3 = $this->objFromFixture(Page::class, 'page3'); $page31 = $this->objFromFixture(Page::class, 'page31'); - $adminuser = $this->objFromFixture('SilverStripe\\Security\\Member', 'admin'); + $adminuser = $this->objFromFixture(Member::class, 'admin'); Security::setCurrentUser($adminuser); $response = $this->get('admin/pages/edit/show/' . $page31->ID); @@ -567,17 +564,17 @@ class CMSMainTest extends FunctionalTest $page->write(); $form = $cms->getEditForm($page->ID); - $form->loadDataFrom(['ClassName' => 'CMSMainTest_ClassB']); + $form->loadDataFrom(['ClassName' => CMSMainTest_ClassB::class]); $result = $cms->save([ 'ID' => $page->ID, - 'ClassName' => 'CMSMainTest_ClassB' + 'ClassName' => CMSMainTest_ClassB::class ], $form); $this->assertEquals(200, $result->getStatusCode()); $newPage = SiteTree::get()->byID($page->ID); - $this->assertInstanceOf('CMSMainTest_ClassB', $newPage); - $this->assertEquals('CMSMainTest_ClassB', $newPage->ClassName); + $this->assertInstanceOf(CMSMainTest_ClassB::class, $newPage); + $this->assertEquals(CMSMainTest_ClassB::class, $newPage->ClassName); $this->assertEquals('Class A', $newPage->Title); } } diff --git a/tests/controller/CMSMainTest.yml b/tests/php/Controllers/CMSMainTest.yml similarity index 100% rename from tests/controller/CMSMainTest.yml rename to tests/php/Controllers/CMSMainTest.yml diff --git a/tests/controller/CMSMainTest_ClassA.php b/tests/php/Controllers/CMSMainTest_ClassA.php similarity index 66% rename from tests/controller/CMSMainTest_ClassA.php rename to tests/php/Controllers/CMSMainTest_ClassA.php index afbdb743..9f507739 100644 --- a/tests/controller/CMSMainTest_ClassA.php +++ b/tests/php/Controllers/CMSMainTest_ClassA.php @@ -1,11 +1,16 @@ ID; $deletedPage->delete(); $deletedPage = Versioned::get_one_by_stage( - 'SilverStripe\\CMS\\Model\\SiteTree', + SiteTree::class, 'Live', array('"SiteTree_Live"."ID"' => $deletedPageID) ); @@ -125,7 +127,7 @@ class CMSSiteTreeFilterTest extends SapphireTest { $draftPage = $this->objFromFixture('Page', 'page4'); $draftPage = Versioned::get_one_by_stage( - 'SilverStripe\\CMS\\Model\\SiteTree', + SiteTree::class, 'Stage', sprintf('"SiteTree"."ID" = %d', $draftPage->ID) ); @@ -163,7 +165,7 @@ class CMSSiteTreeFilterTest extends SapphireTest $removedDraftPage->publishRecursive(); $removedDraftPage->deleteFromStage('Stage'); $removedDraftPage = Versioned::get_one_by_stage( - 'SilverStripe\\CMS\\Model\\SiteTree', + SiteTree::class, 'Live', sprintf('"SiteTree"."ID" = %d', $removedDraftPage->ID) ); diff --git a/tests/controller/CMSSiteTreeFilterTest.yml b/tests/php/Controllers/CMSSiteTreeFilterTest.yml similarity index 100% rename from tests/controller/CMSSiteTreeFilterTest.yml rename to tests/php/Controllers/CMSSiteTreeFilterTest.yml diff --git a/tests/controller/CMSTreeTest.php b/tests/php/Controllers/CMSTreeTest.php similarity index 99% rename from tests/controller/CMSTreeTest.php rename to tests/php/Controllers/CMSTreeTest.php index a8f8e3da..7462e82d 100644 --- a/tests/controller/CMSTreeTest.php +++ b/tests/php/Controllers/CMSTreeTest.php @@ -1,5 +1,7 @@ ParentID = $parentID; - $page->Title = "Page Level $i"; + $page->Title = "Page Level $i"; $page->URLSegment = "level-$i"; $page->write(); @@ -154,13 +152,11 @@ class ContentControllerTest extends FunctionalTest /** * Tests that {@link ContentController::getViewer()} chooses the correct templates. * - * @covers SilverStripe\CMS\Controllers\ContentController::getViewer() - **/ + * @covers \SilverStripe\CMS\Controllers\ContentController::getViewer() + **/ public function testGetViewer() { - - $self = $this; - $this->useTestTheme(dirname(__FILE__), 'controllertest', function () use ($self) { + $this->useTestTheme(__DIR__, 'controllertest', function () { // Test a page without a controller (ContentControllerTest_PageWithoutController.ss) $page = new ContentControllerTestPageWithoutController(); @@ -168,8 +164,8 @@ class ContentControllerTest extends FunctionalTest $page->write(); $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); - $response = $self->get($page->RelativeLink()); - $self->assertEquals("ContentControllerTestPageWithoutController", trim($response->getBody())); + $response = $this->get($page->RelativeLink()); + $this->assertEquals("ContentControllerTestPageWithoutController", trim($response->getBody())); // // This should fall over to user Page.ss $page = new ContentControllerTestPage(); @@ -177,8 +173,8 @@ class ContentControllerTest extends FunctionalTest $page->write(); $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); - $response = $self->get($page->RelativeLink()); - $self->assertEquals("Page", trim($response->getBody())); + $response = $this->get($page->RelativeLink()); + $this->assertEquals("Page", trim($response->getBody())); // Test that the action template is rendered. @@ -187,20 +183,24 @@ class ContentControllerTest extends FunctionalTest $page->write(); $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); - $response = $self->get($page->RelativeLink("test")); - $self->assertEquals("ContentControllerTestPage_test", trim($response->getBody())); + $response = $this->get($page->RelativeLink("test")); + $this->assertEquals("ContentControllerTestPage_test", trim($response->getBody())); // Test that an action without a template will default to the index template, which is // to say the default Page.ss template - $response = $self->get($page->RelativeLink("testwithouttemplate")); - $self->assertEquals("Page", trim($response->getBody())); + $response = $this->get($page->RelativeLink("testwithouttemplate")); + $this->assertEquals("Page", trim($response->getBody())); // Test that an action with a template will render the both action template *and* the // correct parent template $controller = new ContentController($page); $viewer = $controller->getViewer('test'); - $templateList = array('ContentControllerTestPage_test', 'Page'); - $self->assertEquals(dirname(__FILE__).'/themes/controllertest/templates/ContentControllerTestPage_test.ss', $viewer->templates()['main']); + $this->assertEquals( + __DIR__ + . '/themes/controllertest/templates/SilverStripe/CMS/Tests/Controllers/' + . 'ContentControllerTestPage_test.ss', + $viewer->templates()['main'] + ); }); } } diff --git a/tests/controller/ContentControllerTest.yml b/tests/php/Controllers/ContentControllerTest.yml similarity index 73% rename from tests/controller/ContentControllerTest.yml rename to tests/php/Controllers/ContentControllerTest.yml index dd65c4c3..d317dc76 100644 --- a/tests/controller/ContentControllerTest.yml +++ b/tests/php/Controllers/ContentControllerTest.yml @@ -21,22 +21,22 @@ SilverStripe\Security\Member: Surname: Administrator Groups: =>SilverStripe\Security\Group.admins -ContentControllerTest_Page: +SilverStripe\CMS\Tests\Controllers\ContentControllerTest_Page: root_page: Title: Home Page URLSegment: home second_level_page: Title: Second Level Page URLSegment: second-level - Parent: =>ContentControllerTest_Page.root_page + Parent: =>SilverStripe\CMS\Tests\Controllers\ContentControllerTest_Page.root_page third_level_page: Title: Third Level Page URLSegment: third-level - Parent: =>ContentControllerTest_Page.second_level_page + Parent: =>SilverStripe\CMS\Tests\Controllers\ContentControllerTest_Page.second_level_page third_level_page_2: Title: Third Level Page Two URLSegment: third-level-2 - Parent: =>ContentControllerTest_Page.second_level_page + Parent: =>SilverStripe\CMS\Tests\Controllers\ContentControllerTest_Page.second_level_page contact_page: Title: Contact Page URLSegment: contact diff --git a/tests/php/Controllers/ContentControllerTestPage.php b/tests/php/Controllers/ContentControllerTestPage.php new file mode 100644 index 00000000..0c67a3b7 --- /dev/null +++ b/tests/php/Controllers/ContentControllerTestPage.php @@ -0,0 +1,11 @@ +assertContains( - 'SilverStripeNavigatorTest_TestItem', + SilverStripeNavigatorTest_TestItem::class, $classes, 'Autodiscovers new classes' ); @@ -49,11 +41,11 @@ class SilverStripeNavigatorTest extends SapphireTest $this->logInWithPermission('CMS_ACCESS_CMSMain'); $items = $navigator->getItems(); $classes = array_map('get_class', $items->toArray()); - $this->assertNotContains('SilverStripeNavigatorTest_ProtectedTestItem', $classes); + $this->assertNotContains(SilverStripeNavigatorTest_ProtectedTestItem::class, $classes); $this->logInWithPermission('ADMIN'); $items = $navigator->getItems(); $classes = array_map('get_class', $items->toArray()); - $this->assertContains('SilverStripeNavigatorTest_ProtectedTestItem', $classes); + $this->assertContains(SilverStripeNavigatorTest_ProtectedTestItem::class, $classes); } } diff --git a/tests/controller/SilverStripeNavigatorTest_ProtectedTestItem.php b/tests/php/Controllers/SilverStripeNavigatorTest_ProtectedTestItem.php similarity index 92% rename from tests/controller/SilverStripeNavigatorTest_ProtectedTestItem.php rename to tests/php/Controllers/SilverStripeNavigatorTest_ProtectedTestItem.php index c33122a8..0343a101 100644 --- a/tests/controller/SilverStripeNavigatorTest_ProtectedTestItem.php +++ b/tests/php/Controllers/SilverStripeNavigatorTest_ProtectedTestItem.php @@ -1,4 +1,7 @@ objFromFixture(RedirectorPage::class, 'goodinternal'); - RedirectorPageController::add_extension('RedirectorPageTest_RedirectExtension'); + RedirectorPageController::add_extension(RedirectorPageTest_RedirectExtension::class); $response = $this->get($page->regularLink()); $this->assertEquals(302, $response->getStatusCode()); $this->assertEquals('http://www.mysite.com/foo', $response->getHeader('Location')); - RedirectorPageController::remove_extension('RedirectorPageTest_RedirectExtension'); + RedirectorPageController::remove_extension(RedirectorPageTest_RedirectExtension::class); } public function testNoJSLinksAllowed() diff --git a/tests/model/RedirectorPageTest.yml b/tests/php/Model/RedirectorPageTest.yml similarity index 100% rename from tests/model/RedirectorPageTest.yml rename to tests/php/Model/RedirectorPageTest.yml diff --git a/tests/model/RedirectorPageTest_RedirectExtension.php b/tests/php/Model/RedirectorPageTest_RedirectExtension.php similarity index 85% rename from tests/model/RedirectorPageTest_RedirectExtension.php rename to tests/php/Model/RedirectorPageTest_RedirectExtension.php index 58479a6c..6af5e2af 100644 --- a/tests/model/RedirectorPageTest_RedirectExtension.php +++ b/tests/php/Model/RedirectorPageTest_RedirectExtension.php @@ -1,11 +1,12 @@ owner->redirect('/foo'); diff --git a/tests/model/SiteTreeActionsTest.php b/tests/php/Model/SiteTreeActionsTest.php similarity index 98% rename from tests/model/SiteTreeActionsTest.php rename to tests/php/Model/SiteTreeActionsTest.php index 730137a0..08aa185c 100644 --- a/tests/model/SiteTreeActionsTest.php +++ b/tests/php/Model/SiteTreeActionsTest.php @@ -1,13 +1,14 @@ objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'home'); + $sitetree = $this->objFromFixture(SiteTree::class, 'home'); $editor = new HTMLEditorField('Content'); - $aboutID = $this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'about'); - $contactID = $this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'contact'); + $aboutID = $this->idFromFixture(SiteTree::class, 'about'); + $contactID = $this->idFromFixture(SiteTree::class, 'contact'); $editor->setValue("Example Link"); $editor->saveInto($sitetree); @@ -77,7 +79,7 @@ class SiteTreeHTMLEditorFieldTest extends FunctionalTest public function testFileLinkTracking() { - $sitetree = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'home'); + $sitetree = $this->objFromFixture(SiteTree::class, 'home'); $editor = new HTMLEditorField('Content'); $fileID = $this->idFromFixture('SilverStripe\\Assets\\File', 'example_file'); @@ -138,7 +140,7 @@ class SiteTreeHTMLEditorFieldTest extends FunctionalTest public function testImageTracking() { - $sitetree = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'home'); + $sitetree = $this->objFromFixture(SiteTree::class, 'home'); $editor = new HTMLEditorField('Content'); $file = $this->objFromFixture('SilverStripe\\Assets\\Image', 'example_image'); @@ -175,7 +177,7 @@ class SiteTreeHTMLEditorFieldTest extends FunctionalTest $editor->setValue(sprintf( '

Working Link

', - $this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'home') + $this->idFromFixture(SiteTree::class, 'home') )); $sitetree->HasBrokenLink = false; $editor->saveInto($sitetree); diff --git a/tests/model/SiteTreeHTMLEditorFieldTest.yml b/tests/php/Model/SiteTreeHTMLEditorFieldTest.yml similarity index 100% rename from tests/model/SiteTreeHTMLEditorFieldTest.yml rename to tests/php/Model/SiteTreeHTMLEditorFieldTest.yml diff --git a/tests/model/SiteTreeLinkTrackingTest.php b/tests/php/Model/SiteTreeLinkTrackingTest.php similarity index 98% rename from tests/model/SiteTreeLinkTrackingTest.php rename to tests/php/Model/SiteTreeLinkTrackingTest.php index d16831ef..8363af52 100644 --- a/tests/model/SiteTreeLinkTrackingTest.php +++ b/tests/php/Model/SiteTreeLinkTrackingTest.php @@ -1,9 +1,12 @@ setParent($parent); - $this->assertInstanceOf('SiteTreeTest_PageNode', $child->Parent); + $this->assertInstanceOf(SiteTreeTest_PageNode::class, $child->Parent); } /** @@ -635,7 +628,7 @@ class SiteTreeTest extends SapphireTest $this->assertTrue(singleton(SiteTree::class)->canCreate(null, array('Parent' => singleton(SiteTree::class)))); //Test we don't check for allowedChildren on parent context if it's not SiteTree instance - $this->assertTrue(singleton(SiteTree::class)->canCreate(null, ['Parent' => $this->objFromFixture('SiteTreeTest_DataObject', 'relations')])); + $this->assertTrue(singleton(SiteTree::class)->canCreate(null, ['Parent' => $this->objFromFixture(SiteTreeTest_DataObject::class, 'relations')])); } public function testEditPermissionsOnDraftVsLive() @@ -690,7 +683,7 @@ class SiteTreeTest extends SapphireTest { // Necessary to avoid $oldCleanerClass = Diff::$html_cleaner_class; - Diff::$html_cleaner_class = 'SiteTreeTest_NullHtmlCleaner'; + Diff::$html_cleaner_class = SiteTreeTest_NullHtmlCleaner::class; $page = new Page(); $page->write(); @@ -947,7 +940,7 @@ class SiteTreeTest extends SapphireTest Config::modify()->set(SiteTree::class, 'nested_urls', true); $sitetree = new SiteTree(); - $sitetree->ParentID = $this->idFromFixture('SiteTreeTest_Conflicted', 'parent'); + $sitetree->ParentID = $this->idFromFixture(SiteTreeTest_Conflicted::class, 'parent'); $sitetree->URLSegment = 'index'; $this->assertFalse($sitetree->validURLSegment(), 'index is not a valid URLSegment'); @@ -968,11 +961,11 @@ class SiteTreeTest extends SapphireTest $sitetree->URLSegment = 'unique-segment'; $this->assertTrue($sitetree->validURLSegment()); - SiteTree::add_extension('SiteTreeTest_Extension'); + SiteTree::add_extension(SiteTreeTest_Extension::class); $sitetree = new SiteTree(); $sitetree->URLSegment = 'unique-segment'; $this->assertFalse($sitetree->validURLSegment()); - SiteTree::remove_extension('SiteTreeTest_Extension'); + SiteTree::remove_extension(SiteTreeTest_Extension::class); } public function testURLSegmentMultiByte() @@ -1424,6 +1417,6 @@ class SiteTreeTest extends SapphireTest public function testGetControllerNameWithUnderscoresIsSupported() { $class = new SiteTreeTest_LegacyControllerName; - $this->assertSame('SiteTreeTest_LegacyControllerName_Controller', $class->getControllerName()); + $this->assertEquals(SiteTreeTest_LegacyControllerName_Controller::class, $class->getControllerName()); } } diff --git a/tests/model/SiteTreeTest.yml b/tests/php/Model/SiteTreeTest.yml similarity index 95% rename from tests/model/SiteTreeTest.yml rename to tests/php/Model/SiteTreeTest.yml index 68a4fff6..3b570f3b 100755 --- a/tests/model/SiteTreeTest.yml +++ b/tests/php/Model/SiteTreeTest.yml @@ -113,7 +113,7 @@ Page: Title: 'Breadcrumbs 5' Parent: =>Page.breadcrumbs4 -SiteTreeTest_Conflicted: +SilverStripe\CMS\Tests\Model\SiteTreeTest_Conflicted: parent: Title: Parent @@ -124,7 +124,7 @@ SilverStripe\CMS\Model\RedirectorPage: RedirectionType: External ExternalURL: "http://www.google.com?a&b" -SiteTreeTest_DataObject: +SilverStripe\CMS\Tests\Model\SiteTreeTest_DataObject: relations: Title: 'Linked DataObject' - Pages: =>Page.home,=>Page.about,=>Page.staff \ No newline at end of file + Pages: =>Page.home,=>Page.about,=>Page.staff diff --git a/tests/php/Model/SiteTreeTest_AdminDenied.php b/tests/php/Model/SiteTreeTest_AdminDenied.php new file mode 100644 index 00000000..7b50ccf1 --- /dev/null +++ b/tests/php/Model/SiteTreeTest_AdminDenied.php @@ -0,0 +1,15 @@ + array('SiteTreeSubsites', 'Translatable'), + SiteTree::class => [ + 'SiteTreeSubsites', + 'Translatable' + ], ); protected static $required_extensions = array( - SiteTree::class => array('VirtualPageTest_PageExtension') + SiteTree::class => [ + VirtualPageTest_PageExtension::class + ] ); public function setUp() @@ -46,7 +53,11 @@ class VirtualPageTest extends FunctionalTest // Add extra fields Config::modify()->merge(VirtualPage::class, 'initially_copied_fields', array('MyInitiallyCopiedField')); - Config::modify()->merge(VirtualPage::class, 'non_virtual_fields', array('MyNonVirtualField', 'MySharedNonVirtualField')); + Config::modify()->merge( + VirtualPage::class, + 'non_virtual_fields', + array('MyNonVirtualField', 'MySharedNonVirtualField') + ); } /** @@ -80,6 +91,7 @@ class VirtualPageTest extends FunctionalTest { $this->logInWithPermission('ADMIN'); + /** @var Page $master */ $master = $this->objFromFixture('Page', 'master'); $master->publishRecursive(); @@ -88,7 +100,9 @@ class VirtualPageTest extends FunctionalTest $master->Content = "

New content

"; $master->write(); + /** @var VirtualPage $vp1 */ $vp1 = DataObject::get_by_id(VirtualPage::class, $this->idFromFixture(VirtualPage::class, 'vp1')); + /** @var VirtualPage $vp2 */ $vp2 = DataObject::get_by_id(VirtualPage::class, $this->idFromFixture(VirtualPage::class, 'vp2')); $this->assertTrue($vp1->publishRecursive()); $this->assertTrue($vp2->publishRecursive()); @@ -221,6 +235,7 @@ class VirtualPageTest extends FunctionalTest /** @var Page $parentPage */ $parentPage = $this->objFromFixture('Page', 'master3'); $parentPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); + /** @var VirtualPage $virtualPage */ $virtualPage = $this->objFromFixture(VirtualPage::class, 'vp3'); $virtualPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $cindy = $this->objFromFixture(Member::class, 'cindy'); @@ -309,10 +324,8 @@ class VirtualPageTest extends FunctionalTest $vp->flushCache(); $vp = DataObject::get_by_id(SiteTree::class, $vpID); $this->assertEquals($p->ID, $vp->CopyContentFromID); - - $vpLive = Versioned::get_one_by_stage(SiteTree::class, Versioned::LIVE, '"SiteTree"."ID" = ' . $vpID); + $vpLive = Versioned::get_by_stage(SiteTree::class, Versioned::LIVE)->byID($vpID); $this->assertNull($vpLive); - // Delete from draft, ensure virtual page deletion cascades $p->delete(); $vp->flushCache(); @@ -335,7 +348,6 @@ class VirtualPageTest extends FunctionalTest // All is fine, the virtual page doesn't have a broken link $this->assertFalse($vp->HasBrokenLink); - // Delete the source page from draft, cascades to virtual page $pID = $p->ID; $p->delete(); @@ -343,8 +355,8 @@ class VirtualPageTest extends FunctionalTest $vpDraft = Versioned::get_by_stage(SiteTree::class, Versioned::DRAFT) ->byID($pID); $this->assertNull($vpDraft); - // Delete the source page form live, confirm that the virtual page has also been unpublished + /** @var Page $pLive */ $pLive = Versioned::get_by_stage(SiteTree::class, Versioned::LIVE) ->byID($pID); $this->assertTrue($pLive->doUnpublish()); @@ -484,14 +496,19 @@ class VirtualPageTest extends FunctionalTest $nonVirtual = $virtual; - $nonVirtual->ClassName = 'VirtualPageTest_ClassA'; + $nonVirtual->ClassName = VirtualPageTest_ClassA::class; $nonVirtual->MySharedNonVirtualField = 'changed on new type'; $nonVirtual->write(); // not publishing the page type change here // Stage record is changed to the new type and no longer acts as a virtual page - $nonVirtualStage = Versioned::get_one_by_stage(SiteTree::class, 'Stage', '"SiteTree"."ID" = ' . $nonVirtual->ID, false); + $nonVirtualStage = Versioned::get_one_by_stage( + SiteTree::class, + 'Stage', + '"SiteTree"."ID" = ' . $nonVirtual->ID, + false + ); $this->assertNotNull($nonVirtualStage); - $this->assertEquals('VirtualPageTest_ClassA', $nonVirtualStage->ClassName); + $this->assertEquals(VirtualPageTest_ClassA::class, $nonVirtualStage->ClassName); $this->assertEquals('changed on new type', $nonVirtualStage->MySharedNonVirtualField); $this->assertEquals( 'original', @@ -500,9 +517,14 @@ class VirtualPageTest extends FunctionalTest ); // Virtual page on live keeps working as it should - $virtualLive = Versioned::get_one_by_stage(SiteTree::class, Versioned::LIVE, '"SiteTree_Live"."ID" = ' . $virtual->ID, false); + $virtualLive = Versioned::get_one_by_stage( + SiteTree::class, + Versioned::LIVE, + '"SiteTree_Live"."ID" = ' . $virtual->ID, + false + ); $this->assertNotNull($virtualLive); - $this->assertEquals('VirtualPageTest_VirtualPageSub', $virtualLive->ClassName); + $this->assertEquals(VirtualPageTest_VirtualPageSub::class, $virtualLive->ClassName); $this->assertEquals('virtual published field', $virtualLive->MySharedNonVirtualField); $this->assertEquals('published title', $virtualLive->Title); @@ -513,7 +535,12 @@ class VirtualPageTest extends FunctionalTest $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); // Virtual page only notices changes to virtualised fields (Title) - $virtualLive = Versioned::get_one_by_stage(SiteTree::class, Versioned::LIVE, '"SiteTree_Live"."ID" = ' . $virtual->ID, false); + $virtualLive = Versioned::get_one_by_stage( + SiteTree::class, + Versioned::LIVE, + '"SiteTree_Live"."ID" = ' . $virtual->ID, + false + ); $this->assertEquals('virtual published field', $virtualLive->MySharedNonVirtualField); $this->assertEquals('title changed on original', $virtualLive->Title); } @@ -527,7 +554,7 @@ class VirtualPageTest extends FunctionalTest $virtual->CopyContentFromID = $page->ID; $virtual->write(); - $this->assertEquals('VirtualPageTest_TestDBField', $virtual->castingHelper('CastingTest')); + $this->assertEquals(VirtualPageTest_TestDBField::class, $virtual->castingHelper('CastingTest')); $this->assertEquals('SOME CONTENT', $virtual->obj('CastingTest')->forTemplate()); } @@ -610,10 +637,11 @@ class VirtualPageTest extends FunctionalTest public function testMethod() { + /** @var VirtualPage $virtualPage */ $virtualPage = $this->objFromFixture(VirtualPage::class, 'vp4'); + /** @var VirtualPageTest_ClassAController $controller */ $controller = ModelAsController::controller_for($virtualPage); - - $this->assertInstanceOf('VirtualPageTest_ClassAController', $controller); + $this->assertInstanceOf(VirtualPageTest_ClassAController::class, $controller); $this->assertTrue($controller->hasMethod('testMethod')); $this->assertEquals('hello', $controller->testMethod()); $this->assertTrue($controller->hasMethod('modelMethod')); @@ -622,6 +650,7 @@ class VirtualPageTest extends FunctionalTest public function testAllowedActions() { + /** @var VirtualPage $virtualPage */ $virtualPage = $this->objFromFixture(VirtualPage::class, 'vp4'); $controller = ModelAsController::controller_for($virtualPage); $this->assertContains('testaction', $controller->allowedActions()); diff --git a/tests/model/VirtualPageTest.yml b/tests/php/Model/VirtualPageTest.yml similarity index 92% rename from tests/model/VirtualPageTest.yml rename to tests/php/Model/VirtualPageTest.yml index 75a82946..59571e47 100644 --- a/tests/model/VirtualPageTest.yml +++ b/tests/php/Model/VirtualPageTest.yml @@ -45,7 +45,7 @@ Page: CanEditType: OnlyTheseUsers CanViewType: Inherit EditorGroups: =>SilverStripe\Security\Group.bobgroup -VirtualPageTest_ClassA: +SilverStripe\CMS\Tests\Model\VirtualPageTest_ClassA: pagea: Title: 'Page A' Content: '

Content

' @@ -66,5 +66,5 @@ SilverStripe\CMS\Model\VirtualPage: EditorGroups: =>SilverStripe\Security\Group.andrewgroup ViewerGroups: =>SilverStripe\Security\Group.cindygroup vp4: - CopyContentFrom: =>VirtualPageTest_ClassA.pagea + CopyContentFrom: =>SilverStripe\CMS\Tests\Model\VirtualPageTest_ClassA.pagea Title: 'vp4' diff --git a/tests/model/VirtualPageTest_ClassA.php b/tests/php/Model/VirtualPageTest_ClassA.php similarity index 56% rename from tests/model/VirtualPageTest_ClassA.php rename to tests/php/Model/VirtualPageTest_ClassA.php index 53331e04..3c11298e 100644 --- a/tests/model/VirtualPageTest_ClassA.php +++ b/tests/php/Model/VirtualPageTest_ClassA.php @@ -1,17 +1,24 @@ 'Text', 'MyVirtualField' => 'Text', 'MyNonVirtualField' => 'Text', - 'CastingTest' => 'VirtualPageTest_TestDBField' + 'CastingTest' => VirtualPageTest_TestDBField::class, ); - private static $allowed_children = array('VirtualPageTest_ClassB'); + private static $allowed_children = [ + VirtualPageTest_ClassB::class, + ]; public function modelMethod() { diff --git a/tests/model/VirtualPageTest_ClassAController.php b/tests/php/Model/VirtualPageTest_ClassAController.php similarity index 81% rename from tests/model/VirtualPageTest_ClassAController.php rename to tests/php/Model/VirtualPageTest_ClassAController.php index 986e44be..578d9db3 100644 --- a/tests/model/VirtualPageTest_ClassAController.php +++ b/tests/php/Model/VirtualPageTest_ClassAController.php @@ -1,6 +1,9 @@ 'Varchar', ); diff --git a/tests/model/themes/virtualpagetest/templates/Page.ss b/tests/php/Model/themes/virtualpagetest/templates/Page.ss similarity index 100% rename from tests/model/themes/virtualpagetest/templates/Page.ss rename to tests/php/Model/themes/virtualpagetest/templates/Page.ss diff --git a/tests/model/themes/virtualpagetest/templates/VirtualPageTest_ClassA.ss b/tests/php/Model/themes/virtualpagetest/templates/SilverStripe/CMS/Tests/Model/VirtualPageTest_ClassA.ss similarity index 100% rename from tests/model/themes/virtualpagetest/templates/VirtualPageTest_ClassA.ss rename to tests/php/Model/themes/virtualpagetest/templates/SilverStripe/CMS/Tests/Model/VirtualPageTest_ClassA.ss diff --git a/tests/reports/CmsReportsTest.php b/tests/php/Reports/CmsReportsTest.php similarity index 98% rename from tests/reports/CmsReportsTest.php rename to tests/php/Reports/CmsReportsTest.php index ed54b652..03a8437d 100644 --- a/tests/reports/CmsReportsTest.php +++ b/tests/php/Reports/CmsReportsTest.php @@ -1,5 +1,7 @@ session()->set('loggedInAs', $this->idFromFixture('SilverStripe\\Security\\Member', 'admin')); + $this->session()->set('loggedInAs', $this->idFromFixture(Member::class, 'admin')); $response = $this->get( 'admin/pages/SearchForm/?' . diff --git a/tests/search/SearchFormTest.php b/tests/php/Search/SearchFormTest.php similarity index 99% rename from tests/search/SearchFormTest.php rename to tests/php/Search/SearchFormTest.php index 7269f570..617860af 100644 --- a/tests/search/SearchFormTest.php +++ b/tests/php/Search/SearchFormTest.php @@ -1,25 +1,25 @@ idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'home'); - $aboutID = $this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'about'); - $staffID = $this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'staff'); - $actionID = $this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'action'); - $hashID = $this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'hash_link'); + $homeID = $this->idFromFixture(SiteTree::class, 'home'); + $aboutID = $this->idFromFixture(SiteTree::class, 'about'); + $staffID = $this->idFromFixture(SiteTree::class, 'staff'); + $actionID = $this->idFromFixture(SiteTree::class, 'action'); + $hashID = $this->idFromFixture(SiteTree::class, 'hash_link'); $homeContent = sprintf( 'AboutStaffExternal Link', @@ -62,25 +60,25 @@ class MigrateSiteTreeLinkingTaskTest extends SapphireTest $this->assertEquals( $homeContent, - DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $homeID)->Content, + DataObject::get_by_id(SiteTree::class, $homeID)->Content, 'HTML URLSegment links are rewritten.' ); $this->assertEquals( $aboutContent, - DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $aboutID)->Content + DataObject::get_by_id(SiteTree::class, $aboutID)->Content ); $this->assertEquals( $staffContent, - DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $staffID)->Content + DataObject::get_by_id(SiteTree::class, $staffID)->Content ); $this->assertEquals( $actionContent, - DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $actionID)->Content, + DataObject::get_by_id(SiteTree::class, $actionID)->Content, 'Links to actions on pages are rewritten correctly.' ); $this->assertEquals( $hashLinkContent, - DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $hashID)->Content, + DataObject::get_by_id(SiteTree::class, $hashID)->Content, 'Hash/anchor links are correctly handled.' ); } diff --git a/tests/tasks/MigrateSiteTreeLinkingTaskTest.yml b/tests/php/Tasks/MigrateSiteTreeLinkingTaskTest.yml similarity index 100% rename from tests/tasks/MigrateSiteTreeLinkingTaskTest.yml rename to tests/php/Tasks/MigrateSiteTreeLinkingTaskTest.yml diff --git a/tests/tasks/RemoveOrphanedPagesTaskTest.php b/tests/php/Tasks/RemoveOrphanedPagesTaskTest.php similarity index 99% rename from tests/tasks/RemoveOrphanedPagesTaskTest.php rename to tests/php/Tasks/RemoveOrphanedPagesTaskTest.php index 38046c4e..22577d71 100644 --- a/tests/tasks/RemoveOrphanedPagesTaskTest.php +++ b/tests/php/Tasks/RemoveOrphanedPagesTaskTest.php @@ -1,5 +1,7 @@ * * @author Ingo Schommer (@silverstripe.com), SilverStripe Ltd. - * - * @package cms - * @subpackage tests */ class RemoveOrphanedPagesTaskTest extends FunctionalTest { - protected static $fixture_file = 'RemoveOrphanedPagesTaskTest.yml'; protected static $use_draft_site = false; diff --git a/tests/tasks/RemoveOrphanedPagesTaskTest.yml b/tests/php/Tasks/RemoveOrphanedPagesTaskTest.yml similarity index 100% rename from tests/tasks/RemoveOrphanedPagesTaskTest.yml rename to tests/php/Tasks/RemoveOrphanedPagesTaskTest.yml