Fix and upgrade all tests

Fix link tracking
This commit is contained in:
Damian Mooyman 2017-06-21 16:29:40 +12:00
parent 95e304a4ca
commit c2c75aa9e3
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A
65 changed files with 739 additions and 611 deletions

View File

@ -206,6 +206,7 @@ class CMSPageAddController extends CMSPageEditController
$record->write();
$editController = CMSPageEditController::singleton();
$editController->setRequest($this->getRequest());
$editController->setCurrentPageID($record->ID);
$session = $this->getRequest()->getSession();

View File

@ -6,6 +6,7 @@ use Page;
use SilverStripe\Assets\File;
use SilverStripe\Assets\Storage\GeneratedAssetHandler;
use SilverStripe\CMS\Controllers\ModelAsController;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
@ -96,8 +97,10 @@ class ErrorPage extends Page
Requirements::clear();
Requirements::clear_combined_files();
$request = new HTTPRequest('GET', '');
$request->setSession(Controller::curr()->getRequest()->getSession());
return ModelAsController::controller_for($errorPage)
->handleRequest(new HTTPRequest('GET', ''));
->handleRequest($request);
}
// then fall back on a cached version

View File

@ -2,12 +2,13 @@
namespace SilverStripe\CMS\Model;
use Page;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HeaderField;
use SilverStripe\Forms\OptionsetField;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\TreeDropdownField;
use Page;
use SilverStripe\Versioned\Versioned;
/**
* A redirector page redirects when the page is visited.
@ -120,7 +121,9 @@ class RedirectorPage extends Page
{
if ($this->RedirectionType == 'Internal') {
if ($this->LinkToID) {
$this->HasBrokenLink = SiteTree::get()->byID($this->LinkToID) ? false : true;
$this->HasBrokenLink = Versioned::get_by_stage(SiteTree::class, Versioned::DRAFT)
->filter('ID', $this->LinkToID)
->count() === 0;
} else {
// An incomplete redirector page definitely has a broken link
$this->HasBrokenLink = true;

View File

@ -4,8 +4,6 @@ namespace SilverStripe\CMS\Model;
use Page;
use SilverStripe\CampaignAdmin\AddToCampaignHandler_FormAction;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\ORM\CMSPreviewable;
use SilverStripe\CMS\Controllers\CMSPageEditController;
use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\CMS\Controllers\ModelAsController;
@ -18,6 +16,7 @@ use SilverStripe\Control\RequestHandler;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Resettable;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\CheckboxField;
@ -41,6 +40,7 @@ use SilverStripe\Forms\TreeDropdownField;
use SilverStripe\i18n\i18n;
use SilverStripe\i18n\i18nEntityProvider;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\CMSPreviewable;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
@ -48,16 +48,16 @@ use SilverStripe\ORM\HiddenClass;
use SilverStripe\ORM\Hierarchy\Hierarchy;
use SilverStripe\ORM\ManyManyList;
use SilverStripe\ORM\ValidationResult;
use SilverStripe\Security\Group;
use SilverStripe\Security\InheritedPermissions;
use SilverStripe\Security\InheritedPermissionsExtension;
use SilverStripe\Security\PermissionChecker;
use SilverStripe\Security\Security;
use SilverStripe\Versioned\Versioned;
use SilverStripe\Security\Group;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionChecker;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Security\Security;
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\Versioned\Versioned;
use SilverStripe\View\ArrayData;
use SilverStripe\View\HTML;
use SilverStripe\View\Parsers\ShortcodeParser;
@ -1472,18 +1472,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
public function onAfterDelete()
{
// Need to flush cache to avoid outdated versionnumber references
$this->flushCache();
// Need to mark pages depending to this one as broken
$dependentPages = $this->DependentPages();
if ($dependentPages) {
foreach ($dependentPages as $page) {
// $page->write() calls syncLinkTracking, which does all the hard work for us.
$page->write();
}
}
$this->updateDependentPages();
parent::onAfterDelete();
}
@ -2336,14 +2325,11 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
/** @var SiteTree $result */
$result = DataObject::get_by_id(self::class, $this->ID);
// Need to update pages linking to this one as no longer broken
foreach ($result->DependentPages(false) as $page) {
// $page->write() calls syncLinkTracking, which does all the hard work for us.
$page->write();
}
Versioned::set_reading_mode($oldReadingMode);
// Need to update pages linking to this one as no longer broken
$this->updateDependentPages();
$this->invokeWithExtensions('onAfterRestoreToStage', $this);
return $result;
@ -2865,4 +2851,22 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$permissions->clearCache();
}
}
/**
* Update dependant pages
*/
protected function updateDependentPages()
{
// Need to flush cache to avoid outdated versionnumber references
$this->flushCache();
// Need to mark pages depending to this one as broken
$dependentPages = $this->DependentPages();
if ($dependentPages) {
foreach ($dependentPages as $page) {
// $page->write() calls syncLinkTracking, which does all the hard work for us.
$page->write();
}
}
}
}

View File

@ -2,13 +2,13 @@
namespace SilverStripe\CMS\Model;
use DOMElement;
use SilverStripe\Assets\File;
use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\ORM\ManyManyList;
use SilverStripe\Versioned\Versioned;
use DOMElement;
use SilverStripe\View\Parsers\HTMLValue;
/**

View File

@ -159,8 +159,9 @@ class VirtualPage extends Page
public function syncLinkTracking()
{
if ($this->CopyContentFromID) {
$copyPage = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $this->CopyContentFromID);
$this->HasBrokenLink = !$copyPage;
$this->HasBrokenLink = Versioned::get_by_stage(SiteTree::class, Versioned::DRAFT)
->filter('ID', $this->CopyContentFromID)
->count() === 0;
} else {
$this->HasBrokenLink = true;
}

View File

@ -22,6 +22,8 @@ class ContentControllerSearchExtension extends Extension
/**
* Site search form
*
* @return SearchForm
*/
public function SearchForm()
{

View File

@ -5,5 +5,3 @@ require FRAMEWORK_PATH . '/tests/bootstrap/init.php';
require FRAMEWORK_PATH . '/tests/bootstrap/cli.php';
require FRAMEWORK_PATH . '/tests/bootstrap/environment.php';
require __DIR__ . '/bootstrap/mysite.php';
require FRAMEWORK_PATH . '/tests/bootstrap/mysite.php';
require FRAMEWORK_PATH . '/tests/bootstrap/phpunit.php';

View File

@ -1,25 +1,26 @@
<?php
use SilverStripe\Core\Injector\Injector;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\ValidationException;
use SilverStripe\Security\Security;
use SilverStripe\Versioned\Versioned;
use SilverStripe\ORM\HiddenClass;
use Psr\SimpleCache\CacheInterface;
use SilverStripe\Admin\CMSBatchActionHandler;
use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Admin\CMSBatchActionHandler;
use SilverStripe\SiteConfig\SiteConfig;
use Psr\SimpleCache\CacheInterface;
use SilverStripe\Core\Convert;
use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\CSSContentParser;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Forms\FieldList;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\CSSContentParser;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\HiddenClass;
use SilverStripe\ORM\ValidationException;
use SilverStripe\Security\Security;
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\Versioned\Versioned;
/**
* @package cms
@ -162,33 +163,6 @@ class CMSMainTest extends FunctionalTest
*/
}
/**
* Test publication of one of every page type
*/
public function testPublishOneOfEachKindOfPage()
{
$this->markTestIncomplete();
// $classes = ClassInfo::subclassesFor("SiteTree");
// array_shift($classes);
// foreach($classes as $class) {
// $page = new $class();
// if($class instanceof TestOnly) continue;
// $page->Title = "Test $class page";
// $page->write();
// $this->assertEquals("Test $class page", DB::query("SELECT \"Title\" FROM \"SiteTree\" WHERE \"ID\" = $page->ID")->value());
// $page->publishRecursive();
// $this->assertEquals("Test $class page", DB::query("SELECT \"Title\" FROM \"SiteTree_Live\" WHERE \"ID\" = $page->ID")->value());
// // Check that you can visit the page
// $this->get($page->URLSegment);
// }
}
/**
* Test that getCMSFields works on each page type.
* Mostly, this is just checking that the method doesn't return an error
@ -275,6 +249,7 @@ class CMSMainTest extends FunctionalTest
$page1->delete();
$cmsMain = new CMSMain();
$cmsMain->setRequest(Controller::curr()->getRequest());
// Bad calls
$this->assertNull($cmsMain->getRecord('0'));
@ -450,6 +425,7 @@ class CMSMainTest extends FunctionalTest
public function testGetNewItem()
{
$controller = new CMSMain();
$controller->setRequest(Controller::curr()->getRequest());
$id = 'new-Page-0';
// Test success
@ -475,6 +451,7 @@ class CMSMainTest extends FunctionalTest
public function testGetList()
{
$controller = new CMSMain();
$controller->setRequest(Controller::curr()->getRequest());
// Test all pages (stage)
$pages = $controller->getList()->sort('Title');
@ -567,6 +544,7 @@ class CMSMainTest extends FunctionalTest
// Get a associated with a fixture page.
$page = $this->objFromFixture(Page::class, 'page1');
$controller = new CMSMain();
$controller->setRequest(Controller::curr()->getRequest());
$form = $controller->getEditForm($page->ID);
$this->assertInstanceOf("SilverStripe\\Forms\\Form", $form);
@ -583,6 +561,7 @@ class CMSMainTest extends FunctionalTest
{
$this->logInWithPermission('ADMIN');
$cms = new CMSMain();
$cms->setRequest(Controller::curr()->getRequest());
$page = new CMSMainTest_ClassA();
$page->Title = 'Class A';
$page->write();
@ -602,40 +581,3 @@ class CMSMainTest extends FunctionalTest
$this->assertEquals('Class A', $newPage->Title);
}
}
class CMSMainTest_ClassA extends Page implements TestOnly
{
private static $allowed_children = array('CMSMainTest_ClassB');
protected function onBeforeWrite()
{
parent::onBeforeWrite();
if ($this->ClassName !== self::class) {
throw new ValidationException("Class saved with incorrect ClassName");
}
}
}
class CMSMainTest_ClassB extends Page implements TestOnly
{
protected function onBeforeWrite()
{
parent::onBeforeWrite();
if ($this->ClassName !== self::class) {
throw new ValidationException("Class saved with incorrect ClassName");
}
}
}
class CMSMainTest_NotRoot extends Page implements TestOnly
{
private static $can_be_root = false;
}
class CMSMainTest_HiddenClass extends Page implements TestOnly, HiddenClass
{
}

View File

@ -0,0 +1,18 @@
<?php
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\ValidationException;
class CMSMainTest_ClassA extends Page implements TestOnly
{
private static $allowed_children = array('CMSMainTest_ClassB');
protected function onBeforeWrite()
{
parent::onBeforeWrite();
if ($this->ClassName !== self::class) {
throw new ValidationException("Class saved with incorrect ClassName");
}
}
}

View File

@ -0,0 +1,16 @@
<?php
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\ValidationException;
class CMSMainTest_ClassB extends Page implements TestOnly
{
protected function onBeforeWrite()
{
parent::onBeforeWrite();
if ($this->ClassName !== self::class) {
throw new ValidationException("Class saved with incorrect ClassName");
}
}
}

View File

@ -0,0 +1,9 @@
<?php
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\HiddenClass;
class CMSMainTest_HiddenClass extends Page implements TestOnly, HiddenClass
{
}

View File

@ -0,0 +1,8 @@
<?php
use SilverStripe\Dev\TestOnly;
class CMSMainTest_NotRoot extends Page implements TestOnly
{
private static $can_be_root = false;
}

View File

@ -1,5 +1,6 @@
<?php
use SilverStripe\Control\Controller;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HiddenField;
@ -54,6 +55,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest
public function testGetEditForm()
{
$controller = new CMSPageHistoryController();
$controller->setRequest(Controller::curr()->getRequest());
// should get the latest version which we cannot rollback to
$form = $controller->getEditForm($this->page->ID);
@ -98,7 +100,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest
*/
public function testVersionsForm()
{
$history = $this->get('admin/pages/history/show/'. $this->page->ID);
$this->get('admin/pages/history/show/'. $this->page->ID);
$form = $this->cssParser()->getBySelector('#Form_VersionsForm');
$this->assertEquals(1, count($form));
@ -116,7 +118,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest
public function testVersionsFormTableContainsInformation()
{
$history = $this->get('admin/pages/history/show/'. $this->page->ID);
$this->get('admin/pages/history/show/'. $this->page->ID);
$form = $this->cssParser()->getBySelector('#Form_VersionsForm');
$rows = $form[0]->xpath("fieldset/table/tbody/tr");
@ -142,7 +144,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest
public function testVersionsFormSelectsUnpublishedCheckbox()
{
$history = $this->get('admin/pages/history/show/'. $this->page->ID);
$this->get('admin/pages/history/show/'. $this->page->ID);
$checkbox = $this->cssParser()->getBySelector('#Form_VersionsForm_ShowUnpublished');
$this->assertThat($checkbox[0], $this->logicalNot($this->isNull()));
@ -151,7 +153,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest
$this->assertThat($checked, $this->logicalNot($this->stringContains('checked')));
// viewing an unpublished
$history = $this->get('admin/pages/history/show/'.$this->page->ID .'/'.$this->versionUnpublishedCheck);
$this->get('admin/pages/history/show/'.$this->page->ID .'/'.$this->versionUnpublishedCheck);
$checkbox = $this->cssParser()->getBySelector('#Form_VersionsForm_ShowUnpublished');
$this->assertThat($checkbox[0], $this->logicalNot($this->isNull()));
@ -161,7 +163,8 @@ class CMSPageHistoryControllerTest extends FunctionalTest
public function testTransformReadonly()
{
/** @var CMSPageHistoryController $history */
$history = singleton(CMSPageHistoryController::class);
$history = new CMSPageHistoryController();
$history->setRequest(Controller::curr()->getRequest());
$fieldList = FieldList::create([
FieldGroup::create('group', [

View File

@ -1,19 +1,18 @@
<?php
use SilverStripe\Versioned\Versioned;
use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\ORM\Search\FulltextSearchable;
use SilverStripe\Core\Config\Config;
use SilverStripe\Assets\File;
use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\CMS\Search\ContentControllerSearchExtension;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\Search\FulltextSearchable;
use SilverStripe\Versioned\Versioned;
class ContentControllerSearchExtensionTest extends SapphireTest
{
protected static $required_extensions = array(
ContentController::class => [
\SilverStripe\CMS\Search\ContentControllerSearchExtension::class,
],
ContentControllerSearchExtension::class,
]
);
public function testCustomSearchFormClassesToTest()
@ -23,19 +22,16 @@ class ContentControllerSearchExtensionTest extends SapphireTest
$page->Content = 'oh really?';
$page->write();
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
/** @var ContentController|ContentControllerSearchExtension $controller */
$controller = new ContentController($page);
$form = $controller->SearchForm();
if (get_class($form) == 'SilverStripe\\CMS\\Search\\SearchForm') {
$this->assertEquals(array('SilverStripe\\Assets\\File'), $form->getClassesToSearch());
}
$this->assertEquals([ File::class ], $form->getClassesToSearch());
}
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
FulltextSearchable::enable('SilverStripe\\Assets\\File');
FulltextSearchable::enable(File::class);
}
/**
@ -45,9 +41,7 @@ class ContentControllerSearchExtensionTest extends SapphireTest
*/
public static function tearDownAfterClass()
{
File::remove_extension(FulltextSearchable::class);
parent::tearDownAfterClass();
Config::inst()->update('SilverStripe\\Assets\\File', 'create_table_options', array('SilverStripe\ORM\Connect\MySQLDatabase' => 'ENGINE=InnoDB'));
File::remove_extension('SilverStripe\\ORM\\Search\\FulltextSearchable');
}
}

View File

@ -1,13 +1,13 @@
<?php
use SilverStripe\Versioned\Versioned;
use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\CMS\Controllers\RootURLController;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\Core\Config\Config;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Versioned\Versioned;
/**
* @package cms
@ -22,6 +22,12 @@ class ContentControllerTest extends FunctionalTest
protected static $disable_themes = true;
protected static $extra_dataobjects = [
ContentControllerTest_Page::class,
ContentControllerTestPage::class,
ContentControllerTestPageWithoutController::class,
];
/**
* Test that nested pages, basic actions, and nested/non-nested URL switching works properly
*/
@ -119,10 +125,9 @@ class ContentControllerTest extends FunctionalTest
$this->assertEquals('403', $response->getstatusCode());
// test when user does have permission, should show page title and header ok.
$this->logInWithPermission('ADMIN');
$this->assertEquals('200', $this->get('/contact/?stage=Stage')->getstatusCode());
$this->assertEquals('200', $this->get('contact/?stage=Stage')->getstatusCode());
}
public function testLinkShortcodes()
@ -200,48 +205,3 @@ class ContentControllerTest extends FunctionalTest
}
}
class ContentControllerTest_Page extends Page
{
}
class ContentControllerTest_PageController extends PageController
{
private static $allowed_actions = array (
'second_index'
);
public function index()
{
return $this->Title;
}
public function second_index()
{
return $this->index();
}
}
// For testing templates
class ContentControllerTestPageWithoutController extends Page
{
}
class ContentControllerTestPage extends Page
{
}
class ContentControllerTestPageController extends PageController
{
private static $allowed_actions = array(
'test',
'testwithouttemplate'
);
public function testwithouttemplate()
{
return array();
}
}

View File

@ -0,0 +1,8 @@
<?php
use SilverStripe\Dev\TestOnly;
class ContentControllerTestPage extends Page implements TestOnly
{
}

View File

@ -0,0 +1,16 @@
<?php
use SilverStripe\Dev\TestOnly;
class ContentControllerTestPageController extends PageController implements TestOnly
{
private static $allowed_actions = array(
'test',
'testwithouttemplate'
);
public function testwithouttemplate()
{
return array();
}
}

View File

@ -0,0 +1,8 @@
<?php
use SilverStripe\Dev\TestOnly;
class ContentControllerTestPageWithoutController extends Page implements TestOnly
{
}

View File

@ -0,0 +1,8 @@
<?php
use SilverStripe\Dev\TestOnly;
class ContentControllerTest_Page extends Page implements TestOnly
{
}

View File

@ -0,0 +1,21 @@
<?php
use SilverStripe\Dev\TestOnly;
class ContentControllerTest_PageController extends PageController implements TestOnly
{
private static $allowed_actions = array(
'second_index'
);
public function index()
{
return $this->Title;
}
public function second_index()
{
return $this->index();
}
}

View File

@ -57,37 +57,3 @@ class SilverStripeNavigatorTest extends SapphireTest
$this->assertContains('SilverStripeNavigatorTest_ProtectedTestItem', $classes);
}
}
class SilverStripeNavigatorTest_TestItem extends SilverStripeNavigatorItem implements TestOnly
{
public function getTitle()
{
return self::class;
}
public function getHTML()
{
return null;
}
}
class SilverStripeNavigatorTest_ProtectedTestItem extends SilverStripeNavigatorItem implements TestOnly
{
public function getTitle()
{
return self::class;
}
public function getHTML()
{
return null;
}
public function canView($member = null)
{
if (!$member) {
$member = Security::getCurrentUser();
}
return Permission::checkMember($member, 'ADMIN');
}
}

View File

@ -0,0 +1,27 @@
<?php
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Security\Permission;
use SilverStripe\Security\Security;
class SilverStripeNavigatorTest_ProtectedTestItem extends SilverStripeNavigatorItem implements TestOnly
{
public function getTitle()
{
return self::class;
}
public function getHTML()
{
return null;
}
public function canView($member = null)
{
if (!$member) {
$member = Security::getCurrentUser();
}
return Permission::checkMember($member, 'ADMIN');
}
}

View File

@ -0,0 +1,17 @@
<?php
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem;
use SilverStripe\Dev\TestOnly;
class SilverStripeNavigatorTest_TestItem extends SilverStripeNavigatorItem implements TestOnly
{
public function getTitle()
{
return self::class;
}
public function getHTML()
{
return null;
}
}

View File

@ -1,16 +1,14 @@
<?php
use SilverStripe\Assets\File;
use SilverStripe\Assets\Tests\Storage\AssetStoreTest\TestAssetStore;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Security\Security;
use SilverStripe\Versioned\Versioned;
use SilverStripe\Assets\File;
use SilverStripe\Control\Session;
use SilverStripe\View\Parsers\ShortcodeParser;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Assets\Tests\Storage\AssetStoreTest\TestAssetStore;
class ErrorPageFileExtensionTest extends SapphireTest
{
protected static $fixture_file = 'ErrorPageTest.yml';
protected $versionedMode = null;

View File

@ -100,12 +100,3 @@ class RedirectorPageTest extends FunctionalTest
RedirectorPageController::remove_extension('RedirectorPageTest_RedirectExtension');
}
}
class RedirectorPageTest_RedirectExtension extends Extension implements TestOnly
{
public function onBeforeInit()
{
$this->owner->redirect('/foo');
}
}

View File

@ -0,0 +1,13 @@
<?php
use SilverStripe\Core\Extension;
use SilverStripe\Dev\TestOnly;
class RedirectorPageTest_RedirectExtension extends Extension implements TestOnly
{
public function onBeforeInit()
{
$this->owner->redirect('/foo');
}
}

View File

@ -28,10 +28,6 @@ class SiteTreeActionsTest extends FunctionalTest
public function testActionsReadonly()
{
if (class_exists('SiteTreeCMSWorkflow')) {
$this->markTestSkipped('Skip if SiteTreeCMSWorkflow installed');
}
// Publish record
$this->logInWithPermission('ADMIN');
$page = new SiteTreeActionsTest_Page();
@ -58,10 +54,6 @@ class SiteTreeActionsTest extends FunctionalTest
public function testActionsNoDeletePublishedRecord()
{
if (class_exists('SiteTreeCMSWorkflow')) {
$this->markTestSkipped('Skip if SiteTreeCMSWorkflow installed');
}
$this->logInWithPermission('ADMIN');
$page = new SiteTreeActionsTest_Page();
@ -92,10 +84,6 @@ class SiteTreeActionsTest extends FunctionalTest
public function testActionsPublishedRecord()
{
if (class_exists('SiteTreeCMSWorkflow')) {
$this->markTestSkipped('Skip if SiteTreeCMSWorkflow installed');
}
$author = $this->objFromFixture(Member::class, 'cmseditor');
Security::setCurrentUser($author);
@ -121,10 +109,6 @@ class SiteTreeActionsTest extends FunctionalTest
public function testActionsDeletedFromStageRecord()
{
if (class_exists('SiteTreeCMSWorkflow')) {
$this->markTestSkipped('Skip if SiteTreeCMSWorkflow installed');
}
$author = $this->objFromFixture(Member::class, 'cmseditor');
Security::setCurrentUser($author);
@ -154,10 +138,6 @@ class SiteTreeActionsTest extends FunctionalTest
public function testActionsChangedOnStageRecord()
{
if (class_exists('SiteTreeCMSWorkflow')) {
$this->markTestSkipped('Skip if SiteTreeCMSWorkflow installed');
}
$author = $this->objFromFixture(Member::class, 'cmseditor');
Security::setCurrentUser($author);
@ -185,10 +165,6 @@ class SiteTreeActionsTest extends FunctionalTest
public function testActionsViewingOldVersion()
{
if (class_exists('SiteTreeCMSWorkflow')) {
$this->markTestSkipped('Skip if SiteTreeCMSWorkflow installed');
}
$p = new Page();
$p->Content = 'test page first version';
$p->write();
@ -207,16 +183,3 @@ class SiteTreeActionsTest extends FunctionalTest
$this->assertNotNull($actions->dataFieldByName('action_rollback'));
}
}
class SiteTreeActionsTest_Page extends Page implements TestOnly
{
public function canEdit($member = null)
{
return Permission::checkMember($member, 'SiteTreeActionsTest_Page_CANEDIT');
}
public function canDelete($member = null)
{
return Permission::checkMember($member, 'SiteTreeActionsTest_Page_CANDELETE');
}
}

View File

@ -0,0 +1,17 @@
<?php
use SilverStripe\Dev\TestOnly;
use SilverStripe\Security\Permission;
class SiteTreeActionsTest_Page extends Page implements TestOnly
{
public function canEdit($member = null)
{
return Permission::checkMember($member, 'SiteTreeActionsTest_Page_CANEDIT');
}
public function canDelete($member = null)
{
return Permission::checkMember($member, 'SiteTreeActionsTest_Page_CANDELETE');
}
}

View File

@ -1,5 +1,6 @@
<?php
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Versioned\Versioned;
use SilverStripe\ORM\DataExtension;
use SilverStripe\Control\HTTP;
@ -16,9 +17,11 @@ class SiteTreeBacklinksTest extends SapphireTest
{
protected static $fixture_file = "SiteTreeBacklinksTest.yml";
protected static $required_extensions = array(
'SilverStripe\\CMS\\Model\\SiteTree' => array('SiteTreeBacklinksTest_DOD'),
);
protected static $required_extensions = [
SiteTree::class => [
SiteTreeBacklinksTest_DOD::class
],
];
public function setUp()
{
@ -96,8 +99,6 @@ class SiteTreeBacklinksTest extends SapphireTest
public function testChangingUrlOnLiveSiteRewritesLink()
{
$this->markTestSkipped("Test disabled until versioned many_many implemented");
// publish page 1 & 3
$page1 = $this->objFromFixture('Page', 'page1');
$page3 = $this->objFromFixture('Page', 'page3');
@ -130,8 +131,6 @@ class SiteTreeBacklinksTest extends SapphireTest
public function testPublishingPageWithModifiedUrlRewritesLink()
{
$this->markTestSkipped("Test disabled until versioned many_many implemented");
// publish page 1 & 3
$page1 = $this->objFromFixture('Page', 'page1');
$page3 = $this->objFromFixture('Page', 'page3');
@ -168,8 +167,6 @@ class SiteTreeBacklinksTest extends SapphireTest
public function testPublishingPageWithModifiedLinksRewritesLinks()
{
$this->markTestSkipped("Test disabled until versioned many_many implemented");
// publish page 1 & 3
$page1 = $this->objFromFixture('Page', 'page1');
$page3 = $this->objFromFixture('Page', 'page3');
@ -211,7 +208,9 @@ class SiteTreeBacklinksTest extends SapphireTest
public function testLinkTrackingOnExtraContentFields()
{
/** @var Page $page1 */
$page1 = $this->objFromFixture('Page', 'page1');
/** @var Page $page2 */
$page2 = $this->objFromFixture('Page', 'page2');
$page1->publishRecursive();
$page2->publishRecursive();
@ -236,9 +235,6 @@ class SiteTreeBacklinksTest extends SapphireTest
$page2 = $this->objFromFixture('Page', 'page2');
$this->assertEquals('<p><a href="'.Director::baseURL().'page1-new-url/">Testing page 1 link</a></p>', $page2->obj('ExtraContent')->forTemplate());
// @todo - Implement versioned many_many
$this->markTestSkipped("Test disabled until versioned many_many implemented");
// confirm that published link hasn't
$page2Live = Versioned::get_one_by_stage("Page", "Live", "\"SiteTree\".\"ID\" = $page2->ID");
Versioned::set_stage(Versioned::LIVE);
@ -249,8 +245,8 @@ class SiteTreeBacklinksTest extends SapphireTest
$page2Live = Versioned::get_one_by_stage("Page", "Live", "\"SiteTree\".\"ID\" = $page2->ID");
$this->assertEquals('<p><a href="'.Director::baseURL().'page1-new-url/">Testing page 1 link</a></p>', $page2Live->obj('ExtraContent')->forTemplate());
// remove hyperlink to page 1
// Edit draft again
Versioned::set_stage(Versioned::DRAFT);
$page2->ExtraContent = '<p>No links anymore!</p>';
$page2->write();
@ -258,16 +254,3 @@ class SiteTreeBacklinksTest extends SapphireTest
$this->assertNotContains($page2->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 2 has been removed');
}
}
class SiteTreeBacklinksTest_DOD extends DataExtension implements TestOnly
{
private static $db = array(
'ExtraContent' => 'HTMLText',
);
public function updateCMSFields(FieldList $fields)
{
$fields->addFieldToTab("Root.Content", new HTMLEditorField("ExtraContent"));
}
}

View File

@ -0,0 +1,18 @@
<?php
use SilverStripe\Dev\TestOnly;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\ORM\DataExtension;
class SiteTreeBacklinksTest_DOD extends DataExtension implements TestOnly
{
private static $db = array(
'ExtraContent' => 'HTMLText',
);
public function updateCMSFields(FieldList $fields)
{
$fields->addFieldToTab("Root.Content", new HTMLEditorField("ExtraContent"));
}
}

View File

@ -153,8 +153,6 @@ class SiteTreeBrokenLinksTest extends SapphireTest
public function testPublishingSourceBeforeDestHasBrokenLink()
{
$this->markTestSkipped("Test disabled until versioned many_many implemented");
$this->logInWithPermission('ADMIN');
// Set up two draft pages with a link from content -> about
@ -169,15 +167,16 @@ class SiteTreeBrokenLinksTest extends SapphireTest
// Publish the source of the link, while the dest is still unpublished.
$linkSrc->publishRecursive();
// Verify that the link isn't broken on draft but is broken on published
// Verify that the link is not marked as broken on draft (source of truth)
$this->assertEquals(0, (int)$linkSrc->HasBrokenLink);
$this->assertEquals(1, DB::query("SELECT \"HasBrokenLink\" FROM \"SiteTree_Live\"
// Live doesn't have separate broken link tracking
$this->assertEquals(0, DB::query("SELECT \"HasBrokenLink\" FROM \"SiteTree_Live\"
WHERE \"ID\" = $linkSrc->ID")->value());
}
public function testRestoreFixesBrokenLinks()
{
$this->markTestSkipped("Test disabled until versioned many_many implemented");
// Create page and virtual page
$p = new Page();
$p->Title = "source";
@ -210,43 +209,44 @@ class SiteTreeBrokenLinksTest extends SapphireTest
$this->assertFalse($vp->HasBrokenLink);
$this->assertFalse($rp->HasBrokenLink);
// Unpublish the source page, confirm that the page 2 and RP has a broken link on published
// Unpublishing doesn't affect broken state on live (draft is source of truth)
$p->doUnpublish();
$p2Live = Versioned::get_one_by_stage('SilverStripe\\CMS\\Model\\SiteTree', 'Live', '"SiteTree"."ID" = ' . $p2->ID);
$rpLive = Versioned::get_one_by_stage('SilverStripe\\CMS\\Model\\SiteTree', 'Live', '"SiteTree"."ID" = ' . $rp->ID);
$this->assertEquals(1, $p2Live->HasBrokenLink);
$this->assertEquals(1, $rpLive->HasBrokenLink);
$p2Live = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $p2->ID);
$rpLive = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $rp->ID);
$this->assertEquals(0, $p2Live->HasBrokenLink);
$this->assertEquals(0, $rpLive->HasBrokenLink);
// Delete the source page, confirm that the VP, RP and page 2 have broken links on draft
$p->delete();
$vp->flushCache();
$vp = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $vp->ID);
$vp = DataObject::get_by_id(SiteTree::class, $vp->ID);
$p2->flushCache();
$p2 = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $p2->ID);
$p2 = DataObject::get_by_id(SiteTree::class, $p2->ID);
$rp->flushCache();
$rp = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $rp->ID);
$rp = DataObject::get_by_id(SiteTree::class, $rp->ID);
$this->assertEquals(1, $p2->HasBrokenLink);
$this->assertEquals(1, $vp->HasBrokenLink);
$this->assertEquals(1, $rp->HasBrokenLink);
// Restore the page to stage, confirm that this fixes the links
$p = Versioned::get_latest_version('SilverStripe\\CMS\\Model\\SiteTree', $pageID);
/** @var SiteTree $p */
$p = Versioned::get_latest_version(SiteTree::class, $pageID);
$p->doRestoreToStage();
$p2->flushCache();
$p2 = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $p2->ID);
$p2 = DataObject::get_by_id(SiteTree::class, $p2->ID);
$vp->flushCache();
$vp = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $vp->ID);
$vp = DataObject::get_by_id(SiteTree::class, $vp->ID);
$rp->flushCache();
$rp = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $rp->ID);
$rp = DataObject::get_by_id(SiteTree::class, $rp->ID);
$this->assertFalse((bool)$p2->HasBrokenLink);
$this->assertFalse((bool)$vp->HasBrokenLink);
$this->assertFalse((bool)$rp->HasBrokenLink);
// Publish and confirm that the p2 and RP broken links are fixed on published
$this->assertTrue($p->publishRecursive());
$p2Live = Versioned::get_one_by_stage('SilverStripe\\CMS\\Model\\SiteTree', 'Live', '"SiteTree"."ID" = ' . $p2->ID);
$rpLive = Versioned::get_one_by_stage('SilverStripe\\CMS\\Model\\SiteTree', 'Live', '"SiteTree"."ID" = ' . $rp->ID);
$p2Live = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $p2->ID);
$rpLive = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $rp->ID);
$this->assertFalse((bool)$p2Live->HasBrokenLink);
$this->assertFalse((bool)$rpLive->HasBrokenLink);
}
@ -290,25 +290,25 @@ class SiteTreeBrokenLinksTest extends SapphireTest
$p->delete();
$vp->flushCache();
$vp = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $vp->ID);
$vp = DataObject::get_by_id(SiteTree::class, $vp->ID);
$p2->flushCache();
$p2 = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $p2->ID);
$p2 = DataObject::get_by_id(SiteTree::class, $p2->ID);
$rp->flushCache();
$rp = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $rp->ID);
$rp = DataObject::get_by_id(SiteTree::class, $rp->ID);
$this->assertEquals(1, $p2->HasBrokenLink);
$this->assertEquals(1, $vp->HasBrokenLink);
$this->assertEquals(1, $rp->HasBrokenLink);
// Call doRevertToLive and confirm that broken links are restored
$pLive = Versioned::get_one_by_stage('SilverStripe\\CMS\\Model\\SiteTree', 'Live', '"SiteTree"."ID" = ' . $pID);
$pLive = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $pID);
$pLive->doRevertToLive();
$p2->flushCache();
$p2 = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $p2->ID);
$p2 = DataObject::get_by_id(SiteTree::class, $p2->ID);
$vp->flushCache();
$vp = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $vp->ID);
$vp = DataObject::get_by_id(SiteTree::class, $vp->ID);
$rp->flushCache();
$rp = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $rp->ID);
$rp = DataObject::get_by_id(SiteTree::class, $rp->ID);
$this->assertFalse((bool)$p2->HasBrokenLink);
$this->assertFalse((bool)$vp->HasBrokenLink);
$this->assertFalse((bool)$rp->HasBrokenLink);

View File

@ -41,40 +41,39 @@ class SiteTreePermissionsTest extends FunctionalTest
$this->useDraftSite(false);
$this->autoFollowRedirection = false;
$page = $this->objFromFixture('Page', 'draftOnlyPage');
/** @var Page $draftOnlyPage */
$draftOnlyPage = $this->objFromFixture('Page', 'draftOnlyPage');
$this->logOut();
if ($member = Security::getCurrentUser()) {
Security::setCurrentUser(null);
}
$response = $this->get($page->URLSegment . '?stage=Live');
$response = $this->get($draftOnlyPage->URLSegment . '?stage=Live');
$this->assertEquals($response->getStatusCode(), '404');
$response = $this->get($page->URLSegment . '?stage=');
$response = $this->get($draftOnlyPage->URLSegment);
$this->assertEquals($response->getStatusCode(), '404');
// should be prompted for a login
try {
$response = $this->get($page->URLSegment . '?stage=Stage');
$response = $this->get($draftOnlyPage->URLSegment . '?stage=Stage');
} catch (HTTPResponse_Exception $responseException) {
$response = $responseException->getResponse();
}
$this->assertEquals($response->getStatusCode(), '302');
$this->assertContains(
Config::inst()->get('SilverStripe\\Security\\Security', 'login_url'),
Security::config()->get('login_url'),
$response->getHeader('Location')
);
$this->logInWithPermission('ADMIN');
$response = $this->get($page->URLSegment . '?stage=Live');
$this->assertEquals($response->getStatusCode(), '404');
$response = $this->get($draftOnlyPage->URLSegment . '?stage=Live');
$this->assertEquals('404', $response->getStatusCode());
$response = $this->get($page->URLSegment . '?stage=Stage');
$this->assertEquals($response->getStatusCode(), '200');
$response = $this->get($draftOnlyPage->URLSegment . '?stage=Stage');
$this->assertEquals('200', $response->getStatusCode());
$response = $this->get($page->URLSegment . '?stage=');
$this->assertEquals($response->getStatusCode(), '404');
// Stage is remembered from last request
$response = $this->get($draftOnlyPage->URLSegment);
$this->assertEquals('200', $response->getStatusCode());
}
public function testPermissionCheckingWorksOnDeletedPages()
@ -87,7 +86,7 @@ class SiteTreePermissionsTest extends FunctionalTest
$page->delete();
// Re-fetch the page from the live site
$page = Versioned::get_one_by_stage('SilverStripe\\CMS\\Model\\SiteTree', 'Live', "\"SiteTree\".\"ID\" = $pageID");
$page = Versioned::get_one_by_stage(SiteTree::class, 'Live', "\"SiteTree\".\"ID\" = $pageID");
// subadmin has edit rights on that page
$member = $this->objFromFixture(Member::class, 'subadmin');
@ -137,7 +136,7 @@ class SiteTreePermissionsTest extends FunctionalTest
$page->delete();
// We'll need to resurrect the page from the version cache to test this case
$page = Versioned::get_latest_version('SilverStripe\\CMS\\Model\\SiteTree', $pageID);
$page = Versioned::get_latest_version(SiteTree::class, $pageID);
// subadmin had edit rights on that page, but now it's gone
$member = $this->objFromFixture(Member::class, 'subadmin');

View File

@ -1432,192 +1432,3 @@ class SiteTreeTest extends SapphireTest
$this->assertSame('SiteTreeTest_LegacyControllerName_Controller', $class->getControllerName());
}
}
/**#@+
* @ignore
*/
class SiteTreeTest_PageNode extends Page implements TestOnly
{
}
class SiteTreeTest_PageNodeController extends PageController implements TestOnly
{
}
class SiteTreeTest_Conflicted extends Page implements TestOnly
{
}
class SiteTreeTest_ConflictedController extends PageController implements TestOnly
{
private static $allowed_actions = array (
'conflicted-action'
);
public function hasActionTemplate($template)
{
if ($template == 'conflicted-template') {
return true;
} else {
return parent::hasActionTemplate($template);
}
}
}
class SiteTreeTest_NullHtmlCleaner extends HTMLCleaner
{
public function cleanHTML($html)
{
return $html;
}
}
class SiteTreeTest_ClassA extends Page implements TestOnly
{
private static $need_permission = [
'ADMIN',
'CMS_ACCESS_CMSMain'
];
private static $allowed_children = [
SiteTreeTest_ClassB::class
];
}
class SiteTreeTest_ClassB extends Page implements TestOnly
{
// Also allowed subclasses
private static $allowed_children = array(SiteTreeTest_ClassC::class);
}
class SiteTreeTest_ClassC extends Page implements TestOnly
{
private static $allowed_children = array();
}
class SiteTreeTest_ClassD extends Page implements TestOnly
{
// Only allows this class, no children classes
private static $allowed_children = array('*SiteTreeTest_ClassC');
private static $extensions = [
'SiteTreeTest_ExtensionA',
'SiteTreeTest_ExtensionB',
];
public $canEditValue = null;
public function canEdit($member = null)
{
return isset($this->canEditValue)
? $this->canEditValue
: parent::canEdit($member);
}
}
class SiteTreeTest_ClassE extends Page implements TestOnly, HiddenClass
{
}
class SiteTreeTest_ClassCext extends SiteTreeTest_ClassC implements TestOnly
{
// Override SiteTreeTest_ClassC definitions
private static $allowed_children = array(SiteTreeTest_ClassB::class);
}
class SiteTreeTest_NotRoot extends Page implements TestOnly
{
private static $can_be_root = false;
}
class SiteTreeTest_StageStatusInherit extends SiteTree implements TestOnly
{
public function getStatusFlags($cached = true)
{
$flags = parent::getStatusFlags($cached);
$flags['inherited-class'] = "InheritedTitle";
return $flags;
}
}
class SiteTreeTest_Extension extends DataExtension implements TestOnly
{
public function augmentValidURLSegment()
{
return false;
}
}
class SiteTreeTest_AdminDenied extends Page implements TestOnly
{
private static $extensions = array(
'SiteTreeTest_AdminDeniedExtension'
);
}
class SiteTreeTest_ExtensionA extends SiteTreeExtension implements TestOnly
{
public static $can_publish = true;
public function canPublish($member)
{
return static::$can_publish;
}
}
class SiteTreeTest_ExtensionB extends SiteTreeExtension implements TestOnly
{
public static $can_publish = true;
public function canPublish($member)
{
return static::$can_publish;
}
}
/**
* An extension that can even deny actions to admins
*/
class SiteTreeTest_AdminDeniedExtension extends DataExtension implements TestOnly
{
public function canCreate($member)
{
return false;
}
public function canEdit($member)
{
return false;
}
public function canDelete($member)
{
return false;
}
public function canAddChildren()
{
return false;
}
public function canView()
{
return false;
}
}
/**
* An empty SiteTree instance with a controller to test that legacy controller names can still be loaded
*/
class SiteTreeTest_LegacyControllerName extends Page implements TestOnly
{
}
class SiteTreeTest_LegacyControllerName_Controller extends PageController implements TestOnly
{
}

View File

@ -0,0 +1,10 @@
<?php
use SilverStripe\Dev\TestOnly;
class SiteTreeTest_AdminDenied extends Page implements TestOnly
{
private static $extensions = array(
'SiteTreeTest_AdminDeniedExtension'
);
}

View File

@ -0,0 +1,35 @@
<?php
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataExtension;
/**
* An extension that can even deny actions to admins
*/
class SiteTreeTest_AdminDeniedExtension extends DataExtension implements TestOnly
{
public function canCreate($member)
{
return false;
}
public function canEdit($member)
{
return false;
}
public function canDelete($member)
{
return false;
}
public function canAddChildren()
{
return false;
}
public function canView()
{
return false;
}
}

View File

@ -0,0 +1,15 @@
<?php
use SilverStripe\Dev\TestOnly;
class SiteTreeTest_ClassA extends Page implements TestOnly
{
private static $need_permission = [
'ADMIN',
'CMS_ACCESS_CMSMain'
];
private static $allowed_children = [
SiteTreeTest_ClassB::class
];
}

View File

@ -0,0 +1,9 @@
<?php
use SilverStripe\Dev\TestOnly;
class SiteTreeTest_ClassB extends Page implements TestOnly
{
// Also allowed subclasses
private static $allowed_children = array(SiteTreeTest_ClassC::class);
}

View File

@ -0,0 +1,8 @@
<?php
use SilverStripe\Dev\TestOnly;
class SiteTreeTest_ClassC extends Page implements TestOnly
{
private static $allowed_children = array();
}

View File

@ -0,0 +1,9 @@
<?php
use SilverStripe\Dev\TestOnly;
class SiteTreeTest_ClassCext extends SiteTreeTest_ClassC implements TestOnly
{
// Override SiteTreeTest_ClassC definitions
private static $allowed_children = array(SiteTreeTest_ClassB::class);
}

View File

@ -0,0 +1,23 @@
<?php
use SilverStripe\Dev\TestOnly;
class SiteTreeTest_ClassD extends Page implements TestOnly
{
// Only allows this class, no children classes
private static $allowed_children = array('*SiteTreeTest_ClassC');
private static $extensions = [
'SiteTreeTest_ExtensionA',
'SiteTreeTest_ExtensionB',
];
public $canEditValue = null;
public function canEdit($member = null)
{
return isset($this->canEditValue)
? $this->canEditValue
: parent::canEdit($member);
}
}

View File

@ -0,0 +1,9 @@
<?php
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\HiddenClass;
class SiteTreeTest_ClassE extends Page implements TestOnly, HiddenClass
{
}

View File

@ -0,0 +1,8 @@
<?php
use SilverStripe\Dev\TestOnly;
class SiteTreeTest_Conflicted extends Page implements TestOnly
{
}

View File

@ -0,0 +1,20 @@
<?php
use SilverStripe\Dev\TestOnly;
class SiteTreeTest_ConflictedController extends PageController implements TestOnly
{
private static $allowed_actions = array(
'conflicted-action'
);
public function hasActionTemplate($template)
{
if ($template == 'conflicted-template') {
return true;
} else {
return parent::hasActionTemplate($template);
}
}
}

View File

@ -0,0 +1,12 @@
<?php
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataExtension;
class SiteTreeTest_Extension extends DataExtension implements TestOnly
{
public function augmentValidURLSegment()
{
return false;
}
}

View File

@ -0,0 +1,14 @@
<?php
use SilverStripe\CMS\Model\SiteTreeExtension;
use SilverStripe\Dev\TestOnly;
class SiteTreeTest_ExtensionA extends SiteTreeExtension implements TestOnly
{
public static $can_publish = true;
public function canPublish($member)
{
return static::$can_publish;
}
}

View File

@ -0,0 +1,14 @@
<?php
use SilverStripe\CMS\Model\SiteTreeExtension;
use SilverStripe\Dev\TestOnly;
class SiteTreeTest_ExtensionB extends SiteTreeExtension implements TestOnly
{
public static $can_publish = true;
public function canPublish($member)
{
return static::$can_publish;
}
}

View File

@ -0,0 +1,11 @@
<?php
use SilverStripe\Dev\TestOnly;
/**
* An empty SiteTree instance with a controller to test that legacy controller names can still be loaded
*/
class SiteTreeTest_LegacyControllerName extends Page implements TestOnly
{
}

View File

@ -0,0 +1,8 @@
<?php
use SilverStripe\Dev\TestOnly;
class SiteTreeTest_LegacyControllerName_Controller extends PageController implements TestOnly
{
}

View File

@ -0,0 +1,8 @@
<?php
use SilverStripe\Dev\TestOnly;
class SiteTreeTest_NotRoot extends Page implements TestOnly
{
private static $can_be_root = false;
}

View File

@ -0,0 +1,12 @@
<?php
use SilverStripe\Dev\TestOnly;
use SilverStripe\View\Parsers\HTMLCleaner;
class SiteTreeTest_NullHtmlCleaner extends HTMLCleaner implements TestOnly
{
public function cleanHTML($html)
{
return $html;
}
}

View File

@ -0,0 +1,8 @@
<?php
use SilverStripe\Dev\TestOnly;
class SiteTreeTest_PageNode extends Page implements TestOnly
{
}

View File

@ -0,0 +1,7 @@
<?php
use SilverStripe\Dev\TestOnly;
class SiteTreeTest_PageNodeController extends PageController implements TestOnly
{
}

View File

@ -0,0 +1,14 @@
<?php
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\TestOnly;
class SiteTreeTest_StageStatusInherit extends SiteTree implements TestOnly
{
public function getStatusFlags($cached = true)
{
$flags = parent::getStatusFlags($cached);
$flags['inherited-class'] = "InheritedTitle";
return $flags;
}
}

View File

@ -617,10 +617,6 @@ class VirtualPageTest extends FunctionalTest
public function testVirtualPagePointingToRedirectorPage()
{
if (!class_exists('SilverStripe\\CMS\\Model\\RedirectorPage')) {
$this->markTestSkipped('RedirectorPage required');
}
$rp = new RedirectorPage(array('ExternalURL' => 'http://google.com', 'RedirectionType' => 'External'));
$rp->write();
$rp->publishRecursive();
@ -653,82 +649,3 @@ class VirtualPageTest extends FunctionalTest
$this->assertContains('testaction', $controller->allowedActions());
}
}
class VirtualPageTest_ClassA extends Page implements TestOnly
{
private static $db = array(
'MyInitiallyCopiedField' => 'Text',
'MyVirtualField' => 'Text',
'MyNonVirtualField' => 'Text',
'CastingTest' => 'VirtualPageTest_TestDBField'
);
private static $allowed_children = array('VirtualPageTest_ClassB');
public function modelMethod()
{
return 'hi there';
}
}
class VirtualPageTest_ClassAController extends PageController implements TestOnly
{
private static $allowed_actions = [
'testaction'
];
public function testMethod()
{
return 'hello';
}
}
class VirtualPageTest_ClassB extends Page implements TestOnly
{
private static $allowed_children = array('VirtualPageTest_ClassC');
}
class VirtualPageTest_ClassC extends Page implements TestOnly
{
private static $allowed_children = array();
}
class VirtualPageTest_NotRoot extends Page implements TestOnly
{
private static $can_be_root = false;
}
class VirtualPageTest_TestDBField extends DBVarchar implements TestOnly
{
public function forTemplate()
{
return strtoupper($this->XML());
}
}
class VirtualPageTest_VirtualPageSub extends VirtualPage implements TestOnly
{
private static $db = array(
'MyProperty' => 'Varchar',
);
}
class VirtualPageTest_PageExtension extends DataExtension implements TestOnly
{
private static $db = array(
// These fields are just on an extension to simulate shared properties between Page and VirtualPage.
// Not possible through direct $db definitions due to VirtualPage inheriting from Page, and Page being defined elsewhere.
'MySharedVirtualField' => 'Text',
'MySharedNonVirtualField' => 'Text',
);
}
class VirtualPageTest_PageWithAllowedChildren extends Page implements TestOnly
{
private static $allowed_children = array(
'VirtualPageTest_ClassA',
'SilverStripe\\CMS\\Model\\VirtualPage'
);
}

View File

@ -0,0 +1,20 @@
<?php
use SilverStripe\Dev\TestOnly;
class VirtualPageTest_ClassA extends Page implements TestOnly
{
private static $db = array(
'MyInitiallyCopiedField' => 'Text',
'MyVirtualField' => 'Text',
'MyNonVirtualField' => 'Text',
'CastingTest' => 'VirtualPageTest_TestDBField'
);
private static $allowed_children = array('VirtualPageTest_ClassB');
public function modelMethod()
{
return 'hi there';
}
}

View File

@ -0,0 +1,15 @@
<?php
use SilverStripe\Dev\TestOnly;
class VirtualPageTest_ClassAController extends PageController implements TestOnly
{
private static $allowed_actions = [
'testaction'
];
public function testMethod()
{
return 'hello';
}
}

View File

@ -0,0 +1,8 @@
<?php
use SilverStripe\Dev\TestOnly;
class VirtualPageTest_ClassB extends Page implements TestOnly
{
private static $allowed_children = array('VirtualPageTest_ClassC');
}

View File

@ -0,0 +1,8 @@
<?php
use SilverStripe\Dev\TestOnly;
class VirtualPageTest_ClassC extends Page implements TestOnly
{
private static $allowed_children = array();
}

View File

@ -0,0 +1,8 @@
<?php
use SilverStripe\Dev\TestOnly;
class VirtualPageTest_NotRoot extends Page implements TestOnly
{
private static $can_be_root = false;
}

View File

@ -0,0 +1,14 @@
<?php
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataExtension;
class VirtualPageTest_PageExtension extends DataExtension implements TestOnly
{
private static $db = array(
// These fields are just on an extension to simulate shared properties between Page and VirtualPage.
// Not possible through direct $db definitions due to VirtualPage inheriting from Page, and Page being defined elsewhere.
'MySharedVirtualField' => 'Text',
'MySharedNonVirtualField' => 'Text',
);
}

View File

@ -0,0 +1,12 @@
<?php
use SilverStripe\CMS\Model\VirtualPage;
use SilverStripe\Dev\TestOnly;
class VirtualPageTest_PageWithAllowedChildren extends Page implements TestOnly
{
private static $allowed_children = array(
VirtualPageTest_ClassA::class,
VirtualPage::class,
);
}

View File

@ -0,0 +1,12 @@
<?php
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\FieldType\DBVarchar;
class VirtualPageTest_TestDBField extends DBVarchar implements TestOnly
{
public function forTemplate()
{
return strtoupper($this->XML());
}
}

View File

@ -0,0 +1,11 @@
<?php
use SilverStripe\CMS\Model\VirtualPage;
use SilverStripe\Dev\TestOnly;
class VirtualPageTest_VirtualPageSub extends VirtualPage implements TestOnly
{
private static $db = array(
'MyProperty' => 'Varchar',
);
}

View File

@ -51,10 +51,10 @@ class ZZZSearchFormTest extends FunctionalTest
{
// HACK Postgres doesn't refresh TSearch indexes when the schema changes after CREATE TABLE
// MySQL will need a different table type
static::kill_temp_db();
static::$tempDB->kill();
Config::modify();
FulltextSearchable::enable();
static::create_temp_db();
static::$tempDB->build();
static::resetDBSchema(true);
parent::setUpBeforeClass();
}
@ -116,9 +116,11 @@ class ZZZSearchFormTest extends FunctionalTest
}
$request = new HTTPRequest('GET', 'search', ['Search'=>'publicPublishedPage']);
$request->setSession($this->session());
$this->mockController->setRequest($request);
$sf = new SearchForm($this->mockController);
/** @var SiteTree $publishedPage */
$publishedPage = $this->objFromFixture(SiteTree::class, 'publicPublishedPage');
$publishedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
@ -142,9 +144,11 @@ class ZZZSearchFormTest extends FunctionalTest
}
$request = new HTTPRequest('GET', 'search', ['Search'=>'"finding butterflies"']);
$request->setSession($this->session());
$this->mockController->setRequest($request);
$sf = new SearchForm($this->mockController);
/** @var SiteTree $publishedPage */
$publishedPage = $this->objFromFixture(SiteTree::class, 'publicPublishedPage');
$publishedPage->Title = "finding butterflies";
$publishedPage->write();
@ -169,6 +173,7 @@ class ZZZSearchFormTest extends FunctionalTest
}
$request = new HTTPRequest('GET', 'search', ['Search'=>'publicUnpublishedPage']);
$request->setSession($this->session());
$this->mockController->setRequest($request);
$sf = new SearchForm($this->mockController);
@ -188,9 +193,11 @@ class ZZZSearchFormTest extends FunctionalTest
}
$request = new HTTPRequest('GET', 'search', ['Search'=>'restrictedViewLoggedInUsers']);
$request->setSession($this->session());
$this->mockController->setRequest($request);
$sf = new SearchForm($this->mockController);
/** @var SiteTree $page */
$page = $this->objFromFixture(SiteTree::class, 'restrictedViewLoggedInUsers');
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$results = $sf->getResults();
@ -218,9 +225,11 @@ class ZZZSearchFormTest extends FunctionalTest
}
$request = new HTTPRequest('GET', 'search', ['Search'=>'restrictedViewOnlyWebsiteUsers']);
$request->setSession($this->session());
$this->mockController->setRequest($request);
$sf = new SearchForm($this->mockController);
/** @var SiteTree $page */
$page = $this->objFromFixture(SiteTree::class, 'restrictedViewOnlyWebsiteUsers');
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$results = $sf->getResults();
@ -251,15 +260,21 @@ class ZZZSearchFormTest extends FunctionalTest
Security::setCurrentUser(null);
}
/**
*
*/
public function testInheritedRestrictedPagesNotIncluded()
{
$request = new HTTPRequest('GET', 'search', ['Search'=>'inheritRestrictedView']);
$request->setSession($this->session());
$this->mockController->setRequest($request);
$sf = new SearchForm($this->mockController);
/** @var SiteTree $parent */
$parent = $this->objFromFixture(SiteTree::class, 'restrictedViewLoggedInUsers');
$parent->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
/** @var SiteTree $page */
$page = $this->objFromFixture(SiteTree::class, 'inheritRestrictedView');
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$results = $sf->getResults();
@ -287,6 +302,7 @@ class ZZZSearchFormTest extends FunctionalTest
}
$request = new HTTPRequest('GET', 'search', ['Search'=>'dontShowInSearchPage']);
$request->setSession($this->session());
$this->mockController->setRequest($request);
$sf = new SearchForm($this->mockController);
@ -306,11 +322,14 @@ class ZZZSearchFormTest extends FunctionalTest
}
$request = new HTTPRequest('GET', 'search', ['Search'=>'dontShowInSearchFile']);
$request->setSession($this->session());
$this->mockController->setRequest($request);
$sf = new SearchForm($this->mockController);
/** @var File $dontShowInSearchFile */
$dontShowInSearchFile = $this->objFromFixture(File::class, 'dontShowInSearchFile');
$dontShowInSearchFile->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
/** @var File $showInSearchFile */
$showInSearchFile = $this->objFromFixture(File::class, 'showInSearchFile');
$showInSearchFile->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
@ -323,6 +342,7 @@ class ZZZSearchFormTest extends FunctionalTest
// Check ShowInSearch=1 can be found
$request = new HTTPRequest('GET', 'search', ['Search'=>'showInSearchFile']);
$request->setSession($this->session());
$this->mockController->setRequest($request);
$sf = new SearchForm($this->mockController);
$results = $sf->getResults();
@ -344,9 +364,11 @@ class ZZZSearchFormTest extends FunctionalTest
}
$request = new HTTPRequest('GET', 'search', ['Search'=>'Brötchen']);
$request->setSession($this->session());
$this->mockController->setRequest($request);
$sf = new SearchForm($this->mockController);
/** @var SiteTree $pageWithSpecialChars */
$pageWithSpecialChars = $this->objFromFixture(SiteTree::class, 'pageWithSpecialChars');
$pageWithSpecialChars->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
@ -359,6 +381,7 @@ class ZZZSearchFormTest extends FunctionalTest
// Check another word
$request = new HTTPRequest('GET', 'search', ['Search'=>'Bäcker']);
$request->setSession($this->session());
$this->mockController->setRequest($request);
$sf = new SearchForm($this->mockController);
$results = $sf->getResults();