Skip to content

Commit

Permalink
Merge branch '4.2' into 4
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Jun 25, 2018
2 parents 7c3dba2 + 5b8242c commit 019bb52
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 36 deletions.
51 changes: 28 additions & 23 deletions tests/php/Model/SiteTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\CMS\Tests\Model;

use LogicException;
use Page;
use ReflectionMethod;
use SilverStripe\CMS\Model\RedirectorPage;
Expand All @@ -11,6 +12,7 @@
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\i18n\i18n;
use SilverStripe\ORM\DataObject;
Expand All @@ -22,22 +24,25 @@
use SilverStripe\Security\Permission;
use SilverStripe\Security\Security;
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\Subsites\Extensions\SiteTreeSubsites;
use SilverStripe\Versioned\Versioned;
use SilverStripe\View\Parsers\Diff;
use SilverStripe\View\Parsers\ShortcodeParser;
use SilverStripe\View\Parsers\URLSegmentFilter;
use SilverStripe\Core\Injector\Injector;
use LogicException;
use TractorCow\Fluent\Extension\FluentSiteTreeExtension;

class SiteTreeTest extends SapphireTest
{
protected static $fixture_file = 'SiteTreeTest.yml';

protected static $illegal_extensions = array(
SiteTree::class => array('SiteTreeSubsites', 'Translatable'),
);
protected static $illegal_extensions = [
SiteTree::class => [
SiteTreeSubsites::class,
FluentSiteTreeExtension::class,
],
];

protected static $extra_dataobjects = array(
protected static $extra_dataobjects = [
SiteTreeTest_ClassA::class,
SiteTreeTest_ClassB::class,
SiteTreeTest_ClassC::class,
Expand All @@ -46,7 +51,7 @@ class SiteTreeTest extends SapphireTest
SiteTreeTest_NotRoot::class,
SiteTreeTest_StageStatusInherit::class,
SiteTreeTest_DataObject::class,
);
];

public function reservedSegmentsProvider()
{
Expand Down Expand Up @@ -97,7 +102,7 @@ public function testCreateDefaultpages()
*/
public function testURLGeneration()
{
$expectedURLs = array(
$expectedURLs = [
'home' => 'home',
'staff' => 'my-staff',
'about' => 'about-us',
Expand All @@ -109,7 +114,7 @@ public function testURLGeneration()
'object' => 'object',
'controller' => 'controller',
'numericonly' => '1930',
);
];

foreach ($expectedURLs as $fixture => $urlSegment) {
$obj = $this->objFromFixture('Page', $fixture);
Expand Down Expand Up @@ -214,9 +219,9 @@ public function testGetOneFromLive()
$oldMode = Versioned::get_reading_mode();
Versioned::set_stage(Versioned::LIVE);

$checkSiteTree = DataObject::get_one(SiteTree::class, array(
$checkSiteTree = DataObject::get_one(SiteTree::class, [
'"SiteTree"."URLSegment"' => 'get-one-test-page'
));
]);
$this->assertEquals("V1", $checkSiteTree->Title);

Versioned::set_reading_mode($oldMode);
Expand Down Expand Up @@ -610,9 +615,9 @@ public function testReadArchiveDate()
{
$date = '2009-07-02 14:05:07';
Versioned::reading_archived_date($date);
SiteTree::get()->where(array(
SiteTree::get()->where([
'"SiteTree"."ParentID"' => 0
))->sql($args);
])->sql($args);
$this->assertContains($date, $args);
}

Expand Down Expand Up @@ -671,19 +676,19 @@ public function testCreatePermissions()

// Test creation underneath a parent which this user doesn't have access to
$parent = $this->objFromFixture('Page', 'about');
$this->assertFalse(singleton(SiteTree::class)->canCreate(null, array('Parent' => $parent)));
$this->assertFalse(singleton(SiteTree::class)->canCreate(null, ['Parent' => $parent]));

// Test creation underneath a parent which doesn't allow a certain child
$parentB = new SiteTreeTest_ClassB();
$parentB->Title = 'Only Allows SiteTreeTest_ClassC';
$parentB->write();
$this->assertTrue(singleton(SiteTreeTest_ClassA::class)->canCreate(null));
$this->assertFalse(singleton(SiteTreeTest_ClassA::class)->canCreate(null, array('Parent' => $parentB)));
$this->assertTrue(singleton(SiteTreeTest_ClassC::class)->canCreate(null, array('Parent' => $parentB)));
$this->assertFalse(singleton(SiteTreeTest_ClassA::class)->canCreate(null, ['Parent' => $parentB]));
$this->assertTrue(singleton(SiteTreeTest_ClassC::class)->canCreate(null, ['Parent' => $parentB]));

// Test creation underneath a parent which doesn't exist in the database. This should
// fall back to checking whether the user can create pages at the root of the site
$this->assertTrue(singleton(SiteTree::class)->canCreate(null, array('Parent' => singleton(SiteTree::class))));
$this->assertTrue(singleton(SiteTree::class)->canCreate(null, ['Parent' => singleton(SiteTree::class)]));

//Test we don't check for allowedChildren on parent context if it's not SiteTree instance
$this->assertTrue(singleton(SiteTree::class)->canCreate(null, ['Parent' => $this->objFromFixture(SiteTreeTest_DataObject::class, 'relations')]));
Expand Down Expand Up @@ -803,7 +808,7 @@ public function testLinkShortcodeHandler()
$redirectPage = $this->objFromFixture(RedirectorPage::class, 'external');

$parser = new ShortcodeParser();
$parser->register('sitetree_link', array(SiteTree::class, 'link_shortcode_handler'));
$parser->register('sitetree_link', [SiteTree::class, 'link_shortcode_handler']);

$aboutShortcode = sprintf('[sitetree_link,id=%d]', $aboutPage->ID);
$aboutEnclosed = sprintf('[sitetree_link,id=%d]Example Content[/sitetree_link]', $aboutPage->ID);
Expand Down Expand Up @@ -847,9 +852,9 @@ public function testIsCurrent()
$this->assertFalse($productPage->isCurrent());

$this->assertTrue(
DataObject::get_one(SiteTree::class, array(
DataObject::get_one(SiteTree::class, [
'"SiteTree"."Title"' => 'About Us'
))->isCurrent(),
])->isCurrent(),
'Assert that isCurrent works on another instance with the same ID.'
);

Expand Down Expand Up @@ -893,7 +898,7 @@ public function testURLSegmentAutoUpdate()
$sitetree->Title = _t(
'SilverStripe\\CMS\\Controllers\\CMSMain.NEWPAGE',
'New {pagetype}',
array('pagetype' => $sitetree->i18n_singular_name())
['pagetype' => $sitetree->i18n_singular_name()]
);
$sitetree->write();
$this->assertEquals(
Expand Down Expand Up @@ -928,7 +933,7 @@ public function testURLSegmentAutoUpdateLocalized()
$sitetree->Title = _t(
'SilverStripe\\CMS\\Controllers\\CMSMain.NEWPAGE',
'New {pagetype}',
array('pagetype' => $sitetree->i18n_singular_name())
['pagetype' => $sitetree->i18n_singular_name()]
);
$sitetree->write();
$this->assertEquals(
Expand Down Expand Up @@ -1361,7 +1366,7 @@ public function testOrphanedPages()
// necessary for admin / cms users, who require this permission to edit / rearrange these pages.
$permission = new Permission();
$permission->Code = 'VIEW_DRAFT_CONTENT';
$group = new Group(array('Title' => 'Staging Users'));
$group = new Group(['Title' => 'Staging Users']);
$group->write();
$group->Permissions()->add($permission);
$member = new Member();
Expand Down
22 changes: 12 additions & 10 deletions tests/php/Model/VirtualPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\ValidationException;
use SilverStripe\Security\Member;
use SilverStripe\Subsites\Extensions\SiteTreeSubsites;
use SilverStripe\Versioned\Versioned;
use TractorCow\Fluent\Extension\FluentSiteTreeExtension;

class VirtualPageTest extends FunctionalTest
{
Expand All @@ -31,18 +33,18 @@ class VirtualPageTest extends FunctionalTest
VirtualPageTest_VirtualPageSub::class,
];

protected static $illegal_extensions = array(
protected static $illegal_extensions = [
SiteTree::class => [
'SiteTreeSubsites',
'Translatable'
SiteTreeSubsites::class,
FluentSiteTreeExtension::class,
],
);
];

protected static $required_extensions = array(
protected static $required_extensions = [
SiteTree::class => [
VirtualPageTest_PageExtension::class
]
);
];

public function setUp()
{
Expand All @@ -52,11 +54,11 @@ public function setUp()
$this->logInWithPermission("ADMIN");

// Add extra fields
Config::modify()->merge(VirtualPage::class, 'initially_copied_fields', array('MyInitiallyCopiedField'));
Config::modify()->merge(VirtualPage::class, 'initially_copied_fields', ['MyInitiallyCopiedField']);
Config::modify()->merge(
VirtualPage::class,
'non_virtual_fields',
array('MyNonVirtualField', 'MySharedNonVirtualField')
['MyNonVirtualField', 'MySharedNonVirtualField']
);

// Ensure all pages are published
Expand Down Expand Up @@ -612,11 +614,11 @@ public function testVirtualPageAsAnAllowedChild()

public function testVirtualPagePointingToRedirectorPage()
{
$rp = new RedirectorPage(array('ExternalURL' => 'http://google.com', 'RedirectionType' => 'External'));
$rp = new RedirectorPage(['ExternalURL' => 'http://google.com', 'RedirectionType' => 'External']);
$rp->write();
$rp->publishRecursive();

$vp = new VirtualPage(array('URLSegment' => 'vptest', 'CopyContentFromID' => $rp->ID));
$vp = new VirtualPage(['URLSegment' => 'vptest', 'CopyContentFromID' => $rp->ID]);
$vp->write();
$vp->publishRecursive();

Expand Down
11 changes: 8 additions & 3 deletions tests/php/Search/SearchFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
use SilverStripe\PostgreSQL\PostgreSQLDatabase;
use SilverStripe\Security\Member;
use SilverStripe\Security\Security;
use SilverStripe\Subsites\Extensions\SiteTreeSubsites;
use SilverStripe\Versioned\Versioned;
use TractorCow\Fluent\Extension\FluentSiteTreeExtension;

/**
* @todo Fix unpublished pages check in testPublishedPagesMatchedByTitle()
Expand All @@ -30,9 +32,12 @@ class ZZZSearchFormTest extends FunctionalTest

protected static $fixture_file = 'SearchFormTest.yml';

protected static $illegal_extensions = array(
SiteTree::class => array('SiteTreeSubsites', 'Translatable')
);
protected static $illegal_extensions = [
SiteTree::class => [
SiteTreeSubsites::class,
FluentSiteTreeExtension::class,
],
];

/**
* @var ContentController
Expand Down

0 comments on commit 019bb52

Please sign in to comment.