mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
Merge pull request #350 from creative-commoners/pulls/2.0/fix-cmsmain-tests
Use injected CMSMain to prevent unit test error missing dependencies
This commit is contained in:
commit
0fcde6c0bb
14
.travis.yml
14
.travis.yml
@ -14,25 +14,25 @@ env:
|
|||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- php: 5.6
|
- php: 5.6
|
||||||
env: DB=MYSQL PHPCS_TEST=1 PHPUNIT_TEST=1
|
env: DB=MYSQL INSTALLER_VERSION=4.0.x-dev PHPCS_TEST=1 PHPUNIT_TEST=1
|
||||||
- php: 7.1
|
- php: 7.1
|
||||||
env: DB=PGSQL PHPUNIT_TEST=1
|
env: DB=PGSQL INSTALLER_VERSION=4.1.x-dev PHPUNIT_TEST=1
|
||||||
- php: 7.2
|
- php: 7.2
|
||||||
env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1
|
env: DB=MYSQL INSTALLER_VERSION=4.2.x-dev PHPUNIT_COVERAGE_TEST=1
|
||||||
- php: 7.0
|
- php: 7.0
|
||||||
env: DB=MYSQL BEHAT_TEST=1
|
env: DB=MYSQL INSTALLER_VERSION=4.x-dev BEHAT_TEST=1
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- php: 7.0
|
- php: 7.0
|
||||||
env: DB=MYSQL BEHAT_TEST=1
|
env: DB=MYSQL INSTALLER_VERSION=4.x-dev BEHAT_TEST=1
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- phpenv rehash
|
- phpenv rehash
|
||||||
- phpenv config-rm xdebug.ini
|
- phpenv config-rm xdebug.ini
|
||||||
- echo 'memory_limit = 2G' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
|
- echo 'memory_limit = 2G' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
|
||||||
- composer validate
|
- composer validate
|
||||||
- composer require silverstripe/installer 4.0.x-dev --no-update
|
- composer require silverstripe/installer $INSTALLER_VERSION --no-update
|
||||||
- if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.0.x-dev; fi
|
- if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.0.x-dev; fi
|
||||||
- composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
|
- composer install --prefer-source --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
|
||||||
- echo "SS_BASE_URL=http://localhost:8080/" >> .env
|
- echo "SS_BASE_URL=http://localhost:8080/" >> .env
|
||||||
|
|
||||||
# Behat bootstrapping
|
# Behat bootstrapping
|
||||||
|
@ -19,6 +19,7 @@ use SilverStripe\ORM\DataExtension;
|
|||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\ORM\DataQuery;
|
use SilverStripe\ORM\DataQuery;
|
||||||
use SilverStripe\ORM\Queries\SQLSelect;
|
use SilverStripe\ORM\Queries\SQLSelect;
|
||||||
|
use SilverStripe\Security\Member;
|
||||||
use SilverStripe\Security\Security;
|
use SilverStripe\Security\Security;
|
||||||
use SilverStripe\SiteConfig\SiteConfig;
|
use SilverStripe\SiteConfig\SiteConfig;
|
||||||
use SilverStripe\Subsites\Model\Subsite;
|
use SilverStripe\Subsites\Model\Subsite;
|
||||||
@ -478,20 +479,21 @@ class SiteTreeSubsites extends DataExtension
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Member
|
* @param Member $member
|
||||||
* @return boolean|null
|
* @return boolean|null
|
||||||
*/
|
*/
|
||||||
public function canCreate($member = null)
|
public function canCreate($member = null)
|
||||||
{
|
{
|
||||||
// Typically called on a singleton, so we're not using the Subsite() relation
|
// Typically called on a singleton, so we're not using the Subsite() relation
|
||||||
$subsite = Subsite::currentSubsite();
|
$subsite = Subsite::currentSubsite();
|
||||||
|
|
||||||
if ($subsite && $subsite->exists() && $subsite->PageTypeBlacklist) {
|
if ($subsite && $subsite->exists() && $subsite->PageTypeBlacklist) {
|
||||||
$blacklist = str_replace(['[', '"', ']'], '', $subsite->PageTypeBlacklist);
|
// SS 4.1: JSON encoded. SS 4.0, comma delimited
|
||||||
$blacklist = str_replace(['\\\\'], '\\', $blacklist);
|
$blacklist = Convert::json2array($subsite->PageTypeBlacklist);
|
||||||
$blacklisted = explode(',', $blacklist);
|
if ($blacklist === false) {
|
||||||
|
$blacklist = explode(',', $subsite->PageTypeBlacklist);
|
||||||
|
}
|
||||||
|
|
||||||
if (in_array(get_class($this->owner), $blacklisted)) {
|
if (in_array(get_class($this->owner), (array) $blacklist)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,7 +185,7 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
|||||||
$s2 = $this->objFromFixture(Subsite::class, 'domaintest2');
|
$s2 = $this->objFromFixture(Subsite::class, 'domaintest2');
|
||||||
$page = singleton(SiteTree::class);
|
$page = singleton(SiteTree::class);
|
||||||
|
|
||||||
$s1->PageTypeBlacklist = implode(',', [TestClassA::class, ErrorPage::class]);
|
$s1->PageTypeBlacklist = json_encode([TestClassA::class, ErrorPage::class]);
|
||||||
$s1->write();
|
$s1->write();
|
||||||
|
|
||||||
Subsite::changeSubsite($s1);
|
Subsite::changeSubsite($s1);
|
||||||
@ -252,15 +252,14 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
|||||||
{
|
{
|
||||||
$this->logInAs('editor');
|
$this->logInAs('editor');
|
||||||
|
|
||||||
$cmsmain = new CMSMain();
|
|
||||||
|
|
||||||
$s1 = $this->objFromFixture(Subsite::class, 'domaintest1');
|
$s1 = $this->objFromFixture(Subsite::class, 'domaintest1');
|
||||||
$s2 = $this->objFromFixture(Subsite::class, 'domaintest2');
|
$s2 = $this->objFromFixture(Subsite::class, 'domaintest2');
|
||||||
|
|
||||||
$s1->PageTypeBlacklist = implode(',', [TestClassA::class, ErrorPage::class]);
|
$s1->PageTypeBlacklist = json_encode([TestClassA::class, ErrorPage::class]);
|
||||||
$s1->write();
|
$s1->write();
|
||||||
|
|
||||||
Subsite::changeSubsite($s1);
|
Subsite::changeSubsite($s1);
|
||||||
|
$cmsmain = CMSMain::create();
|
||||||
$hints = Convert::json2array($cmsmain->SiteTreeHints());
|
$hints = Convert::json2array($cmsmain->SiteTreeHints());
|
||||||
$classes = $hints['Root']['disallowedChildren'];
|
$classes = $hints['Root']['disallowedChildren'];
|
||||||
$this->assertContains(ErrorPage::class, $classes);
|
$this->assertContains(ErrorPage::class, $classes);
|
||||||
@ -268,7 +267,12 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
|||||||
$this->assertNotContains(TestClassB::class, $classes);
|
$this->assertNotContains(TestClassB::class, $classes);
|
||||||
|
|
||||||
Subsite::changeSubsite($s2);
|
Subsite::changeSubsite($s2);
|
||||||
|
// SS 4.1 and above
|
||||||
|
if ($cmsmain->hasMethod('getHintsCache')) {
|
||||||
|
$cmsmain->getHintsCache()->clear();
|
||||||
|
}
|
||||||
$hints = Convert::json2array($cmsmain->SiteTreeHints());
|
$hints = Convert::json2array($cmsmain->SiteTreeHints());
|
||||||
|
|
||||||
$classes = $hints['Root']['disallowedChildren'];
|
$classes = $hints['Root']['disallowedChildren'];
|
||||||
$this->assertNotContains(ErrorPage::class, $classes);
|
$this->assertNotContains(ErrorPage::class, $classes);
|
||||||
$this->assertNotContains(TestClassA::class, $classes);
|
$this->assertNotContains(TestClassA::class, $classes);
|
||||||
|
@ -21,10 +21,6 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest
|
|||||||
'SubsitesVirtualPageTest.yml',
|
'SubsitesVirtualPageTest.yml',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected static $illegal_extensions = [
|
|
||||||
SiteTree::class => ['Translatable'] // @todo implement Translatable namespace
|
|
||||||
];
|
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
Loading…
Reference in New Issue
Block a user