ENH PHP 8.1 compatibility

This commit is contained in:
Steve Boyd 2022-04-13 17:07:59 +12:00
parent 13c1ae487f
commit 1b0b2154b4
40 changed files with 203 additions and 203 deletions

View File

@ -57,6 +57,6 @@ class CMSBatchAction_Restore extends CMSBatchAction
// Get pages that exist in stage and remove them from the restore-able set
$stageIDs = Versioned::get_by_stage($this->managedClass, Versioned::DRAFT)->column('ID');
return array_values(array_diff($ids, $stageIDs));
return array_values(array_diff($ids ?? [], $stageIDs));
}
}

View File

@ -184,7 +184,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
{
// set reading lang
if (SiteTree::has_extension('Translatable') && !$this->getRequest()->isAjax()) {
Translatable::choose_site_locale(array_keys(Translatable::get_existing_content_languages(SiteTree::class)));
Translatable::choose_site_locale(array_keys(Translatable::get_existing_content_languages(SiteTree::class) ?? []));
}
parent::init();
@ -454,7 +454,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
];
$link = Controller::join_links(
$link,
array_filter(array_values($params)) ? '?' . http_build_query($params) : null
array_filter(array_values($params ?? [])) ? '?' . http_build_query($params) : null
);
$this->extend('updateLinkWithSearch', $link);
return $link;
@ -470,7 +470,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
}
if ($placeholders) {
$link .= (strpos($link, '?') === false ? "?$placeholders" : "&$placeholders");
$link .= (strpos($link ?? '', '?') === false ? "?$placeholders" : "&$placeholders");
}
return $link;
@ -627,7 +627,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// Get status flag classes
$flags = $node->getStatusFlags();
if ($flags) {
$statuses = array_keys($flags);
$statuses = array_keys($flags ?? []);
foreach ($statuses as $s) {
$classes .= ' status-' . $s;
}
@ -642,7 +642,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$classes .= ' ' . $filterClasses;
}
return trim($classes);
return trim($classes ?? '');
}
/**
@ -664,8 +664,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
);
// Trim off the outer tag
$html = preg_replace('/^[\s\t\r\n]*<ul[^>]*>/', '', $html);
$html = preg_replace('/<\/ul[^>]*>[\s\t\r\n]*$/', '', $html);
$html = preg_replace('/^[\s\t\r\n]*<ul[^>]*>/', '', $html ?? '');
$html = preg_replace('/<\/ul[^>]*>[\s\t\r\n]*$/', '', $html ?? '');
return $html;
}
@ -682,7 +682,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
public function updatetreenodes($request)
{
$data = [];
$ids = explode(',', $request->getVar('ids'));
$ids = explode(',', $request->getVar('ids') ?? '');
foreach ($ids as $id) {
if ($id === "") {
continue; // $id may be a blank string, which is invalid and should be skipped over
@ -824,7 +824,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$this->getResponse()->addHeader(
'X-Status',
rawurlencode(_t(__CLASS__.'.REORGANISATIONSUCCESSFUL', 'Reorganised the site tree successfully.'))
rawurlencode(_t(__CLASS__.'.REORGANISATIONSUCCESSFUL', 'Reorganised the site tree successfully.') ?? '')
);
}
@ -852,7 +852,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$this->getResponse()->addHeader(
'X-Status',
rawurlencode(_t(__CLASS__.'.REORGANISATIONSUCCESSFUL', 'Reorganised the site tree successfully.'))
rawurlencode(_t(__CLASS__.'.REORGANISATIONSUCCESSFUL', 'Reorganised the site tree successfully.') ?? '')
);
}
@ -923,7 +923,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$searchParams = array_combine(array_map(function ($key) {
return 'Search__' . $key;
}, array_keys($searchParams)), $searchParams);
}, array_keys($searchParams ?? [])), $searchParams ?? []);
$schema = [
'formSchemaUrl' => $schemaUrl,
@ -1082,7 +1082,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// Add all ancestors
$ancestors = $record->getAncestors();
$ancestors = new ArrayList(array_reverse($ancestors->toArray()));
$ancestors = new ArrayList(array_reverse($ancestors->toArray() ?? []));
$ancestors->push($record);
/** @var SiteTree $ancestor */
foreach ($ancestors as $ancestor) {
@ -1144,7 +1144,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// Check if can be created at the root
$needsPerm = $obj->config()->get('need_permission');
if (!$obj->config()->get('can_be_root')
|| (!array_key_exists($class, $canCreate) || !$canCreate[$class])
|| (!array_key_exists($class, $canCreate ?? []) || !$canCreate[$class])
|| ($needsPerm && !$this->can($needsPerm))
) {
$def['Root']['disallowedChildren'][] = $class;
@ -1226,7 +1226,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
if ($id instanceof $treeClass) {
return $id;
}
if (substr($id, 0, 3) == 'new') {
if (substr($id ?? '', 0, 3) == 'new') {
return $this->getNewItem($id);
}
if (!is_numeric($id)) {
@ -1459,18 +1459,18 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// Count number of affected change set
$affectedChangeSetCount = 0;
if (count($inChangeSetIDs) > 0) {
if (count($inChangeSetIDs ?? []) > 0) {
$affectedChangeSetCount = ChangeSet::get()
->filter(['ID' => $inChangeSetIDs, 'State' => ChangeSet::STATE_OPEN])
->count();
}
$numCampaigns = ChangeSet::singleton()->i18n_pluralise($affectedChangeSetCount);
$numCampaigns = mb_strtolower($numCampaigns);
$numCampaigns = mb_strtolower($numCampaigns ?? '');
if (count($descendants) > 0 && $affectedChangeSetCount > 0) {
if (count($descendants ?? []) > 0 && $affectedChangeSetCount > 0) {
$archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithChildrenAndCampaigns', 'Warning: This page and all of its child pages will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?', [ 'NumCampaigns' => $numCampaigns ]);
} elseif (count($descendants) > 0) {
} elseif (count($descendants ?? []) > 0) {
$archiveWarningMsg = $defaultMessage;
} elseif ($affectedChangeSetCount > 0) {
$archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithCampaigns', 'Warning: This page will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?', [ 'NumCampaigns' => $numCampaigns ]);
@ -1693,9 +1693,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
);
$breadcrumbs = $item->Breadcrumbs(20, true, false, true, '/');
// Remove item's tile
$breadcrumbs = preg_replace('/[^\/]+$/', '', trim($breadcrumbs));
$breadcrumbs = preg_replace('/[^\/]+$/', '', trim($breadcrumbs ?? ''));
// Trim spaces around delimiters
$breadcrumbs = preg_replace('/\s?\/\s?/', '/', trim($breadcrumbs));
$breadcrumbs = preg_replace('/\s?\/\s?/', '/', trim($breadcrumbs ?? ''));
return $title . sprintf('<p class="small cms-list__item-breadcrumbs">%s</p>', $breadcrumbs);
}
]);
@ -1752,7 +1752,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// Existing or new record?
$id = $data['ID'];
if (substr($id, 0, 3) != 'new') {
if (substr($id ?? '', 0, 3) != 'new') {
/** @var SiteTree $record */
$record = DataObject::get_by_id($className, $id);
// Check edit permissions
@ -1810,7 +1810,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
);
}
$this->getResponse()->addHeader('X-Status', rawurlencode($message));
$this->getResponse()->addHeader('X-Status', rawurlencode($message ?? ''));
return $this->getResponseNegotiator()->respond($this->getRequest());
}
@ -1825,9 +1825,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
public function getNewItem($id, $setID = true)
{
$parentClass = $this->config()->get('tree_class');
list(, $className, $parentID) = array_pad(explode('-', $id), 3, null);
list(, $className, $parentID) = array_pad(explode('-', $id ?? ''), 3, null);
if (!is_a($className, $parentClass, true)) {
if (!is_a($className, $parentClass ?? '', true)) {
$response = Security::permissionFailure($this);
if (!$response) {
$response = $this->getResponse();
@ -1931,7 +1931,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
"Restored '{title}' successfully",
'Param {title} is a title',
['title' => $record->Title]
))
) ?? '')
);
return $this->getResponseNegotiator()->respond($this->getRequest());
@ -1967,7 +1967,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
__CLASS__ . '.REMOVEDPAGEFROMDRAFT',
"Removed '{title}' from the draft site",
['title' => $record->Title]
))
) ?? '')
);
// Even if the record has been deleted from stage and live, it can be viewed in "archive mode"
@ -2003,7 +2003,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
__CLASS__ . '.ARCHIVEDPAGE',
"Archived page '{title}'",
['title' => $record->Title]
))
) ?? '')
);
// Even if the record has been deleted from stage and live, it can be viewed in "archive mode"
@ -2038,7 +2038,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
__CLASS__ . '.REMOVEDPAGE',
"Removed '{title}' from the published site",
['title' => $record->Title]
))
) ?? '')
);
return $this->getResponseNegotiator()->respond($this->getRequest());
@ -2091,7 +2091,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
);
}
$this->getResponse()->addHeader('X-Status', rawurlencode($message));
$this->getResponse()->addHeader('X-Status', rawurlencode($message ?? ''));
// Can be used in different contexts: In normal page edit view, in which case the redirect won't have any effect.
// Or in history view, in which case a revert causes the CMS to re-load the edit view.
@ -2242,7 +2242,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
__CLASS__ . '.RESTORED',
"Restored '{title}' successfully",
['title' => $restoredPage->Title]
))
) ?? '')
);
return $this->getResponseNegotiator()->respond($this->getRequest());
@ -2280,7 +2280,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
__CLASS__ . '.DUPLICATED',
"Duplicated '{title}' successfully",
['title' => $newPage->Title]
))
) ?? '')
);
$url = $newPage->CMSEditLink();
$this->getResponse()->addHeader('X-ControllerURL', $url);
@ -2318,7 +2318,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
__CLASS__ . '.DUPLICATEDWITHCHILDREN',
"Duplicated '{title}' and children successfully",
['title' => $newPage->Title]
))
) ?? '')
);
$url = $newPage->CMSEditLink();
$this->getResponse()->addHeader('X-ControllerURL', $url);
@ -2370,7 +2370,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$this->extend('updateHintsCacheKey', $baseKey);
return md5($baseKey);
return md5($baseKey ?? '');
}
/**

View File

@ -112,7 +112,7 @@ class CMSPageAddController extends CMSPageEditController
"PageType",
DBField::create_field(
'HTMLFragment',
sprintf($numericLabelTmpl, 2, _t('SilverStripe\\CMS\\Controllers\\CMSMain.ChoosePageType', 'Choose page type'))
sprintf($numericLabelTmpl ?? '', 2, _t('SilverStripe\\CMS\\Controllers\\CMSMain.ChoosePageType', 'Choose page type'))
),
$pageTypes,
'Page'
@ -121,7 +121,7 @@ class CMSPageAddController extends CMSPageEditController
$parentModeField->setTitle(DBField::create_field(
'HTMLFragment',
sprintf($numericLabelTmpl, 1, _t('SilverStripe\\CMS\\Controllers\\CMSMain.ChoosePageParentMode', 'Choose where to create this page'))
sprintf($numericLabelTmpl ?? '', 1, _t('SilverStripe\\CMS\\Controllers\\CMSMain.ChoosePageParentMode', 'Choose where to create this page'))
));
$parentField->setSearchFunction(function ($sourceObject, $labelField, $search) {

View File

@ -55,7 +55,7 @@ class CMSPagesController extends CMSMain
$params['ParentID'] = $page->ID;
$item = new stdClass();
$item->Title = $page->Title;
$item->Link = Controller::join_links($this->Link(), '?' . http_build_query($params));
$item->Link = Controller::join_links($this->Link(), '?' . http_build_query($params ?? []));
$items->push(new ArrayData($item));
}
}

View File

@ -90,7 +90,7 @@ abstract class CMSSiteTreeFilter implements LeftAndMain_SearchFilter
uasort($filterMap, function ($a, $b) {
return ($a === CMSSiteTreeFilter_Search::title())
? -1
: strcasecmp($a, $b);
: strcasecmp($a ?? '', $b ?? '');
});
return $filterMap;
@ -164,7 +164,7 @@ abstract class CMSSiteTreeFilter implements LeftAndMain_SearchFilter
while (!empty($parents)) {
$q = Versioned::get_including_deleted(SiteTree::class)
->byIDs(array_keys($parents));
->byIDs(array_keys($parents ?? []));
$list = $q->map('ID', 'ParentID');
$parents = [];
foreach ($list as $id => $parentID) {

View File

@ -156,7 +156,7 @@ class ContentController extends Controller
$getVars = $_GET;
unset($getVars['url']);
if ($getVars) {
$url = "?" . http_build_query($getVars);
$url = "?" . http_build_query($getVars ?? []);
} else {
$url = "";
}
@ -494,7 +494,7 @@ HTML;
// TODO Allow this to work when allow_url_fopen=0
if (isset($_SESSION['StatsID']) && $_SESSION['StatsID']) {
$url = 'http://ss2stat.silverstripe.com/Installation/installed?ID=' . $_SESSION['StatsID'];
@file_get_contents($url);
@file_get_contents($url ?? '');
}
global $project;
@ -532,11 +532,11 @@ HTML;
$unsuccessful = new ArrayList();
foreach ($installfiles as $installfile) {
$installfilepath = PUBLIC_PATH . '/' . $installfile;
if (file_exists($installfilepath)) {
@unlink($installfilepath);
if (file_exists($installfilepath ?? '')) {
@unlink($installfilepath ?? '');
}
if (file_exists($installfilepath)) {
if (file_exists($installfilepath ?? '')) {
$unsuccessful->push(new ArrayData(['File' => $installfile]));
}
}

View File

@ -41,8 +41,8 @@ class ModelAsController extends Controller implements NestedController
{
$controller = $sitetree->getControllerName();
if ($action && class_exists($controller . '_' . ucfirst($action))) {
$controller = $controller . '_' . ucfirst($action);
if ($action && class_exists($controller . '_' . ucfirst($action ?? ''))) {
$controller = $controller . '_' . ucfirst($action ?? '');
}
return Injector::inst()->create($controller, $sitetree);
@ -131,7 +131,7 @@ class ModelAsController extends Controller implements NestedController
// url encode unless it's multibyte (already pre-encoded in the database)
$filter = URLSegmentFilter::create();
if (!$filter->getAllowMultibyte()) {
$URLSegment = rawurlencode($URLSegment);
$URLSegment = rawurlencode($URLSegment ?? '');
}
// Select child page

View File

@ -23,8 +23,8 @@ class OldPageRedirector extends Extension
public function onBeforeHTTPError404($request)
{
// We need to get the URL ourselves because $request->allParams() only has a max of 4 params
$params = preg_split('|/+|', $request->getURL());
$cleanURL = trim(Director::makeRelative($request->getURL(false)), '/');
$params = preg_split('|/+|', $request->getURL() ?? '');
$cleanURL = trim(Director::makeRelative($request->getURL(false)) ?? '', '/');
$getvars = $request->getVars();
unset($getvars['url']);
@ -33,7 +33,7 @@ class OldPageRedirector extends Extension
if (!$page) {
$page = self::find_old_page($params);
}
$cleanPage = trim(Director::makeRelative($page), '/');
$cleanPage = trim(Director::makeRelative($page) ?? '', '/');
if (!$cleanPage) {
$cleanPage = Director::makeRelative(RootURLController::get_homepage_link());
}
@ -64,7 +64,7 @@ class OldPageRedirector extends Extension
{
$parent = is_numeric($parent) && $parent > 0 ? SiteTree::get()->byID($parent) : $parent;
$params = (array)$params;
$URL = rawurlencode(array_shift($params));
$URL = rawurlencode(array_shift($params) ?? '');
if (empty($URL)) {
return false;
}
@ -93,7 +93,7 @@ class OldPageRedirector extends Extension
}
if ($page && $page->canView()) {
if (count($params)) {
if (count($params ?? [])) {
// We have to go deeper!
$ret = self::find_old_page($params, $page, $redirect);
if ($ret) {

View File

@ -56,7 +56,7 @@ class RootURLController extends Controller implements Resettable
*/
public static function should_be_on_root(SiteTree $page)
{
return (!self::$is_at_root && self::get_homepage_link() == trim($page->RelativeLink(true), '/'));
return (!self::$is_at_root && self::get_homepage_link() == trim($page->RelativeLink(true) ?? '', '/'));
}
/**

View File

@ -67,7 +67,7 @@ class SilverStripeNavigator extends ViewableData
ksort($items);
// Drop the keys and let the ArrayList handle the numbering, so $First, $Last and others work properly.
return new ArrayList(array_values($items));
return new ArrayList(array_values($items ?? []));
}
/**

View File

@ -20,7 +20,7 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem
$linkTitle = _t('SilverStripe\\CMS\\Controllers\\ContentController.ARCHIVEDSITE', 'Preview version');
$recordLink = Convert::raw2att(Controller::join_links(
$this->record->AbsoluteLink(),
'?archiveDate=' . urlencode($this->record->LastEdited)
'?archiveDate=' . urlencode($this->record->LastEdited ?? '')
));
return "<a class=\"{$linkClass}\" href=\"$recordLink\" target=\"_blank\">$linkTitle</a>";
}
@ -48,7 +48,7 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem
{
return Controller::join_links(
$this->record->PreviewLink(),
'?archiveDate=' . urlencode($this->record->LastEdited)
'?archiveDate=' . urlencode($this->record->LastEdited ?? '')
);
}

View File

@ -44,7 +44,7 @@ class SiteTreeURLSegmentField extends TextField
public function Value()
{
return rawurldecode($this->value);
return rawurldecode($this->value ?? '');
}
public function getAttributes()
@ -82,7 +82,7 @@ class SiteTreeURLSegmentField extends TextField
$page->URLSegment = $page->generateURLSegment($request->getVar('value'));
$count = 2;
while (!$page->validURLSegment()) {
$page->URLSegment = preg_replace('/-[0-9]+$/', '', $page->URLSegment) . '-' . $count;
$page->URLSegment = preg_replace('/-[0-9]+$/', '', $page->URLSegment ?? '') . '-' . $count;
$count++;
}

View File

@ -173,8 +173,8 @@ class RedirectorPage extends Page
{
parent::onBeforeWrite();
if ($this->ExternalURL && substr($this->ExternalURL, 0, 2) !== '//') {
$urlParts = parse_url($this->ExternalURL);
if ($this->ExternalURL && substr($this->ExternalURL ?? '', 0, 2) !== '//') {
$urlParts = parse_url($this->ExternalURL ?? '');
if ($urlParts) {
if (empty($urlParts['scheme'])) {
// no scheme, assume http

View File

@ -430,16 +430,16 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$urlSegmentExpr = sprintf('"%s"."URLSegment"', $tableName);
$parentIDExpr = sprintf('"%s"."ParentID"', $tableName);
$link = trim(Director::makeRelative($link), '/');
$link = trim(Director::makeRelative($link) ?? '', '/');
if (!$link) {
$link = RootURLController::get_homepage_link();
}
$parts = preg_split('|/+|', $link);
$parts = preg_split('|/+|', $link ?? '');
// Grab the initial root level page to traverse down from.
$URLSegment = array_shift($parts);
$conditions = [$urlSegmentExpr => rawurlencode($URLSegment)];
$conditions = [$urlSegmentExpr => rawurlencode($URLSegment ?? '')];
if (self::config()->get('nested_urls')) {
$conditions[] = [$parentIDExpr => 0];
}
@ -474,7 +474,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
}
// Check if we have any more URL parts to parse.
if (!self::config()->get('nested_urls') || !count($parts)) {
if (!self::config()->get('nested_urls') || !count($parts ?? [])) {
return $sitetree;
}
@ -521,7 +521,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
{
$classes = ClassInfo::getValidSubClasses();
$baseClassIndex = array_search(self::class, $classes);
$baseClassIndex = array_search(self::class, $classes ?? []);
if ($baseClassIndex !== false) {
unset($classes[$baseClassIndex]);
}
@ -542,10 +542,10 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
// If any of the descendents don't want any of the elders to show up, cruelly render the elders surplus to
// requirements
if ($kill_ancestors) {
$kill_ancestors = array_unique($kill_ancestors);
$kill_ancestors = array_unique($kill_ancestors ?? []);
foreach ($kill_ancestors as $mark) {
// unset from $classes
$idx = array_search($mark, $classes, true);
$idx = array_search($mark, $classes ?? [], true);
if ($idx !== false) {
unset($classes[$idx]);
}
@ -733,7 +733,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
*/
public function ElementName()
{
return str_replace('/', '-', trim($this->RelativeLink(true), '/'));
return str_replace('/', '-', trim($this->RelativeLink(true) ?? '', '/'));
}
/**
@ -762,7 +762,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
public function isSection()
{
return $this->isCurrent() || (
Director::get_current_page() instanceof SiteTree && in_array($this->ID, Director::get_current_page()->getAncestors()->column())
Director::get_current_page() instanceof SiteTree && in_array($this->ID, Director::get_current_page()->getAncestors()->column() ?? [])
);
}
@ -931,7 +931,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
while ($page
&& $page->exists()
&& (!$maxDepth || count($pages) < $maxDepth)
&& (!$maxDepth || count($pages ?? []) < $maxDepth)
&& (!$stopAtPageType || $page->ClassName != $stopAtPageType)
) {
if ($showHidden || $page->ShowInMenus || ($page->ID == $this->ID)) {
@ -941,7 +941,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$page = $page->Parent();
}
return new ArrayList(array_reverse($pages));
return new ArrayList(array_reverse($pages ?? []));
}
@ -1013,7 +1013,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$item = $item->getParent();
$level--;
}
return implode($separator, array_reverse($parts));
return implode($separator ?? '', array_reverse($parts ?? []));
}
/**
@ -1043,8 +1043,8 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
return true;
}
if (is_string($perm) && method_exists($this, 'can' . ucfirst($perm))) {
$method = 'can' . ucfirst($perm);
if (is_string($perm) && method_exists($this, 'can' . ucfirst($perm ?? ''))) {
$method = 'can' . ucfirst($perm ?? '');
return $this->$method($member);
}
@ -1266,7 +1266,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
// Block children not allowed for this parent type
$parent = isset($context['Parent']) ? $context['Parent'] : null;
$strictParentInstance = ($parent && $parent instanceof SiteTree);
if ($strictParentInstance && !in_array(static::class, $parent->allowedChildren())) {
if ($strictParentInstance && !in_array(static::class, $parent->allowedChildren() ?? [])) {
return false;
}
@ -1341,7 +1341,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
public function getSiteConfig()
{
$configs = $this->invokeWithExtensions('alternateSiteConfig');
foreach (array_filter($configs) as $config) {
foreach (array_filter($configs ?? []) as $config) {
return $config;
}
@ -1472,7 +1472,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
*/
private function getGenerator(): string
{
$generator = trim(Config::inst()->get(self::class, 'meta_generator'));
$generator = trim(Config::inst()->get(self::class, 'meta_generator') ?? '');
if ($generator === '') {
return '';
}
@ -1480,7 +1480,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$version = $this->getVersionProvider()->getModuleVersion('silverstripe/framework');
// Only include stable version numbers so as not to clutter any aggregate reports
// with non-standard versions e.g. forks
if (preg_match('#^([0-9]+\.[0-9]+)\.[0-9]+$#', $version, $m)) {
if (preg_match('#^([0-9]+\.[0-9]+)\.[0-9]+$#', $version ?? '', $m)) {
$generator .= ' ' . $m[1];
}
}
@ -1517,7 +1517,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
{
$tags = [];
$tagsArray = $this->MetaComponents();
if (!$includeTitle || strtolower($includeTitle) == 'false') {
if (!$includeTitle || strtolower($includeTitle ?? '') == 'false') {
unset($tagsArray['title']);
}
@ -1652,19 +1652,19 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
// Ensure that this object has a non-conflicting URLSegment value.
$count = 2;
while (!$this->validURLSegment()) {
$this->URLSegment = preg_replace('/-[0-9]+$/', '', $this->URLSegment) . '-' . $count;
$this->URLSegment = preg_replace('/-[0-9]+$/', '', $this->URLSegment ?? '') . '-' . $count;
$count++;
}
// Check to see if we've only altered fields that shouldn't affect versioning
$fieldsIgnoredByVersioning = ['HasBrokenLink', 'Status', 'HasBrokenFile', 'ToDo', 'VersionID', 'SaveCount'];
$changedFields = array_keys($this->getChangedFields(true, 2));
$changedFields = array_keys($this->getChangedFields(true, 2) ?? []);
// This more rigorous check is inline with the test that write() does to decide whether or not to write to the
// DB. We use that to avoid cluttering the system with a migrateVersion() call that doesn't get used
$oneChangedFields = array_keys($this->getChangedFields(true, 1));
$oneChangedFields = array_keys($this->getChangedFields(true, 1) ?? []);
if ($oneChangedFields && !array_diff($changedFields, $fieldsIgnoredByVersioning)) {
if ($oneChangedFields && !array_diff($changedFields ?? [], $fieldsIgnoredByVersioning)) {
$this->setNextWriteWithoutVersion(true);
}
@ -1755,7 +1755,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$subject = ($this instanceof VirtualPage && $this->CopyContentFromID)
? $this->CopyContentFrom()
: $this;
if (!in_array($subject->ClassName, $allowed)) {
if (!in_array($subject->ClassName, $allowed ?? [])) {
$result->addError(
_t(
'SilverStripe\\CMS\\Model\\SiteTree.PageTypeNotAllowed',
@ -1804,7 +1804,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
return false;
}
}
} elseif (in_array(strtolower($this->URLSegment), $this->getExcludedURLSegments())) {
} elseif (in_array(strtolower($this->URLSegment ?? ''), $this->getExcludedURLSegments() ?? [])) {
// Guard against url segments for the base page
// Default to '-2', onBeforeWrite takes care of further possible clashes
return false;
@ -2276,7 +2276,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$viewerGroupsField->setDescription(_t(
'SilverStripe\\CMS\\Model\\SiteTree.VIEWER_GROUPS_FIELD_DESC',
'Groups with global view permissions: {groupList}',
['groupList' => implode(', ', array_values($viewAllGroupsMap))]
['groupList' => implode(', ', array_values($viewAllGroupsMap ?? []))]
));
}
@ -2284,7 +2284,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$editorGroupsField->setDescription(_t(
'SilverStripe\\CMS\\Model\\SiteTree.EDITOR_GROUPS_FIELD_DESC',
'Groups with global edit permissions: {groupList}',
['groupList' => implode(', ', array_values($editAllGroupsMap))]
['groupList' => implode(', ', array_values($editAllGroupsMap ?? []))]
));
}
@ -2622,7 +2622,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
return false;
}
return stripos($this->ID, 'new') === 0;
return stripos($this->ID ?? '', 'new') === 0;
}
/**
@ -2673,9 +2673,9 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
if ($currentClass) {
$currentPageTypeName = $result[$currentClass];
unset($result[$currentClass]);
$result = array_reverse($result);
$result = array_reverse($result ?? []);
$result[$currentClass] = $currentPageTypeName;
$result = array_reverse($result);
$result = array_reverse($result ?? []);
}
return $result;
@ -2699,7 +2699,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$candidates = Config::inst()->get($class, 'allowed_children', Config::UNINHERITED);
break;
}
$class = get_parent_class($class);
$class = get_parent_class($class ?? '');
}
if (!$candidates || $candidates === 'none' || $candidates === 'SiteTree_root') {
return [];
@ -2710,8 +2710,8 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
foreach ((array)$candidates as $candidate) {
// If a classname is prefixed by "*", such as "*Page", then only that class is allowed - no subclasses.
// Otherwise, the class and all its subclasses are allowed.
if (substr($candidate, 0, 1) == '*') {
$allowedChildren[] = substr($candidate, 1);
if (substr($candidate ?? '', 0, 1) == '*') {
$allowedChildren[] = substr($candidate ?? '', 1);
} elseif (($candidate !== 'SiteTree_root')
&& ($subclasses = ClassInfo::subclassesFor($candidate))
) {
@ -2802,7 +2802,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$default = $this->config()->get('default_child');
$allowed = $this->allowedChildren();
if ($allowed) {
if (!$default || !in_array($default, $allowed)) {
if (!$default || !in_array($default, $allowed ?? [])) {
$default = reset($allowed);
}
return $default;
@ -2929,7 +2929,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
Convert::raw2htmlid(static::class),
$this->isHomePage() ? ' homepage' : '',
Convert::raw2att(json_encode($children)),
Convert::raw2xml(str_replace(["\n","\r"], "", $this->MenuTitle))
Convert::raw2xml(str_replace(["\n","\r"], "", $this->MenuTitle ?? ''))
);
foreach ($flags as $class => $data) {
if (is_string($data)) {
@ -3143,7 +3143,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
if (!$icon) {
return null;
}
if (strpos($icon, 'data:image/') !== false) {
if (strpos($icon ?? '', 'data:image/') !== false) {
return $icon;
}
@ -3284,15 +3284,15 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
// Build from rules
foreach (Director::config()->get('rules') as $pattern => $rule) {
$route = explode('/', $pattern);
if (!empty($route) && strpos($route[0], '$') === false) {
$excludes[] = strtolower($route[0]);
$route = explode('/', $pattern ?? '');
if (!empty($route) && strpos($route[0] ?? '', '$') === false) {
$excludes[] = strtolower($route[0] ?? '');
}
}
// Build from base folders
foreach (glob(Director::publicFolder() . '/*', GLOB_ONLYDIR) as $folder) {
$excludes[] = strtolower(basename($folder));
$excludes[] = strtolower(basename($folder ?? ''));
}
$this->extend('updateExcludedURLSegments', $excludes);
@ -3306,7 +3306,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
{
$parseSuccess = preg_match_all(
"/\\s+(name|id)\\s*=\\s*([\"'])([^\\2\\s>]*?)\\2|\\s+(name|id)\\s*=\\s*([^\"']+)[\\s +>]/im",
$this->Content,
$this->Content ?? '',
$matches
);

View File

@ -41,7 +41,7 @@ class SiteTreeFolderExtension extends DataExtension
// Get all classes that aren't folder
$fileClasses = array_diff_key(
ClassInfo::subclassesFor(File::class),
ClassInfo::subclassesFor(File::class) ?? [],
ClassInfo::subclassesFor(Folder::class)
);
@ -58,7 +58,7 @@ class SiteTreeFolderExtension extends DataExtension
$where = [];
$columns = [];
foreach ($hasOnes as $relName => $joinClass) {
if (in_array($joinClass, $fileClasses)) {
if (in_array($joinClass, $fileClasses ?? [])) {
$column = $relName . 'ID';
$columns[] = $column;
$quotedColumn = $schema->sqlColumnForField($className, $column);

View File

@ -190,13 +190,13 @@ class SiteTreeLinkTracking extends DataExtension
protected function toggleElementClass(DOMElement $domReference, $class, $toggle)
{
// Get all existing classes.
$classes = array_filter(explode(' ', trim($domReference->getAttribute('class'))));
$classes = array_filter(explode(' ', trim($domReference->getAttribute('class') ?? '')));
// Add or remove the broken class from the link, depending on the link status.
if ($toggle) {
$classes = array_unique(array_merge($classes, [$class]));
} else {
$classes = array_diff($classes, [$class]);
$classes = array_diff($classes ?? [], [$class]);
}
if (!empty($classes)) {

View File

@ -59,7 +59,7 @@ class SiteTreeLinkTracking_Parser
// Link to a page on this site.
$matches = [];
if (preg_match('/\[sitetree_link(?:\s*|%20|,)?id=(?<id>[0-9]+)\](#(?<anchor>.*))?/i', $href, $matches)) {
if (preg_match('/\[sitetree_link(?:\s*|%20|,)?id=(?<id>[0-9]+)\](#(?<anchor>.*))?/i', $href ?? '', $matches)) {
// Check if page link is broken
/** @var SiteTree $page */
$page = DataObject::get_by_id(SiteTree::class, $matches['id']);
@ -68,7 +68,7 @@ class SiteTreeLinkTracking_Parser
$broken = true;
} elseif (!empty($matches['anchor'])) {
// Ensure anchor isn't broken on target page
$broken = !in_array($matches['anchor'], $page->getAnchorsOnPage());
$broken = !in_array($matches['anchor'], $page->getAnchorsOnPage() ?? []);
} else {
$broken = false;
}
@ -85,14 +85,14 @@ class SiteTreeLinkTracking_Parser
}
// Local anchor.
if (preg_match('/^#(.*)/i', $href, $matches)) {
$anchor = preg_quote($matches[1], '#');
if (preg_match('/^#(.*)/i', $href ?? '', $matches)) {
$anchor = preg_quote($matches[1] ?? '', '#');
$results[] = [
'Type' => 'localanchor',
'Target' => null,
'Anchor' => $matches[1],
'DOMReference' => $link,
'Broken' => !preg_match("#(name|id)=\"{$anchor}\"#", $htmlValue->getContent())
'Broken' => !preg_match("#(name|id)=\"{$anchor}\"#", $htmlValue->getContent() ?? '')
];
continue;

View File

@ -96,9 +96,9 @@ class VirtualPage extends Page
}
// Diff db with non-virtual fields
$fields = array_keys(static::getSchema()->fieldSpecs($record));
$fields = array_keys(static::getSchema()->fieldSpecs($record) ?? []);
$nonVirtualFields = $this->getNonVirtualisedFields();
return array_diff($fields, $nonVirtualFields);
return array_diff($fields ?? [], $nonVirtualFields);
}
/**
@ -448,7 +448,7 @@ class VirtualPage extends Page
{
// Don't defer if field is non-virtualised
$ignore = $this->getNonVirtualisedFields();
if (in_array($field, $ignore)) {
if (in_array($field, $ignore ?? [])) {
return false;
}
@ -474,7 +474,7 @@ class VirtualPage extends Page
if (parent::hasMethod($method)) {
return parent::__call($method, $args);
} else {
return call_user_func_array([$this->CopyContentFrom(), $method], $args);
return call_user_func_array([$this->CopyContentFrom(), $method], $args ?? []);
}
}

View File

@ -29,7 +29,7 @@ class BrokenFilesReport extends Report
{
// Get class names for page types that are not virtual pages or redirector pages
$classes = array_diff(
ClassInfo::subclassesFor(SiteTree::class),
ClassInfo::subclassesFor(SiteTree::class) ?? [],
ClassInfo::subclassesFor(VirtualPage::class),
ClassInfo::subclassesFor(RedirectorPage::class)
);

View File

@ -33,7 +33,7 @@ class BrokenLinksReport extends Report
$join = '';
$sortBrokenReason = false;
if ($sort) {
$parts = explode(' ', $sort);
$parts = explode(' ', $sort ?? '');
$field = $parts[0];
$direction = $parts[1];
@ -93,7 +93,7 @@ class BrokenLinksReport extends Report
}
if ($reason) {
if (isset($params['Reason']) && $params['Reason'] && !in_array($params['Reason'], $reasonCodes)) {
if (isset($params['Reason']) && $params['Reason'] && !in_array($params['Reason'], $reasonCodes ?? [])) {
continue;
}
$record->BrokenReason = $reason;

View File

@ -98,14 +98,14 @@ class SearchForm extends Form
public function classesToSearch($classes)
{
$supportedClasses = [SiteTree::class, File::class];
$illegalClasses = array_diff($classes, $supportedClasses);
$illegalClasses = array_diff($classes ?? [], $supportedClasses);
if ($illegalClasses) {
throw new BadMethodCallException(
"SearchForm::classesToSearch() passed illegal classes '" . implode("', '", $illegalClasses)
. "'. At this stage, only File and SiteTree are allowed"
);
}
$legalClasses = array_intersect($classes, $supportedClasses);
$legalClasses = array_intersect($classes ?? [], $supportedClasses);
$this->classesToSearch = $legalClasses;
}
@ -155,10 +155,10 @@ class SearchForm extends Form
return ' -' . $matches[3];
};
$keywords = preg_replace_callback('/()("[^()"]+")( and )("[^"()]+")()/i', $andProcessor, $keywords);
$keywords = preg_replace_callback('/(^| )([^() ]+)( and )([^ ()]+)( |$)/i', $andProcessor, $keywords);
$keywords = preg_replace_callback('/(^| )(not )("[^"()]+")/i', $notProcessor, $keywords);
$keywords = preg_replace_callback('/(^| )(not )([^() ]+)( |$)/i', $notProcessor, $keywords);
$keywords = preg_replace_callback('/()("[^()"]+")( and )("[^"()]+")()/i', $andProcessor, $keywords ?? '');
$keywords = preg_replace_callback('/(^| )([^() ]+)( and )([^ ()]+)( |$)/i', $andProcessor, $keywords ?? '');
$keywords = preg_replace_callback('/(^| )(not )("[^"()]+")/i', $notProcessor, $keywords ?? '');
$keywords = preg_replace_callback('/(^| )(not )([^() ]+)( |$)/i', $notProcessor, $keywords ?? '');
$keywords = $this->addStarsToKeywords($keywords);
@ -166,10 +166,10 @@ class SearchForm extends Form
$start = max(0, (int)$request->requestVar('start'));
$booleanSearch =
strpos($keywords, '"') !== false ||
strpos($keywords, '+') !== false ||
strpos($keywords, '-') !== false ||
strpos($keywords, '*') !== false;
strpos($keywords ?? '', '"') !== false ||
strpos($keywords ?? '', '+') !== false ||
strpos($keywords ?? '', '-') !== false ||
strpos($keywords ?? '', '*') !== false;
$results = DB::get_conn()->searchEngine($this->classesToSearch, $keywords, $start, $pageLength, "\"Relevance\" DESC", "", $booleanSearch);
// filter by permission
@ -197,19 +197,19 @@ class SearchForm extends Form
protected function addStarsToKeywords($keywords)
{
if (!trim($keywords)) {
if (!trim($keywords ?? '')) {
return "";
}
// Add * to each keyword
$splitWords = preg_split("/ +/", trim($keywords));
$splitWords = preg_split("/ +/", trim($keywords ?? ''));
$newWords = [];
for ($i = 0; $i < count($splitWords); $i++) {
for ($i = 0; $i < count($splitWords ?? []); $i++) {
$word = $splitWords[$i];
if ($word[0] == '"') {
while (++$i < count($splitWords)) {
while (++$i < count($splitWords ?? [])) {
$subword = $splitWords[$i];
$word .= ' ' . $subword;
if (substr($subword, -1) == '"') {
if (substr($subword ?? '', -1) == '"') {
break;
}
}

View File

@ -25,7 +25,7 @@ class LoginContext extends BehatLoginContext
$email = "{$permCode}@example.org";
$password = 'Password!456';
$member = $this->generateMemberWithPermission($email, $password, $permCode);
$canEdit = strstr($negative, 'not') ? false : true;
$canEdit = strstr($negative ?? '', 'not') ? false : true;
if ($canEdit) {
Assert::assertTrue($page->canEdit($member), 'The member can edit this page');

View File

@ -23,7 +23,7 @@ class ThemeContext implements Context
*/
public function stepCreateTheme($theme)
{
if (!preg_match('/^[0-9a-zA-Z_-]+$/', $theme)) {
if (!preg_match('/^[0-9a-zA-Z_-]+$/', $theme ?? '')) {
throw new \InvalidArgumentException("Bad theme '$theme'");
}
@ -42,10 +42,10 @@ class ThemeContext implements Context
*/
public function stepCreateTemplate($template, $theme, $content)
{
if (!preg_match('/^[0-9a-zA-Z_-]+$/', $theme)) {
if (!preg_match('/^[0-9a-zA-Z_-]+$/', $theme ?? '')) {
throw new \InvalidArgumentException("Bad theme '$theme'");
}
if (!preg_match('/^(Layout\/)?[0-9a-zA-Z_-]+\.ss$/', $template)) {
if (!preg_match('/^(Layout\/)?[0-9a-zA-Z_-]+\.ss$/', $template ?? '')) {
throw new \InvalidArgumentException("Bad template '$template'");
}
@ -56,16 +56,16 @@ class ThemeContext implements Context
protected function requireFile($filename, $content)
{
// Already exists
if (file_exists($filename)) {
if (file_exists($filename ?? '')) {
// If the content is different, remember old content for restoration
$origContent = file_get_contents($filename);
$origContent = file_get_contents($filename ?? '');
if ($origContent != $content) {
file_put_contents($filename, $content);
file_put_contents($filename ?? '', $content);
$this->restoreFiles[$filename] = $origContent;
}
// Doesn't exist, mark it for deletion after test
} else {
file_put_contents($filename, $content);
file_put_contents($filename ?? '', $content);
$this->restoreFiles[$filename] = null;
}
}
@ -73,8 +73,8 @@ class ThemeContext implements Context
protected function requireDir($dirname)
{
// Directory doesn't exist, create it and mark it for deletion
if (!file_exists($dirname)) {
mkdir($dirname);
if (!file_exists($dirname ?? '')) {
mkdir($dirname ?? '');
$this->restoreDirectories[] = $dirname;
}
}
@ -92,9 +92,9 @@ class ThemeContext implements Context
if ($this->restoreFiles) {
foreach ($this->restoreFiles as $file => $origContent) {
if ($origContent === null) {
unlink($file);
unlink($file ?? '');
} else {
file_put_contents($file, $origContent);
file_put_contents($file ?? '', $origContent);
}
}
@ -104,9 +104,9 @@ class ThemeContext implements Context
// Restore any created directories: that is, delete them
if ($this->restoreDirectories) {
// Flip the order so that nested direcotires are unlinked() first
$this->restoreDirectories = array_reverse($this->restoreDirectories);
$this->restoreDirectories = array_reverse($this->restoreDirectories ?? []);
foreach ($this->restoreDirectories as $dir) {
rmdir($dir);
rmdir($dir ?? '');
}
$this->restoreDirectories = [];

View File

@ -6,8 +6,8 @@ if (defined('BASE_PATH')) {
} else {
$projectPath = getcwd() . '/app';
}
if (!is_dir($projectPath)) {
mkdir($projectPath, 02775);
if (!is_dir($projectPath ?? '')) {
mkdir($projectPath ?? '', 02775);
mkdir($projectPath . '/code', 02775);
mkdir($projectPath . '/_config', 02775);
copy(__DIR__ . '/fixtures/Page.php.fixture', $projectPath . '/code/Page.php');

View File

@ -142,7 +142,7 @@ class CMSBatchActionsTest extends SapphireTest
$this->assertEquals($archivedID, $list->first()->ParentID);
// Run restore
$result = json_decode($action->run($list), true);
$result = json_decode($action->run($list) ?? '', true);
$this->assertEquals(
[
$archivedxID => $archivedxID
@ -162,7 +162,7 @@ class CMSBatchActionsTest extends SapphireTest
$this->assertEquals(0, $list->last()->ParentID); // archived (parent)
// Run restore
$result = json_decode($action->run($list), true);
$result = json_decode($action->run($list) ?? '', true);
$this->assertEquals(
[
// Order of archived is opposite to order items are passed in, as

View File

@ -56,8 +56,8 @@ class CMSMainTest extends FunctionalTest
$rawHints = singleton(CMSMain::class)->SiteTreeHints();
$this->assertNotNull($rawHints);
$rawHints = preg_replace('/^"(.*)"$/', '$1', Convert::xml2raw($rawHints));
$hints = json_decode($rawHints, true);
$rawHints = preg_replace('/^"(.*)"$/', '$1', Convert::xml2raw($rawHints) ?? '');
$hints = json_decode($rawHints ?? '', true);
$this->assertArrayHasKey('Root', $hints);
$this->assertArrayHasKey('Page', $hints);
@ -100,7 +100,7 @@ class CMSMainTest extends FunctionalTest
// Check query
$response = $this->get('admin/pages/childfilter?ParentID=' . $pageA->ID);
$children = json_decode($response->getBody());
$children = json_decode($response->getBody() ?? '');
$this->assertFalse($response->isError());
// Page A can't have unrelated children
@ -137,7 +137,7 @@ class CMSMainTest extends FunctionalTest
$actions = CMSBatchActionHandler::config()->batch_actions;
if (isset($actions['publish'])) {
$response = $this->get('admin/pages/batchactions/publish?ajax=1&csvIDs=' . implode(',', [$page1->ID, $page2->ID]));
$responseData = json_decode($response->getBody(), true);
$responseData = json_decode($response->getBody() ?? '', true);
$this->assertArrayHasKey($page1->ID, $responseData['modified']);
$this->assertArrayHasKey($page2->ID, $responseData['modified']);
}
@ -335,7 +335,7 @@ class CMSMainTest extends FunctionalTest
]
);
$this->assertFalse($response->isError());
$ok = preg_match('/edit\/show\/(\d*)/', $response->getHeader('X-ControllerURL'), $matches);
$ok = preg_match('/edit\/show\/(\d*)/', $response->getHeader('X-ControllerURL') ?? '', $matches);
$this->assertNotEmpty($ok);
$newPageId = $matches[1];
@ -360,7 +360,7 @@ class CMSMainTest extends FunctionalTest
// Verify that the page was created and redirected to accurately
$newerPage = SiteTree::get()->byID($newPageId)->AllChildren()->first();
$this->assertNotEmpty($newerPage);
$ok = preg_match('/edit\/show\/(\d*)/', $response->getHeader('X-ControllerURL'), $matches);
$ok = preg_match('/edit\/show\/(\d*)/', $response->getHeader('X-ControllerURL') ?? '', $matches);
$this->assertNotEmpty($ok);
$newerPageID = $matches[1];
$this->assertEquals($newerPage->ID, $newerPageID);
@ -398,7 +398,7 @@ class CMSMainTest extends FunctionalTest
$crumbs = $parser->getBySelector('.breadcrumbs-wrapper .crumb');
$this->assertNotNull($crumbs);
$this->assertEquals(2, count($crumbs));
$this->assertEquals(2, count($crumbs ?? []));
$this->assertEquals('Page 3', (string)$crumbs[0]);
$this->assertEquals('Page 3.1', (string)$crumbs[1]);

View File

@ -112,7 +112,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest
$form = $this->cssParser()->getBySelector('#Form_VersionsForm');
$this->assertEquals(1, count($form));
$this->assertEquals(1, count($form ?? []));
// check the page ID is present
$hidden = $form[0]->xpath("fieldset/input[@type='hidden']");
@ -122,7 +122,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest
// ensure that all the versions are present in the table and displayed
$rows = $form[0]->xpath("fieldset/table/tbody/tr");
$this->assertEquals(4, count($rows));
$this->assertEquals(4, count($rows ?? []));
}
public function testVersionsFormTableContainsInformation()

View File

@ -40,7 +40,7 @@ class CMSSiteTreeFilterTest extends SapphireTest
$this->assertTrue($f->isPageIncluded($page1));
$this->assertFalse($f->isPageIncluded($page2));
$this->assertEquals(1, count($results));
$this->assertEquals(1, count($results ?? []));
$this->assertEquals(
['ID' => $page1->ID, 'ParentID' => 0],
$results[0]
@ -68,7 +68,7 @@ class CMSSiteTreeFilterTest extends SapphireTest
$this->assertTrue($f->isPageIncluded($parent));
$this->assertTrue($f->isPageIncluded($child));
$this->assertEquals(1, count($results));
$this->assertEquals(1, count($results ?? []));
$this->assertEquals(
['ID' => $child->ID, 'ParentID' => $parent->ID],
$results[0]
@ -95,7 +95,7 @@ class CMSSiteTreeFilterTest extends SapphireTest
$this->assertTrue($f->isPageIncluded($changedPage));
$this->assertFalse($f->isPageIncluded($unchangedPage));
$this->assertEquals(1, count($results));
$this->assertEquals(1, count($results ?? []));
$this->assertEquals(
['ID' => $changedPage->ID, 'ParentID' => 0],
$results[0]
@ -104,7 +104,7 @@ class CMSSiteTreeFilterTest extends SapphireTest
// Check that only changed pages are returned
$f = new CMSSiteTreeFilter_ChangedPages(['Term' => 'No Matches']);
$results = $f->pagesIncluded();
$this->assertEquals(0, count($results));
$this->assertEquals(0, count($results ?? []));
// If we roll back to an earlier version than what's on the published site, we should still show the changed
$changedPage->Title = 'Changed 2';
@ -115,7 +115,7 @@ class CMSSiteTreeFilterTest extends SapphireTest
$f = new CMSSiteTreeFilter_ChangedPages(['Term' => 'Changed']);
$results = $f->pagesIncluded();
$this->assertEquals(1, count($results));
$this->assertEquals(1, count($results ?? []));
$this->assertEquals(['ID' => $changedPage->ID, 'ParentID' => 0], $results[0]);
}
@ -166,7 +166,7 @@ class CMSSiteTreeFilterTest extends SapphireTest
{
$draftPage = $this->objFromFixture('Page', 'page4');
// Grab the date
$date = substr($draftPage->LastEdited, 0, 10);
$date = substr($draftPage->LastEdited ?? '', 0, 10);
// Filter with that date
$filter = new CMSSiteTreeFilter_Search([
'LastEditedFrom' => $date,

View File

@ -98,7 +98,7 @@ class CMSTreeTest extends FunctionalTest
$result = $this->get('admin/pages/edit/updatetreenodes?ids='.$page1->ID);
$this->assertEquals(200, $result->getStatusCode());
$this->assertEquals('application/json', $result->getHeader('Content-Type'));
$data = json_decode($result->getBody(), true);
$data = json_decode($result->getBody() ?? '', true);
$pageData = $data[$page1->ID];
$this->assertEquals(0, $pageData['ParentID']);
$this->assertEquals($page2->ID, $pageData['NextID']);
@ -108,7 +108,7 @@ class CMSTreeTest extends FunctionalTest
$result = $this->get('admin/pages/edit/updatetreenodes?ids='.$page31->ID);
$this->assertEquals(200, $result->getStatusCode());
$this->assertEquals('application/json', $result->getHeader('Content-Type'));
$data = json_decode($result->getBody(), true);
$data = json_decode($result->getBody() ?? '', true);
$pageData = $data[$page31->ID];
$this->assertEquals($page3->ID, $pageData['ParentID']);
$this->assertEquals($page32->ID, $pageData['NextID']);
@ -118,14 +118,14 @@ class CMSTreeTest extends FunctionalTest
$result = $this->get('admin/pages/edit/updatetreenodes?ids='.$page1->ID.','.$page2->ID);
$this->assertEquals(200, $result->getStatusCode());
$this->assertEquals('application/json', $result->getHeader('Content-Type'));
$data = json_decode($result->getBody(), true);
$this->assertEquals(2, count($data));
$data = json_decode($result->getBody() ?? '', true);
$this->assertEquals(2, count($data ?? []));
// Invalid IDs
$result = $this->get('admin/pages/edit/updatetreenodes?ids=-3');
$this->assertEquals(200, $result->getStatusCode());
$this->assertEquals('application/json', $result->getHeader('Content-Type'));
$data = json_decode($result->getBody(), true);
$this->assertEquals(0, count($data));
$data = json_decode($result->getBody() ?? '', true);
$this->assertEquals(0, count($data ?? []));
}
}

View File

@ -172,7 +172,7 @@ class ContentControllerTest extends FunctionalTest
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$response = $this->get($page->RelativeLink());
$this->assertEquals("ContentControllerTestPageWithoutController", trim($response->getBody()));
$this->assertEquals("ContentControllerTestPageWithoutController", trim($response->getBody() ?? ''));
// // This should fall over to user Page.ss
$page = new ContentControllerTestPage();
@ -181,7 +181,7 @@ class ContentControllerTest extends FunctionalTest
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$response = $this->get($page->RelativeLink());
$this->assertEquals("Page", trim($response->getBody()));
$this->assertEquals("Page", trim($response->getBody() ?? ''));
// Test that the action template is rendered.
@ -191,12 +191,12 @@ class ContentControllerTest extends FunctionalTest
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$response = $this->get($page->RelativeLink("test"));
$this->assertEquals("ContentControllerTestPage_test", trim($response->getBody()));
$this->assertEquals("ContentControllerTestPage_test", trim($response->getBody() ?? ''));
// Test that an action without a template will default to the index template, which is
// to say the default Page.ss template
$response = $this->get($page->RelativeLink("testwithouttemplate"));
$this->assertEquals("Page", trim($response->getBody()));
$this->assertEquals("Page", trim($response->getBody() ?? ''));
// Test that an action with a template will render the both action template *and* the
// correct parent template

View File

@ -23,7 +23,7 @@ class SilverStripeNavigatorTest extends SapphireTest
$navigator = new SilverStripeNavigator($page);
$items = $navigator->getItems();
$classes = array_map('get_class', $items->toArray());
$classes = array_map('get_class', $items->toArray() ?? []);
$this->assertContains(
SilverStripeNavigatorItem_StageLink::class,
$classes,
@ -48,18 +48,18 @@ class SilverStripeNavigatorTest extends SapphireTest
// TODO Shouldn't be necessary but SapphireTest logs in as ADMIN by default
$this->logInWithPermission('CMS_ACCESS_CMSMain');
$items = $navigator->getItems();
$classes = array_map('get_class', $items->toArray());
$classes = array_map('get_class', $items->toArray() ?? []);
$this->assertNotContains(SilverStripeNavigatorTest_ProtectedTestItem::class, $classes);
$this->logInWithPermission('ADMIN');
$items = $navigator->getItems();
$classes = array_map('get_class', $items->toArray());
$classes = array_map('get_class', $items->toArray() ?? []);
$this->assertContains(SilverStripeNavigatorTest_ProtectedTestItem::class, $classes);
// Unversioned record shouldn't be viewable in stage / live specific views
$unversioned = new SilverStripeNavigatorTest\UnstagedRecord();
$navigator2 = new SilverStripeNavigator($unversioned);
$classes = array_map('get_class', $navigator2->getItems()->toArray());
$classes = array_map('get_class', $navigator2->getItems()->toArray() ?? []);
$this->assertNotContains(SilverStripeNavigatorItem_LiveLink::class, $classes);
$this->assertNotContains(SilverStripeNavigatorItem_StageLink::class, $classes);
$this->assertNotContains(SilverStripeNavigatorItem_ArchiveLink::class, $classes);

View File

@ -78,8 +78,8 @@ class LinkablePluginTest extends SapphireTest
$this->assertTrue($result->exists());
$this->assertCount(2, $result);
$titles = $result->column('Title');
$this->assertTrue(in_array('Test page', $titles));
$this->assertTrue(in_array('Other test page', $titles));
$this->assertTrue(in_array('Test page', $titles ?? []));
$this->assertTrue(in_array('Other test page', $titles ?? []));
$result = LinkablePlugin::applyLinkFilter(
'test',

View File

@ -37,8 +37,8 @@ class SiteTreeBacklinksTest extends SapphireTest
$page3 = $this->objFromFixture('Page', 'page3');
$page3->Content = str_replace(
'$page1.ID',
$this->objFromFixture('Page', 'page1')->ID,
$page3->Content
$this->objFromFixture('Page', 'page1')->ID ?? '',
$page3->Content ?? ''
);
$page3->write();
}

View File

@ -26,8 +26,8 @@ class SiteTreeHTMLEditorFieldTest extends FunctionalTest
$files = File::get()->exclude('ClassName', Folder::class);
foreach ($files as $file) {
$destPath = TestAssetStore::getLocalPath($file);
Filesystem::makeFolder(dirname($destPath));
file_put_contents($destPath, str_repeat('x', 1000000));
Filesystem::makeFolder(dirname($destPath ?? ''));
file_put_contents($destPath ?? '', str_repeat('x', 1000000));
}
// Ensure all pages are published

View File

@ -81,11 +81,11 @@ class SiteTreeLinkTrackingTest extends SapphireTest
public function testHighlighter()
{
$content = $this->highlight('<a href="[sitetree_link,id=123]" class="existing-class">link</a>');
$this->assertEquals(substr_count($content, 'ss-broken'), 1, 'A ss-broken class is added to the broken link.');
$this->assertEquals(substr_count($content, 'existing-class'), 1, 'Existing class is not removed.');
$this->assertEquals(substr_count($content ?? '', 'ss-broken'), 1, 'A ss-broken class is added to the broken link.');
$this->assertEquals(substr_count($content ?? '', 'existing-class'), 1, 'Existing class is not removed.');
$content = $this->highlight('<a href="[sitetree_link,id=123]">link</a>');
$this->assertEquals(substr_count($content, 'ss-broken'), 1, 'ss-broken class is added to the broken link.');
$this->assertEquals(substr_count($content ?? '', 'ss-broken'), 1, 'ss-broken class is added to the broken link.');
$otherPage = new Page();
$otherPage->Content = '';
@ -94,7 +94,7 @@ class SiteTreeLinkTrackingTest extends SapphireTest
$content = $this->highlight(
"<a href=\"[sitetree_link,id=$otherPage->ID]\" class=\"existing-class ss-broken ss-broken\">link</a>"
);
$this->assertEquals(substr_count($content, 'ss-broken'), 0, 'All ss-broken classes are removed from good link');
$this->assertEquals(substr_count($content, 'existing-class'), 1, 'Existing class is not removed.');
$this->assertEquals(substr_count($content ?? '', 'ss-broken'), 0, 'All ss-broken classes are removed from good link');
$this->assertEquals(substr_count($content ?? '', 'existing-class'), 1, 'Existing class is not removed.');
}
}

View File

@ -146,7 +146,7 @@ class SiteTreeTest extends SapphireTest
public function testDisallowedChildURLGeneration($title, $urlSegment)
{
// Using the same dataprovider, strip out the -2 from the admin and dev segment
$urlSegment = str_replace('-2', '', $urlSegment);
$urlSegment = str_replace('-2', '', $urlSegment ?? '');
$page = Page::create(['Title' => $title, 'ParentID' => 1]);
$id = $page->write();
$page = Page::get()->byID($id);
@ -821,9 +821,9 @@ class SiteTreeTest extends SapphireTest
$diff = $page->compareVersions(1, 2);
$processedContent = trim($diff->Content);
$processedContent = preg_replace('/\s*</', '<', $processedContent);
$processedContent = preg_replace('/>\s*/', '>', $processedContent);
$processedContent = trim($diff->Content ?? '');
$processedContent = preg_replace('/\s*</', '<', $processedContent ?? '');
$processedContent = preg_replace('/>\s*/', '>', $processedContent ?? '');
$this->assertEquals("<ins><span>This is a test</span></ins>", $processedContent);
Diff::$html_cleaner_class = $oldCleanerClass;
@ -1485,7 +1485,7 @@ class SiteTreeTest extends SapphireTest
// test the meta generator tag version can be configured off
Config::modify()->set(SiteTree::class, 'show_meta_generator_version', false);
$content = $expected['generator']['attributes']['content'];
$expected['generator']['attributes']['content'] = str_replace(' 4.50', '', $content);
$expected['generator']['attributes']['content'] = str_replace(' 4.50', '', $content ?? '');
$this->assertEquals($expected, $page->MetaComponents());
}

View File

@ -9,6 +9,6 @@ class VirtualPageTest_TestDBField extends DBVarchar implements TestOnly
{
public function forTemplate()
{
return strtoupper($this->XML());
return strtoupper($this->XML() ?? '');
}
}

View File

@ -52,12 +52,12 @@ class CmsReportsTest extends SapphireTest
// ASSERT that the "draft" report is returning the correct results.
$parameters = ['CheckSite' => 'Draft'];
$results = count($report->sourceRecords($parameters, null, null)) > 0;
$results = count($report->sourceRecords($parameters, null, null) ?? []) > 0;
$isDraftBroken ? $this->assertTrue($results, "{$class} has NOT returned the correct DRAFT results, as NO pages were found.") : $this->assertFalse($results, "{$class} has NOT returned the correct DRAFT results, as pages were found.");
// ASSERT that the "published" report is returning the correct results.
$parameters = ['CheckSite' => 'Published', 'OnLive' => 1];
$results = count($report->sourceRecords($parameters, null, null)) > 0;
$results = count($report->sourceRecords($parameters, null, null) ?? []) > 0;
$isPublishedBroken ? $this->assertTrue($results, "{$class} has NOT returned the correct PUBLISHED results, as NO pages were found.") : $this->assertFalse($results, "{$class} has NOT returned the correct PUBLISHED results, as pages were found.");
}
@ -124,7 +124,7 @@ class CmsReportsTest extends SapphireTest
// Correct the "draft" broken link.
$page->Content = str_replace('987654321', $page->ID, $page->Content);
$page->Content = str_replace('987654321', $page->ID ?? '', $page->Content ?? '');
$page->writeToStage('Stage');
// ASSERT that the "draft" report has NOT detected the page having a broken link.
@ -191,7 +191,7 @@ class CmsReportsTest extends SapphireTest
$file = File::create();
$file->Filename = 'name.pdf';
$file->write();
$page->Content = str_replace('987654321', $file->ID, $page->Content);
$page->Content = str_replace('987654321', $file->ID ?? '', $page->Content ?? '');
$page->writeToStage('Stage');
// ASSERT that the "draft" report has NOT detected the page having a broken file.

View File

@ -25,7 +25,7 @@ class CMSMainSearchFormTest extends FunctionalTest
);
$titles = $this->getPageTitles();
$this->assertEquals(count($titles), 1);
$this->assertEquals(count($titles ?? []), 1);
// For some reason the title gets split into two lines
$this->assertStringContainsString('Page 1', $titles[0]);
@ -37,7 +37,7 @@ class CMSMainSearchFormTest extends FunctionalTest
$links = $this->cssParser()->getBySelector('.col-getTreeTitle span.item');
if ($links) {
foreach ($links as $link) {
$titles[] = preg_replace('/\n/', ' ', $link->asXML());
$titles[] = preg_replace('/\n/', ' ', $link->asXML() ?? '');
}
}
return $titles;

View File

@ -46,7 +46,7 @@ class MigrateSiteTreeLinkingTaskTest extends SapphireTest
];
foreach (DB::query('SELECT "ID", "Content" FROM "SiteTree"') as $row) {
$id = (int)$row['ID'];
$content = str_replace(array_keys($replacements), array_values($replacements), $row['Content']);
$content = str_replace(array_keys($replacements ?? []), array_values($replacements ?? []), $row['Content'] ?? '');
DB::prepared_query('UPDATE "SiteTree" SET "Content" = ? WHERE "ID" = ?', [$content, $id]);
}
DataObject::reset();