Merge pull request #4588 from tractorcow/fix/3.1/admin-tests

BUG Fix missing framework/admin/tests
This commit is contained in:
Daniel Hensby 2015-09-08 09:57:53 +01:00
commit 00385792c5
3 changed files with 39 additions and 10 deletions

View File

@ -40,6 +40,7 @@ before_script:
script: script:
- "if [ \"$BEHAT_TEST\" = \"\" ]; then vendor/bin/phpunit framework/tests; fi" - "if [ \"$BEHAT_TEST\" = \"\" ]; then vendor/bin/phpunit framework/tests; fi"
- "if [ \"$BEHAT_TEST\" = \"\" ]; then vendor/bin/phpunit framework/admin/tests; fi"
- "if [ \"$BEHAT_TEST\" = \"1\" ]; then vendor/bin/behat @framework; fi" - "if [ \"$BEHAT_TEST\" = \"1\" ]; then vendor/bin/behat @framework; fi"
after_failure: after_failure:

View File

@ -17,7 +17,7 @@ class LeftAndMainTest extends FunctionalTest {
// @todo fix controller stack problems and re-activate // @todo fix controller stack problems and re-activate
//$this->autoFollowRedirection = false; //$this->autoFollowRedirection = false;
CMSMenu::populate_menu(); $this->resetMenu();
$this->backupCss = Config::inst()->get('LeftAndMain', 'extra_requirements_css'); $this->backupCss = Config::inst()->get('LeftAndMain', 'extra_requirements_css');
$this->backupJs = Config::inst()->get('LeftAndMain', 'extra_requirements_javascript'); $this->backupJs = Config::inst()->get('LeftAndMain', 'extra_requirements_javascript');
@ -34,6 +34,23 @@ class LeftAndMainTest extends FunctionalTest {
Requirements::set_combined_files_enabled(false); Requirements::set_combined_files_enabled(false);
} }
/**
* Clear menu to default state as per LeftAndMain::init()
*/
protected function resetMenu() {
CMSMenu::clear_menu();
CMSMenu::populate_menu();
CMSMenu::add_link(
'Help',
_t('LeftAndMain.HELP', 'Help', 'Menu title'),
LeftAndMain::config()->help_link,
-2,
array(
'target' => '_blank'
)
);
}
public function tearDown() { public function tearDown() {
parent::tearDown(); parent::tearDown();
@ -127,13 +144,14 @@ class LeftAndMainTest extends FunctionalTest {
public function testLeftAndMainSubclasses() { public function testLeftAndMainSubclasses() {
$adminuser = $this->objFromFixture('Member','admin'); $adminuser = $this->objFromFixture('Member','admin');
$this->session()->inst_set('loggedInAs', $adminuser->ID); $this->session()->inst_set('loggedInAs', $adminuser->ID);
$menuItems = singleton('LeftAndMain')->MainMenu(); $this->resetMenu();
$menuItems = singleton('LeftAndMain')->MainMenu(false);
foreach($menuItems as $menuItem) { foreach($menuItems as $menuItem) {
$link = $menuItem->Link; $link = $menuItem->Link;
// don't test external links // don't test external links
if(preg_match('/^https?:\/\//',$link)) continue; if(preg_match('/^(https?:)?\/\//',$link)) continue;
$response = $this->get($link); $response = $this->get($link);
@ -157,6 +175,7 @@ class LeftAndMainTest extends FunctionalTest {
// anonymous user // anonymous user
$this->session()->inst_set('loggedInAs', null); $this->session()->inst_set('loggedInAs', null);
$this->resetMenu();
$menuItems = singleton('LeftAndMain')->MainMenu(false); $menuItems = singleton('LeftAndMain')->MainMenu(false);
$this->assertEquals( $this->assertEquals(
array_map($allValsFn, $menuItems->column('Code')), array_map($allValsFn, $menuItems->column('Code')),
@ -165,18 +184,24 @@ class LeftAndMainTest extends FunctionalTest {
); );
// restricted cms user // restricted cms user
$this->session()->inst_set('loggedInAs', $securityonlyuser->ID); $this->logInAs($securityonlyuser);
$this->resetMenu();
$menuItems = singleton('LeftAndMain')->MainMenu(false); $menuItems = singleton('LeftAndMain')->MainMenu(false);
$this->assertEquals( $this->assertEquals(
array_map($allValsFn, $menuItems->column('Code')), array_map($allValsFn, $menuItems->column('Code')),
array('SecurityAdmin','Help'), array('CMSProfileController', 'SecurityAdmin','Help'),
'Groups with limited access can only access the interfaces they have permissions for' 'Groups with limited access can only access the interfaces they have permissions for'
); );
// all cms sections user // all cms sections user
$this->session()->inst_set('loggedInAs', $allcmssectionsuser->ID); $this->logInAs($allcmssectionsuser);
$this->resetMenu();
$menuItems = singleton('LeftAndMain')->MainMenu(false); $menuItems = singleton('LeftAndMain')->MainMenu(false);
$this->assertContains('SecurityAdmin', $this->assertContains('CMSProfileController',
array_map($allValsFn, $menuItems->column('Code')),
'Group with CMS_ACCESS_LeftAndMain permission can edit own profile'
);
$this->assertContains('SecurityAdmin',
array_map($allValsFn, $menuItems->column('Code')), array_map($allValsFn, $menuItems->column('Code')),
'Group with CMS_ACCESS_LeftAndMain permission can access all sections' 'Group with CMS_ACCESS_LeftAndMain permission can access all sections'
); );
@ -186,7 +211,8 @@ class LeftAndMainTest extends FunctionalTest {
); );
// admin // admin
$this->session()->inst_set('loggedInAs', $adminuser->ID); $this->logInAs($adminuser);
$this->resetMenu();
$menuItems = singleton('LeftAndMain')->MainMenu(false); $menuItems = singleton('LeftAndMain')->MainMenu(false);
$this->assertContains( $this->assertContains(
'SecurityAdmin', 'SecurityAdmin',
@ -265,6 +291,8 @@ class LeftAndMainTest_Object extends DataObject implements TestOnly {
'URLSegment' => 'Varchar', 'URLSegment' => 'Varchar',
'Sort' => 'Int', 'Sort' => 'Int',
); );
private static $default_sort = '"Sort"';
private static $extensions = array( private static $extensions = array(
'Hierarchy' 'Hierarchy'

View File

@ -732,7 +732,7 @@ class Hierarchy extends DataExtension {
$children = $baseClass::get() $children = $baseClass::get()
->filter('ParentID', (int)$this->owner->ID) ->filter('ParentID', (int)$this->owner->ID)
->sort('Sort', 'ASC'); ->sort('"Sort"', 'ASC');
if ($afterNode) { if ($afterNode) {
$children = $children->filter('Sort:GreaterThan', $afterNode->Sort); $children = $children->filter('Sort:GreaterThan', $afterNode->Sort);
} }