diff --git a/code/SiteTreeSubsites.php b/code/SiteTreeSubsites.php index 033b1b2..5b84bb3 100644 --- a/code/SiteTreeSubsites.php +++ b/code/SiteTreeSubsites.php @@ -47,8 +47,8 @@ class SiteTreeSubsites extends DataObjectDecorator { // If you're querying by ID, ignore the sub-site - this is a bit ugly... if(strpos($query->where[0], ".`ID` = ") === false && strpos($query->where[0], ".ID = ") === false) { - if($context = DataObject::context_obj()) { $subsiteID = $context->SubsiteID; } - else $subsiteID = Subsite::currentSubsiteID(); + if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID; + else $subsiteID = (int)Subsite::currentSubsiteID(); // The foreach is an ugly way of getting the first key :-) foreach($query->from as $tableName => $info) { diff --git a/tests/SubsiteAdminTest.php b/tests/SubsiteAdminTest.php index 53c02dd..ef1aa7b 100644 --- a/tests/SubsiteAdminTest.php +++ b/tests/SubsiteAdminTest.php @@ -14,6 +14,40 @@ class SubsiteAdminTest extends SapphireTest { $this->assertTrue($templates->onlyContainsIDs($templateIDs)); } + /** + * Test searching for an intranet + */ + function testIntranetSearch() { + $cont = new SubsiteAdmin(); + $cont->pushCurrent(); + + $member = $this->objFromFixture('Member','admin'); + $member->logIn(); + + // Check that the logged-in member has the correct permissions + $this->assertTrue(Permission::check('ADMIN') ? true : false); + + $form = $cont->SearchForm(); + + $searches = array( + array('Name' => 'Other'), + array('Name' => ''), + ); + + foreach($searches as $search) { + $response = $form->testAjaxSubmission('getResults', $search); + + echo $response->getBody(); + } + + + /* + $this->assertHasLink($response->getBody(), 'admin/intranets/show/' . $this->idFromFixture('Subsite', 'other')); + $this->assertHasntLink($response->getBody(), 'admin/intranets/show/' . $this->idFromFixture('Subsite', 'other')); + */ + $cont->popCurrent(); + } + } ?> \ No newline at end of file diff --git a/tests/SubsiteTest.yml b/tests/SubsiteTest.yml index b002995..8231d3d 100644 --- a/tests/SubsiteTest.yml +++ b/tests/SubsiteTest.yml @@ -34,4 +34,20 @@ Page: # Title: Page not Found # ErrorCode: 404 # SubsiteID: =>Subsite_Template.main - \ No newline at end of file + +Group: + admin: + Title: Admin + +Member: + admin: + FirstName: Admin + Surname: User + Email: admin@test.com + Password: rangi + Groups: =>Group.admin + +Permission: + admin: + Code: ADMIN + GroupID: =>Group.admin \ No newline at end of file