mirror of
https://github.com/joomla/joomla-cms.git
synced 2024-06-25 23:02:55 +00:00
Add unit tests for JAdministratorHelper.
This commit is contained in:
parent
9bb86cd84f
commit
3886eeac1e
|
@ -21,24 +21,27 @@ class JAdministratorHelper
|
|||
/**
|
||||
* Return the application option string [main component].
|
||||
*
|
||||
* @return string Option.
|
||||
* @since 1.5
|
||||
* @return string The component to access.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public static function findOption()
|
||||
{
|
||||
$input = JFactory::getApplication()->input;
|
||||
$option = strtolower($input->get('option'));
|
||||
$app = JFactory::getApplication();
|
||||
$option = strtolower($app->input->get('option'));
|
||||
|
||||
$user = JFactory::getUser();
|
||||
if (($user->get('guest')) || !$user->authorise('core.login.admin')) {
|
||||
$user = $app->getIdentity();
|
||||
if ($user->get('guest') || !$user->authorise('core.login.admin'))
|
||||
{
|
||||
$option = 'com_login';
|
||||
}
|
||||
|
||||
if (empty($option)) {
|
||||
if (empty($option))
|
||||
{
|
||||
$option = 'com_cpanel';
|
||||
}
|
||||
|
||||
$input->set('option', $option);
|
||||
$app->input->set('option', $option);
|
||||
return $option;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
<testsuite name="libraries">
|
||||
<directory>tests/unit/suites/libraries</directory>
|
||||
</testsuite>
|
||||
<testsuite name="administrator">
|
||||
<directory>tests/unit/suites/administrator</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<logging>
|
||||
|
@ -15,6 +18,7 @@
|
|||
<filter>
|
||||
<whitelist addUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">libraries/cms</directory>
|
||||
<directory suffix=".php">administrator/includes</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
|
|
|
@ -0,0 +1,146 @@
|
|||
<?php
|
||||
/**
|
||||
* @package Joomla.UnitTest
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
require_once JPATH_ADMINISTRATOR . '/includes/helper.php';
|
||||
|
||||
/**
|
||||
* Test class for JAdministratorHelper.
|
||||
*/
|
||||
class JAdministratorHelperTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var JAdministratorHelper
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
//$this->object = new JErrorPage;
|
||||
$this->saveFactoryState();
|
||||
|
||||
JFactory::$application = $this->getMockApplication();
|
||||
$this->user = $this->getMock('Observer', array('get', 'authorise'));
|
||||
|
||||
JFactory::$application->expects($this->once())
|
||||
->method('getIdentity')
|
||||
->will($this->returnValue($this->user));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->restoreFactoryState();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers JAdministratorHelper::findOption
|
||||
*/
|
||||
public function testFindOptionGuest()
|
||||
{
|
||||
$this->user->expects($this->once())
|
||||
->method('get')
|
||||
->with($this->equalTo('guest'))
|
||||
->will($this->returnValue(true));
|
||||
$this->user->expects($this->never())
|
||||
->method('authorise');
|
||||
|
||||
$this->assertEquals(
|
||||
'com_login',
|
||||
JAdministratorHelper::findOption()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'com_login',
|
||||
JFactory::$application->input->get('option')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers JAdministratorHelper::findOption
|
||||
*/
|
||||
public function testFindOptionCanNotLoginAdmin()
|
||||
{
|
||||
$this->user->expects($this->once())
|
||||
->method('get')
|
||||
->with($this->equalTo('guest'))
|
||||
->will($this->returnValue(false));
|
||||
$this->user->expects($this->once())
|
||||
->method('authorise')
|
||||
->with($this->equalTo('core.login.admin'))
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$this->assertEquals(
|
||||
'com_login',
|
||||
JAdministratorHelper::findOption()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'com_login',
|
||||
JFactory::$application->input->get('option')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers JAdministratorHelper::findOption
|
||||
*/
|
||||
public function testFindOptionCanLoginAdmin()
|
||||
{
|
||||
$this->user->expects($this->once())
|
||||
->method('get')
|
||||
->with($this->equalTo('guest'))
|
||||
->will($this->returnValue(false));
|
||||
$this->user->expects($this->once())
|
||||
->method('authorise')
|
||||
->with($this->equalTo('core.login.admin'))
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->assertEquals(
|
||||
'com_cpanel',
|
||||
JAdministratorHelper::findOption()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'com_cpanel',
|
||||
JFactory::$application->input->get('option')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers JAdministratorHelper::findOption
|
||||
*/
|
||||
public function testFindOptionCanLoginAdminOptionSet()
|
||||
{
|
||||
$this->user->expects($this->once())
|
||||
->method('get')
|
||||
->with($this->equalTo('guest'))
|
||||
->will($this->returnValue(false));
|
||||
$this->user->expects($this->once())
|
||||
->method('authorise')
|
||||
->with($this->equalTo('core.login.admin'))
|
||||
->will($this->returnValue(true));
|
||||
|
||||
JFactory::$application->input->set('option', 'foo');
|
||||
|
||||
$this->assertEquals(
|
||||
'foo',
|
||||
JAdministratorHelper::findOption()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'foo',
|
||||
JFactory::$application->input->get('option')
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user