silverstripe-subsites/tests/php/SubsiteAdminTest.php

75 lines
2.5 KiB
PHP
Raw Normal View History

2009-05-04 07:03:44 +02:00
<?php
namespace SilverStripe\Subsites\Tests;
2017-05-29 13:42:42 +02:00
use SilverStripe\CMS\Controllers\CMSMain;
2017-06-01 15:57:53 +02:00
use SilverStripe\Control\Director;
use SilverStripe\Control\Session;
use SilverStripe\Security\Member;
2017-05-24 15:25:34 +02:00
use SilverStripe\Subsites\Model\Subsite;
2017-05-24 15:26:28 +02:00
class SubsiteAdminTest extends BaseSubsiteTest
{
public static $fixture_file = 'subsites/tests/php/SubsiteTest.yml';
2017-05-29 13:42:42 +02:00
public function adminLoggedInSession()
2017-05-24 15:26:28 +02:00
{
2017-06-01 15:57:53 +02:00
return new Session([
2017-05-29 13:42:42 +02:00
'loggedInAs' => $this->idFromFixture(Member::class, 'admin')
2017-06-01 15:57:53 +02:00
]);
2007-08-21 03:38:20 +02:00
}
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
{
Subsite::$write_hostmap = false;
$subsite1ID = $this->objFromFixture(Subsite::class, 'domaintest1')->ID;
2007-08-21 03:38:20 +02:00
// Open the admin area logged in as admin
$response1 = Director::test('admin/subsites/', null, $this->adminLoggedInSession());
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
$response2 = Director::test(
"admin/subsites/SilverStripe-Subsites-Model-Subsite/EditForm/field/SilverStripe-Subsites-Model-Subsite/item/$subsite1ID/edit",
2017-06-01 15:57:53 +02:00
null,
$this->adminLoggedInSession()
);
$this->assertTrue(
strpos($response2->getBody(), 'id="Form_ItemEditForm_ID"') !== false,
'Testing Form_ItemEditForm_ID exists'
);
$this->assertTrue(strpos($response2->getBody(), '<head') !== false, 'Testing <head> exists');
2007-08-21 03:38:20 +02: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-05-29 13:42:42 +02:00
$member = $this->objFromFixture(Member::class, 'admin');
Session::set('loggedInAs', $member->ID);
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');
$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
}
}