silverstripe /
silverstripe-subsites
| 1 | <?php |
||
| 2 | |||
| 3 | namespace SilverStripe\Subsites\Tests; |
||
| 4 | |||
| 5 | use SilverStripe\CMS\Controllers\CMSMain; |
||
| 6 | use SilverStripe\Control\Director; |
||
| 7 | use SilverStripe\Control\Session; |
||
| 8 | use SilverStripe\Core\Config\Config; |
||
| 9 | use SilverStripe\Security\Member; |
||
| 10 | use SilverStripe\Subsites\Model\Subsite; |
||
| 11 | |||
| 12 | class SubsiteAdminTest extends BaseSubsiteTest |
||
| 13 | { |
||
| 14 | protected static $fixture_file = 'SubsiteTest.yml'; |
||
| 15 | |||
| 16 | protected function setUp() |
||
| 17 | { |
||
| 18 | parent::setUp(); |
||
| 19 | |||
| 20 | Config::modify()->set(Subsite::class, 'write_hostmap', false); |
||
| 21 | } |
||
| 22 | |||
| 23 | protected function adminLoggedInSession() |
||
| 24 | { |
||
| 25 | return new Session([ |
||
| 26 | 'loggedInAs' => $this->idFromFixture(Member::class, 'admin') |
||
| 27 | ]); |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Test generation of the view |
||
| 32 | */ |
||
| 33 | public function testBasicView() |
||
| 34 | { |
||
| 35 | $subsite1ID = $this->objFromFixture(Subsite::class, 'domaintest1')->ID; |
||
| 36 | |||
| 37 | // Open the admin area logged in as admin |
||
| 38 | $response1 = Director::test('admin/subsites/', null, $this->adminLoggedInSession()); |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 39 | |||
| 40 | // Confirm that this URL gets you the entire page, with the edit form loaded |
||
| 41 | $response2 = Director::test( |
||
| 42 | "admin/subsites/SilverStripe-Subsites-Model-Subsite/EditForm/field/" |
||
| 43 | ."SilverStripe-Subsites-Model-Subsite/item/$subsite1ID/edit", |
||
| 44 | null, |
||
| 45 | $this->adminLoggedInSession() |
||
| 46 | ); |
||
| 47 | $this->assertTrue( |
||
| 48 | strpos($response2->getBody(), 'id="Form_ItemEditForm_ID"') !== false, |
||
| 49 | 'Testing Form_ItemEditForm_ID exists' |
||
| 50 | ); |
||
| 51 | $this->assertTrue(strpos($response2->getBody(), '<head') !== false, 'Testing <head> exists'); |
||
| 52 | } |
||
| 53 | |||
| 54 | |||
| 55 | /** |
||
| 56 | * Test that the main-site user with ADMIN permissions can access all subsites, regardless |
||
| 57 | * of whether he is in a subsite-specific group or not. |
||
| 58 | */ |
||
| 59 | public function testMainsiteAdminCanAccessAllSubsites() |
||
| 60 | { |
||
| 61 | $this->logInAs('admin'); |
||
| 62 | |||
| 63 | $cmsMain = new CMSMain(); |
||
| 64 | foreach ($cmsMain->Subsites() as $subsite) { |
||
| 65 | $ids[$subsite->ID] = true; |
||
| 66 | } |
||
| 67 | |||
| 68 | $this->assertArrayHasKey(0, $ids, 'Main site accessible'); |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 69 | $this->assertArrayHasKey($this->idFromFixture(Subsite::class, 'main'), $ids, 'Site with no groups inaccesible'); |
||
| 70 | $this->assertArrayHasKey( |
||
| 71 | $this->idFromFixture(Subsite::class, 'subsite1'), |
||
| 72 | $ids, |
||
| 73 | 'Subsite1 Template inaccessible' |
||
| 74 | ); |
||
| 75 | $this->assertArrayHasKey( |
||
| 76 | $this->idFromFixture(Subsite::class, 'subsite2'), |
||
| 77 | $ids, |
||
| 78 | 'Subsite2 Template inaccessible' |
||
| 79 | ); |
||
| 80 | } |
||
| 81 | } |
||
| 82 |