2009-05-04 07:03:44 +02:00
|
|
|
<?php
|
2007-08-16 08:38:29 +02:00
|
|
|
|
2017-04-23 22:23:34 +02:00
|
|
|
namespace SilverStripe\Subsites\Tests;
|
|
|
|
|
2017-05-29 13:42:42 +02:00
|
|
|
use SilverStripe\CMS\Controllers\CMSMain;
|
2018-01-18 05:16:13 +01:00
|
|
|
use SilverStripe\Core\Config\Config;
|
2021-09-07 05:36:57 +02:00
|
|
|
use SilverStripe\Dev\FunctionalTest;
|
2017-05-24 15:25:34 +02:00
|
|
|
use SilverStripe\Subsites\Model\Subsite;
|
|
|
|
|
2021-09-07 05:36:57 +02:00
|
|
|
class SubsiteAdminTest extends FunctionalTest
|
2017-05-24 15:26:28 +02:00
|
|
|
{
|
2017-08-29 07:22:32 +02:00
|
|
|
protected static $fixture_file = 'SubsiteTest.yml';
|
2007-08-21 00:37:43 +02:00
|
|
|
|
2021-10-27 07:24:03 +02:00
|
|
|
protected function setUp(): void
|
2018-01-18 05:48:09 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
Config::modify()->set(Subsite::class, 'write_hostmap', false);
|
|
|
|
}
|
|
|
|
|
2007-08-21 03:38:20 +02:00
|
|
|
/**
|
|
|
|
* Test generation of the view
|
|
|
|
*/
|
2017-05-29 13:42:42 +02:00
|
|
|
public function testBasicView()
|
2017-05-24 15:26:28 +02:00
|
|
|
{
|
|
|
|
$subsite1ID = $this->objFromFixture(Subsite::class, 'domaintest1')->ID;
|
2010-08-04 00:41:10 +02:00
|
|
|
|
2021-09-07 05:36:57 +02:00
|
|
|
$this->logInAs('admin');
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2007-08-21 03:38:20 +02:00
|
|
|
// Confirm that this URL gets you the entire page, with the edit form loaded
|
2021-09-07 05:36:57 +02:00
|
|
|
$response = $this->get(
|
2018-02-01 01:19:02 +01:00
|
|
|
"admin/subsites/SilverStripe-Subsites-Model-Subsite/EditForm/field/"
|
2021-09-07 05:36:57 +02:00
|
|
|
."SilverStripe-Subsites-Model-Subsite/item/$subsite1ID/edit"
|
2017-08-29 07:07:24 +02:00
|
|
|
);
|
|
|
|
$this->assertTrue(
|
2022-04-13 03:49:48 +02:00
|
|
|
strpos($response->getBody() ?? '', 'id="Form_ItemEditForm_ID"') !== false,
|
2017-08-29 07:07:24 +02:00
|
|
|
'Testing Form_ItemEditForm_ID exists'
|
|
|
|
);
|
2022-04-13 03:49:48 +02:00
|
|
|
$this->assertTrue(strpos($response->getBody() ?? '', '<head') !== false, 'Testing <head> exists');
|
2007-08-21 03:38:20 +02:00
|
|
|
}
|
2009-02-24 23:09:15 +01:00
|
|
|
|
2017-05-24 15:26:28 +02:00
|
|
|
/**
|
|
|
|
* Test that the main-site user with ADMIN permissions can access all subsites, regardless
|
|
|
|
* of whether he is in a subsite-specific group or not.
|
|
|
|
*/
|
2017-05-29 13:42:42 +02:00
|
|
|
public function testMainsiteAdminCanAccessAllSubsites()
|
2017-05-24 15:26:28 +02:00
|
|
|
{
|
2017-08-29 07:22:32 +02:00
|
|
|
$this->logInAs('admin');
|
2017-05-24 15:26:28 +02:00
|
|
|
|
|
|
|
$cmsMain = new CMSMain();
|
|
|
|
foreach ($cmsMain->Subsites() as $subsite) {
|
|
|
|
$ids[$subsite->ID] = true;
|
|
|
|
}
|
|
|
|
|
2017-06-01 15:57:53 +02:00
|
|
|
$this->assertArrayHasKey(0, $ids, 'Main site accessible');
|
|
|
|
$this->assertArrayHasKey($this->idFromFixture(Subsite::class, 'main'), $ids, 'Site with no groups inaccesible');
|
2017-08-29 07:07:24 +02:00
|
|
|
$this->assertArrayHasKey(
|
|
|
|
$this->idFromFixture(Subsite::class, 'subsite1'),
|
|
|
|
$ids,
|
|
|
|
'Subsite1 Template inaccessible'
|
|
|
|
);
|
|
|
|
$this->assertArrayHasKey(
|
|
|
|
$this->idFromFixture(Subsite::class, 'subsite2'),
|
|
|
|
$ids,
|
|
|
|
'Subsite2 Template inaccessible'
|
|
|
|
);
|
2017-06-01 15:57:53 +02:00
|
|
|
}
|
2007-08-16 08:38:29 +02:00
|
|
|
}
|