mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
Merge pull request #1854 from open-sausages/pulls/4.0/app-object
[WIP] App object refactor
This commit is contained in:
commit
ecbd778547
@ -7,6 +7,7 @@ use SilverStripe\Admin\CMSBatchActionHandler;
|
||||
use SilverStripe\Admin\LeftAndMain_SearchFilter;
|
||||
use SilverStripe\Admin\LeftAndMainFormRequestHandler;
|
||||
use SilverStripe\CMS\Model\VirtualPage;
|
||||
use SilverStripe\Core\Environment;
|
||||
use SilverStripe\Forms\Tab;
|
||||
use SilverStripe\ORM\CMSPreviewable;
|
||||
use SilverStripe\Admin\LeftAndMain;
|
||||
@ -1576,7 +1577,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
||||
public function getNewItem($id, $setID = true)
|
||||
{
|
||||
$parentClass = $this->stat('tree_class');
|
||||
list($dummy, $className, $parentID, $suffix) = array_pad(explode('-', $id), 4, null);
|
||||
list(, $className, $parentID) = array_pad(explode('-', $id), 3, null);
|
||||
|
||||
if (!is_a($className, $parentClass, true)) {
|
||||
$response = Security::permissionFailure($this);
|
||||
@ -1588,18 +1589,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
||||
|
||||
/** @var SiteTree $newItem */
|
||||
$newItem = Injector::inst()->create($className);
|
||||
if (!$suffix) {
|
||||
$sessionTag = "NewItems." . $parentID . "." . $className;
|
||||
if (Session::get($sessionTag)) {
|
||||
$suffix = '-' . Session::get($sessionTag);
|
||||
Session::set($sessionTag, Session::get($sessionTag) + 1);
|
||||
} else {
|
||||
Session::set($sessionTag, 1);
|
||||
}
|
||||
|
||||
$id = $id . $suffix;
|
||||
}
|
||||
|
||||
$newItem->Title = _t(
|
||||
'SilverStripe\\CMS\\Controllers\\CMSMain.NEWPAGE',
|
||||
"New {pagetype}",
|
||||
@ -1612,10 +1601,14 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
||||
// DataObject::fieldExists only checks the current class, not the hierarchy
|
||||
// This allows the CMS to set the correct sort value
|
||||
if ($newItem->castingHelper('Sort')) {
|
||||
$newItem->Sort = DB::prepared_query('SELECT MAX("Sort") FROM "SiteTree" WHERE "ParentID" = ?', array($parentID))->value() + 1;
|
||||
$maxSort = DB::prepared_query(
|
||||
'SELECT MAX("Sort") FROM "SiteTree" WHERE "ParentID" = ?',
|
||||
array($parentID)
|
||||
)->value();
|
||||
$newItem->Sort = (int)$maxSort + 1;
|
||||
}
|
||||
|
||||
if ($setID) {
|
||||
if ($setID && $id) {
|
||||
$newItem->ID = $id;
|
||||
}
|
||||
|
||||
@ -1891,8 +1884,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
||||
return Security::permissionFailure($this);
|
||||
}
|
||||
|
||||
increase_time_limit_to();
|
||||
increase_memory_limit_to();
|
||||
Environment::increaseTimeLimitTo();
|
||||
Environment::increaseMemoryLimitTo();
|
||||
|
||||
$response = "";
|
||||
|
||||
@ -2034,7 +2027,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
||||
if (!SecurityToken::inst()->checkRequest($request)) {
|
||||
return $this->httpError(400);
|
||||
}
|
||||
increase_time_limit_to();
|
||||
Environment::increaseTimeLimitTo();
|
||||
if (($id = $this->urlParams['ID']) && is_numeric($id)) {
|
||||
/** @var SiteTree $page */
|
||||
$page = SiteTree::get()->byID($id);
|
||||
|
@ -180,8 +180,6 @@ class CMSPageAddController extends CMSPageEditController
|
||||
$className = isset($data['PageType']) ? $data['PageType'] : "Page";
|
||||
$parentID = isset($data['ParentID']) ? (int)$data['ParentID'] : 0;
|
||||
|
||||
$suffix = isset($data['Suffix']) ? "-" . $data['Suffix'] : null;
|
||||
|
||||
if (!$parentID && isset($data['Parent'])) {
|
||||
$page = SiteTree::get_by_link($data['Parent']);
|
||||
if ($page) {
|
||||
@ -203,18 +201,20 @@ class CMSPageAddController extends CMSPageEditController
|
||||
return Security::permissionFailure($this);
|
||||
}
|
||||
|
||||
$record = $this->getNewItem("new-$className-$parentID".$suffix, false);
|
||||
$record = $this->getNewItem("new-$className-$parentID", false);
|
||||
$this->extend('updateDoAdd', $record, $form);
|
||||
$record->write();
|
||||
|
||||
$editController = CMSPageEditController::singleton();
|
||||
$editController->setRequest($this->getRequest());
|
||||
$editController->setCurrentPageID($record->ID);
|
||||
|
||||
Session::set(
|
||||
$session = $this->getRequest()->getSession();
|
||||
$session->set(
|
||||
"FormInfo.Form_EditForm.formError.message",
|
||||
_t('SilverStripe\\CMS\\Controllers\\CMSMain.PageAdded', 'Successfully created page')
|
||||
);
|
||||
Session::set("FormInfo.Form_EditForm.formError.type", 'good');
|
||||
$session->set("FormInfo.Form_EditForm.formError.type", 'good');
|
||||
|
||||
return $this->redirect(Controller::join_links($editController->Link('show'), $record->ID));
|
||||
}
|
||||
|
@ -5,24 +5,22 @@ namespace SilverStripe\CMS\Controllers;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Control\Session;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\HTTPResponse;
|
||||
use SilverStripe\Control\HTTPResponse_Exception;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\i18n\i18n;
|
||||
use SilverStripe\ORM\ArrayList;
|
||||
use SilverStripe\ORM\DataModel;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||
use SilverStripe\ORM\FieldType\DBField;
|
||||
use SilverStripe\ORM\FieldType\DBHTMLText;
|
||||
use SilverStripe\ORM\FieldType\DBVarchar;
|
||||
use SilverStripe\ORM\SS_List;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use SilverStripe\Security\Permission;
|
||||
use SilverStripe\Security\Security;
|
||||
use SilverStripe\SiteConfig\SiteConfig;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use SilverStripe\View\ArrayData;
|
||||
use SilverStripe\View\Requirements;
|
||||
use SilverStripe\View\SSViewer;
|
||||
@ -169,16 +167,14 @@ class ContentController extends Controller
|
||||
* fall over to a child controller in order to provide functionality for nested URLs.
|
||||
*
|
||||
* @param HTTPRequest $request
|
||||
* @param DataModel $model
|
||||
* @return HTTPResponse
|
||||
* @throws HTTPResponse_Exception
|
||||
*/
|
||||
public function handleRequest(HTTPRequest $request, DataModel $model)
|
||||
public function handleRequest(HTTPRequest $request)
|
||||
{
|
||||
/** @var SiteTree $child */
|
||||
$child = null;
|
||||
$action = $request->param('Action');
|
||||
$this->setDataModel($model);
|
||||
|
||||
// If nested URLs are enabled, and there is no action handler for the current request then attempt to pass
|
||||
// control to a child controller. This allows for the creation of chains of controllers which correspond to a
|
||||
@ -203,7 +199,7 @@ class ContentController extends Controller
|
||||
$request->shiftAllParams();
|
||||
$request->shift();
|
||||
|
||||
$response = ModelAsController::controller_for($child)->handleRequest($request, $model);
|
||||
$response = ModelAsController::controller_for($child)->handleRequest($request);
|
||||
} else {
|
||||
// If a specific locale is requested, and it doesn't match the page found by URLSegment,
|
||||
// look for a translation and redirect (see #5001). Only happens on the last child in
|
||||
@ -227,7 +223,7 @@ class ContentController extends Controller
|
||||
Director::set_current_page($this->data());
|
||||
|
||||
try {
|
||||
$response = parent::handleRequest($request, $model);
|
||||
$response = parent::handleRequest($request);
|
||||
|
||||
Director::set_current_page(null);
|
||||
} catch (HTTPResponse_Exception $e) {
|
||||
@ -474,8 +470,8 @@ HTML;
|
||||
global $project;
|
||||
$data = new ArrayData(array(
|
||||
'Project' => Convert::raw2xml($project),
|
||||
'Username' => Convert::raw2xml(Session::get('username')),
|
||||
'Password' => Convert::raw2xml(Session::get('password')),
|
||||
'Username' => Convert::raw2xml($this->getRequest()->getSession()->get('username')),
|
||||
'Password' => Convert::raw2xml($this->getRequest()->getSession()->get('password')),
|
||||
));
|
||||
|
||||
return array(
|
||||
@ -518,8 +514,8 @@ HTML;
|
||||
}
|
||||
|
||||
$data = new ArrayData(array(
|
||||
'Username' => Convert::raw2xml(Session::get('username')),
|
||||
'Password' => Convert::raw2xml(Session::get('password')),
|
||||
'Username' => Convert::raw2xml($this->getRequest()->getSession()->get('username')),
|
||||
'Password' => Convert::raw2xml($this->getRequest()->getSession()->get('password')),
|
||||
'UnsuccessfulFiles' => $unsuccessful
|
||||
));
|
||||
$content->setValue($data->renderWith([
|
||||
|
@ -2,22 +2,20 @@
|
||||
|
||||
namespace SilverStripe\CMS\Controllers;
|
||||
|
||||
use Exception;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Control\NestedController;
|
||||
use SilverStripe\Control\RequestHandler;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\HTTPResponse;
|
||||
use SilverStripe\Control\HTTPResponse_Exception;
|
||||
use SilverStripe\Control\NestedController;
|
||||
use SilverStripe\Control\RequestHandler;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Dev\Debug;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\ORM\DataModel;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\DB;
|
||||
use Exception;
|
||||
use Translatable;
|
||||
|
||||
/**
|
||||
@ -26,8 +24,9 @@ use Translatable;
|
||||
*/
|
||||
class ModelAsController extends Controller implements NestedController
|
||||
{
|
||||
|
||||
private static $extensions = array('SilverStripe\\CMS\\Controllers\\OldPageRedirector');
|
||||
private static $extensions = [
|
||||
OldPageRedirector::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the appropriate {@link ContentController} for handling a {@link SiteTree} object, link it to the object and
|
||||
@ -54,9 +53,9 @@ class ModelAsController extends Controller implements NestedController
|
||||
parent::init();
|
||||
}
|
||||
|
||||
protected function beforeHandleRequest(HTTPRequest $request, DataModel $model)
|
||||
protected function beforeHandleRequest(HTTPRequest $request)
|
||||
{
|
||||
parent::beforeHandleRequest($request, $model);
|
||||
parent::beforeHandleRequest($request);
|
||||
// If the database has not yet been created, redirect to the build page.
|
||||
/** @skipUpgrade */
|
||||
if (!DB::is_active() || !ClassInfo::hasTable('SiteTree')) {
|
||||
@ -73,12 +72,11 @@ class ModelAsController extends Controller implements NestedController
|
||||
/**
|
||||
* @uses ModelAsController::getNestedController()
|
||||
* @param HTTPRequest $request
|
||||
* @param DataModel $model
|
||||
* @return HTTPResponse
|
||||
*/
|
||||
public function handleRequest(HTTPRequest $request, DataModel $model)
|
||||
public function handleRequest(HTTPRequest $request)
|
||||
{
|
||||
$this->beforeHandleRequest($request, $model);
|
||||
$this->beforeHandleRequest($request);
|
||||
|
||||
// If we had a redirection or something, halt processing.
|
||||
if ($this->getResponse()->isFinished()) {
|
||||
@ -99,7 +97,7 @@ class ModelAsController extends Controller implements NestedController
|
||||
$result = $this->getNestedController();
|
||||
|
||||
if ($result instanceof RequestHandler) {
|
||||
$result = $result->handleRequest($this->getRequest(), $model);
|
||||
$result = $result->handleRequest($this->getRequest());
|
||||
} elseif (!($result instanceof HTTPResponse)) {
|
||||
user_error("ModelAsController::getNestedController() returned bad object type '" .
|
||||
get_class($result)."'", E_USER_WARNING);
|
||||
@ -131,11 +129,11 @@ class ModelAsController extends Controller implements NestedController
|
||||
|
||||
// Select child page
|
||||
$conditions = array('"SiteTree"."URLSegment"' => rawurlencode($URLSegment));
|
||||
if (SiteTree::config()->nested_urls) {
|
||||
if (SiteTree::config()->get('nested_urls')) {
|
||||
$conditions[] = array('"SiteTree"."ParentID"' => 0);
|
||||
}
|
||||
/** @var SiteTree $sitetree */
|
||||
$sitetree = DataObject::get_one('SilverStripe\\CMS\\Model\\SiteTree', $conditions);
|
||||
$sitetree = DataObject::get_one(SiteTree::class, $conditions);
|
||||
|
||||
// Check translation module
|
||||
// @todo Refactor out module specific code
|
||||
|
@ -10,8 +10,6 @@ use SilverStripe\Control\HTTPResponse;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Core\Resettable;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\ORM\DataModel;
|
||||
use SilverStripe\ORM\DB;
|
||||
use Translatable;
|
||||
|
||||
@ -103,9 +101,9 @@ class RootURLController extends Controller implements Resettable
|
||||
self::$cached_homepage_link = null;
|
||||
}
|
||||
|
||||
protected function beforeHandleRequest(HTTPRequest $request, DataModel $model)
|
||||
protected function beforeHandleRequest(HTTPRequest $request)
|
||||
{
|
||||
parent::beforeHandleRequest($request, $model);
|
||||
parent::beforeHandleRequest($request);
|
||||
|
||||
self::$is_at_root = true;
|
||||
|
||||
@ -123,13 +121,12 @@ class RootURLController extends Controller implements Resettable
|
||||
|
||||
/**
|
||||
* @param HTTPRequest $request
|
||||
* @param DataModel|null $model
|
||||
* @return HTTPResponse
|
||||
*/
|
||||
public function handleRequest(HTTPRequest $request, DataModel $model = null)
|
||||
public function handleRequest(HTTPRequest $request)
|
||||
{
|
||||
self::$is_at_root = true;
|
||||
$this->beforeHandleRequest($request, $model);
|
||||
$this->beforeHandleRequest($request);
|
||||
|
||||
if (!$this->getResponse()->isFinished()) {
|
||||
/** @skipUpgrade */
|
||||
@ -142,7 +139,7 @@ class RootURLController extends Controller implements Resettable
|
||||
$request->match('$URLSegment//$Action', true);
|
||||
$controller = new ModelAsController();
|
||||
|
||||
$response = $controller->handleRequest($request, $model);
|
||||
$response = $controller->handleRequest($request);
|
||||
|
||||
$this->prepareResponse($response);
|
||||
}
|
||||
|
@ -2,21 +2,23 @@
|
||||
|
||||
namespace SilverStripe\CMS\Model;
|
||||
|
||||
use Page;
|
||||
use SilverStripe\Assets\File;
|
||||
use SilverStripe\Assets\Storage\GeneratedAssetHandler;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\ORM\DataModel;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use SilverStripe\ORM\DB;
|
||||
use SilverStripe\CMS\Controllers\ModelAsController;
|
||||
use SilverStripe\View\Requirements;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\HTTPResponse;
|
||||
use SilverStripe\Forms\DropdownField;
|
||||
use SilverStripe\Assets\File;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use Page;
|
||||
use SilverStripe\Dev\Debug;
|
||||
use SilverStripe\Forms\DropdownField;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\ORM\DB;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use SilverStripe\View\Requirements;
|
||||
use SilverStripe\View\SSViewer;
|
||||
|
||||
/**
|
||||
* ErrorPage holds the content for the page of an error response.
|
||||
@ -32,7 +34,6 @@ use Page;
|
||||
*/
|
||||
class ErrorPage extends Page
|
||||
{
|
||||
|
||||
private static $db = array(
|
||||
"ErrorCode" => "Int",
|
||||
);
|
||||
@ -96,11 +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', ''),
|
||||
DataModel::inst()
|
||||
);
|
||||
->handleRequest($request);
|
||||
}
|
||||
|
||||
// then fall back on a cached version
|
||||
@ -279,7 +279,7 @@ class ErrorPage extends Page
|
||||
|
||||
// Run the page (reset the theme, it might've been disabled by LeftAndMain::init())
|
||||
Config::nest();
|
||||
Config::inst()->update('SilverStripe\\View\\SSViewer', 'theme_enabled', true);
|
||||
SSViewer::config()->set('theme_enabled', true);
|
||||
$response = Director::test(Director::makeRelative($this->Link()));
|
||||
Config::unnest();
|
||||
$errorContent = $response->getBody();
|
||||
@ -359,7 +359,7 @@ class ErrorPage extends Page
|
||||
505 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_505', '505 - HTTP Version Not Supported'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the filename identifier for the given error code.
|
||||
* Used when handling responses under error conditions.
|
||||
|
@ -1,17 +1,15 @@
|
||||
<?php
|
||||
namespace SilverStripe\CMS\Model;
|
||||
|
||||
use SilverStripe\ORM\DataModel;
|
||||
use PageController;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\HTTPResponse;
|
||||
use PageController;
|
||||
|
||||
/**
|
||||
* Controller for ErrorPages.
|
||||
*/
|
||||
class ErrorPageController extends PageController
|
||||
{
|
||||
|
||||
/**
|
||||
* Overload the provided {@link Controller::handleRequest()} to append the
|
||||
* correct status code post request since otherwise permission related error
|
||||
@ -19,13 +17,14 @@ class ErrorPageController extends PageController
|
||||
* {@link HTTPResponse::isFinished() ignoring the response body.
|
||||
*
|
||||
* @param HTTPRequest $request
|
||||
* @param DataModel $model
|
||||
* @return HTTPResponse
|
||||
*/
|
||||
public function handleRequest(HTTPRequest $request, DataModel $model = null)
|
||||
public function handleRequest(HTTPRequest $request)
|
||||
{
|
||||
$response = parent::handleRequest($request, $model);
|
||||
$response->setStatusCode($this->ErrorCode);
|
||||
/** @var ErrorPage $page */
|
||||
$page = $this->data();
|
||||
$response = parent::handleRequest($request);
|
||||
$response->setStatusCode($page->ErrorCode);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ class ContentControllerSearchExtension extends Extension
|
||||
|
||||
/**
|
||||
* Site search form
|
||||
*
|
||||
* @return SearchForm
|
||||
*/
|
||||
public function SearchForm()
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ Feature: Duplicate a page
|
||||
And I click on "This page and subpages" in the context menu
|
||||
Then I should see a "Duplicated 'Page1' and children successfully" notice
|
||||
|
||||
When I fill in "Title" with "Duplicate Page"
|
||||
When I fill in "MenuTitle" with "Duplicate Page"
|
||||
And I press the "Save & publish" button
|
||||
Then I should see "Page1" in the tree
|
||||
And I should see "Duplicate Page" in the tree
|
||||
|
@ -4,4 +4,3 @@ require __DIR__ . '/../bootstrap/init.php';
|
||||
require FRAMEWORK_PATH . '/tests/bootstrap/init.php';
|
||||
require FRAMEWORK_PATH . '/tests/bootstrap/environment.php';
|
||||
require __DIR__ . '/../bootstrap/mysite.php';
|
||||
require FRAMEWORK_PATH . '/tests/bootstrap/mysite.php';
|
||||
|
@ -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';
|
||||
|
@ -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
|
||||
@ -125,7 +126,7 @@ class CMSMainTest extends FunctionalTest
|
||||
{
|
||||
$page1 = $this->objFromFixture(Page::class, "page1");
|
||||
$page2 = $this->objFromFixture(Page::class, "page2");
|
||||
$this->session()->inst_set('loggedInAs', $this->idFromFixture('SilverStripe\\Security\\Member', 'admin'));
|
||||
$this->session()->set('loggedInAs', $this->idFromFixture('SilverStripe\\Security\\Member', 'admin'));
|
||||
|
||||
$response = $this->get('admin/pages/publishall?confirm=1');
|
||||
$this->assertContains(
|
||||
@ -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
|
||||
{
|
||||
|
||||
}
|
||||
|
18
tests/controller/CMSMainTest_ClassA.php
Normal file
18
tests/controller/CMSMainTest_ClassA.php
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
16
tests/controller/CMSMainTest_ClassB.php
Normal file
16
tests/controller/CMSMainTest_ClassB.php
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
9
tests/controller/CMSMainTest_HiddenClass.php
Normal file
9
tests/controller/CMSMainTest_HiddenClass.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\ORM\HiddenClass;
|
||||
|
||||
class CMSMainTest_HiddenClass extends Page implements TestOnly, HiddenClass
|
||||
{
|
||||
|
||||
}
|
8
tests/controller/CMSMainTest_NotRoot.php
Normal file
8
tests/controller/CMSMainTest_NotRoot.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
|
||||
class CMSMainTest_NotRoot extends Page implements TestOnly
|
||||
{
|
||||
private static $can_be_root = false;
|
||||
}
|
@ -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', [
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
8
tests/controller/ContentControllerTestPage.php
Normal file
8
tests/controller/ContentControllerTestPage.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
|
||||
class ContentControllerTestPage extends Page implements TestOnly
|
||||
{
|
||||
|
||||
}
|
16
tests/controller/ContentControllerTestPageController.php
Normal file
16
tests/controller/ContentControllerTestPageController.php
Normal 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();
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
|
||||
class ContentControllerTestPageWithoutController extends Page implements TestOnly
|
||||
{
|
||||
|
||||
}
|
8
tests/controller/ContentControllerTest_Page.php
Normal file
8
tests/controller/ContentControllerTest_Page.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
|
||||
class ContentControllerTest_Page extends Page implements TestOnly
|
||||
{
|
||||
|
||||
}
|
21
tests/controller/ContentControllerTest_PageController.php
Normal file
21
tests/controller/ContentControllerTest_PageController.php
Normal 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();
|
||||
}
|
||||
}
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
17
tests/controller/SilverStripeNavigatorTest_TestItem.php
Normal file
17
tests/controller/SilverStripeNavigatorTest_TestItem.php
Normal 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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
13
tests/model/RedirectorPageTest_RedirectExtension.php
Normal file
13
tests/model/RedirectorPageTest_RedirectExtension.php
Normal 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');
|
||||
}
|
||||
}
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
17
tests/model/SiteTreeActionsTest_Page.php
Normal file
17
tests/model/SiteTreeActionsTest_Page.php
Normal 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');
|
||||
}
|
||||
}
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
18
tests/model/SiteTreeBacklinksTest_DOD.php
Normal file
18
tests/model/SiteTreeBacklinksTest_DOD.php
Normal 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"));
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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');
|
||||
@ -198,7 +197,7 @@ class SiteTreePermissionsTest extends FunctionalTest
|
||||
'Users without SITETREE_GRANT_ACCESS permission cannot change "edit" permissions in cms fields'
|
||||
);
|
||||
|
||||
$this->session()->inst_set('loggedInAs', null);
|
||||
$this->session()->set('loggedInAs', null);
|
||||
}
|
||||
|
||||
public function testRestrictedViewLoggedInUsers()
|
||||
|
@ -53,17 +53,6 @@ class SiteTreeTest extends SapphireTest
|
||||
SiteTreeTest_StageStatusInherit::class,
|
||||
);
|
||||
|
||||
/**
|
||||
* Ensure any current member is logged out
|
||||
*/
|
||||
public function logOut()
|
||||
{
|
||||
if ($member = Security::getCurrentUser()) {
|
||||
Session::clear('loggedInAs');
|
||||
Security::setCurrentUser(null);
|
||||
}
|
||||
}
|
||||
|
||||
public function testCreateDefaultpages()
|
||||
{
|
||||
$remove = SiteTree::get();
|
||||
@ -1443,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
|
||||
{
|
||||
|
||||
}
|
||||
|
10
tests/model/SiteTreeTest_AdminDenied.php
Normal file
10
tests/model/SiteTreeTest_AdminDenied.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
|
||||
class SiteTreeTest_AdminDenied extends Page implements TestOnly
|
||||
{
|
||||
private static $extensions = array(
|
||||
'SiteTreeTest_AdminDeniedExtension'
|
||||
);
|
||||
}
|
35
tests/model/SiteTreeTest_AdminDeniedExtension.php
Normal file
35
tests/model/SiteTreeTest_AdminDeniedExtension.php
Normal 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;
|
||||
}
|
||||
}
|
15
tests/model/SiteTreeTest_ClassA.php
Normal file
15
tests/model/SiteTreeTest_ClassA.php
Normal 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
|
||||
];
|
||||
}
|
9
tests/model/SiteTreeTest_ClassB.php
Normal file
9
tests/model/SiteTreeTest_ClassB.php
Normal 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);
|
||||
}
|
8
tests/model/SiteTreeTest_ClassC.php
Normal file
8
tests/model/SiteTreeTest_ClassC.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
|
||||
class SiteTreeTest_ClassC extends Page implements TestOnly
|
||||
{
|
||||
private static $allowed_children = array();
|
||||
}
|
9
tests/model/SiteTreeTest_ClassCext.php
Normal file
9
tests/model/SiteTreeTest_ClassCext.php
Normal 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);
|
||||
}
|
23
tests/model/SiteTreeTest_ClassD.php
Normal file
23
tests/model/SiteTreeTest_ClassD.php
Normal 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);
|
||||
}
|
||||
}
|
9
tests/model/SiteTreeTest_ClassE.php
Normal file
9
tests/model/SiteTreeTest_ClassE.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\ORM\HiddenClass;
|
||||
|
||||
class SiteTreeTest_ClassE extends Page implements TestOnly, HiddenClass
|
||||
{
|
||||
|
||||
}
|
8
tests/model/SiteTreeTest_Conflicted.php
Normal file
8
tests/model/SiteTreeTest_Conflicted.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
|
||||
class SiteTreeTest_Conflicted extends Page implements TestOnly
|
||||
{
|
||||
|
||||
}
|
20
tests/model/SiteTreeTest_ConflictedController.php
Normal file
20
tests/model/SiteTreeTest_ConflictedController.php
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
12
tests/model/SiteTreeTest_Extension.php
Normal file
12
tests/model/SiteTreeTest_Extension.php
Normal 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;
|
||||
}
|
||||
}
|
14
tests/model/SiteTreeTest_ExtensionA.php
Normal file
14
tests/model/SiteTreeTest_ExtensionA.php
Normal 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;
|
||||
}
|
||||
}
|
14
tests/model/SiteTreeTest_ExtensionB.php
Normal file
14
tests/model/SiteTreeTest_ExtensionB.php
Normal 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;
|
||||
}
|
||||
}
|
11
tests/model/SiteTreeTest_LegacyControllerName.php
Normal file
11
tests/model/SiteTreeTest_LegacyControllerName.php
Normal 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
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
|
||||
class SiteTreeTest_LegacyControllerName_Controller extends PageController implements TestOnly
|
||||
{
|
||||
|
||||
}
|
8
tests/model/SiteTreeTest_NotRoot.php
Normal file
8
tests/model/SiteTreeTest_NotRoot.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
|
||||
class SiteTreeTest_NotRoot extends Page implements TestOnly
|
||||
{
|
||||
private static $can_be_root = false;
|
||||
}
|
12
tests/model/SiteTreeTest_NullHtmlCleaner.php
Normal file
12
tests/model/SiteTreeTest_NullHtmlCleaner.php
Normal 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;
|
||||
}
|
||||
}
|
8
tests/model/SiteTreeTest_PageNode.php
Normal file
8
tests/model/SiteTreeTest_PageNode.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
|
||||
class SiteTreeTest_PageNode extends Page implements TestOnly
|
||||
{
|
||||
|
||||
}
|
7
tests/model/SiteTreeTest_PageNodeController.php
Normal file
7
tests/model/SiteTreeTest_PageNodeController.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
|
||||
class SiteTreeTest_PageNodeController extends PageController implements TestOnly
|
||||
{
|
||||
}
|
14
tests/model/SiteTreeTest_StageStatusInherit.php
Normal file
14
tests/model/SiteTreeTest_StageStatusInherit.php
Normal 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;
|
||||
}
|
||||
}
|
@ -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'
|
||||
);
|
||||
}
|
||||
|
20
tests/model/VirtualPageTest_ClassA.php
Normal file
20
tests/model/VirtualPageTest_ClassA.php
Normal 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';
|
||||
}
|
||||
}
|
15
tests/model/VirtualPageTest_ClassAController.php
Normal file
15
tests/model/VirtualPageTest_ClassAController.php
Normal 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';
|
||||
}
|
||||
}
|
8
tests/model/VirtualPageTest_ClassB.php
Normal file
8
tests/model/VirtualPageTest_ClassB.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
|
||||
class VirtualPageTest_ClassB extends Page implements TestOnly
|
||||
{
|
||||
private static $allowed_children = array('VirtualPageTest_ClassC');
|
||||
}
|
8
tests/model/VirtualPageTest_ClassC.php
Normal file
8
tests/model/VirtualPageTest_ClassC.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
|
||||
class VirtualPageTest_ClassC extends Page implements TestOnly
|
||||
{
|
||||
private static $allowed_children = array();
|
||||
}
|
8
tests/model/VirtualPageTest_NotRoot.php
Normal file
8
tests/model/VirtualPageTest_NotRoot.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
|
||||
class VirtualPageTest_NotRoot extends Page implements TestOnly
|
||||
{
|
||||
private static $can_be_root = false;
|
||||
}
|
14
tests/model/VirtualPageTest_PageExtension.php
Normal file
14
tests/model/VirtualPageTest_PageExtension.php
Normal 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',
|
||||
);
|
||||
}
|
12
tests/model/VirtualPageTest_PageWithAllowedChildren.php
Normal file
12
tests/model/VirtualPageTest_PageWithAllowedChildren.php
Normal 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,
|
||||
);
|
||||
}
|
12
tests/model/VirtualPageTest_TestDBField.php
Normal file
12
tests/model/VirtualPageTest_TestDBField.php
Normal 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());
|
||||
}
|
||||
}
|
11
tests/model/VirtualPageTest_VirtualPageSub.php
Normal file
11
tests/model/VirtualPageTest_VirtualPageSub.php
Normal 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',
|
||||
);
|
||||
}
|
@ -9,7 +9,7 @@ class CMSMainSearchFormTest extends FunctionalTest
|
||||
|
||||
public function testTitleFilter()
|
||||
{
|
||||
$this->session()->inst_set('loggedInAs', $this->idFromFixture('SilverStripe\\Security\\Member', 'admin'));
|
||||
$this->session()->set('loggedInAs', $this->idFromFixture('SilverStripe\\Security\\Member', 'admin'));
|
||||
|
||||
$response = $this->get(
|
||||
'admin/pages/SearchForm/?' .
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user