Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,70 +132,6 @@ public function testExecute()
$this->class->execute();
}

/**
* Data for fetchConfigurationData method.
*
* @return array
*
* @since 11.3
*/
public function getFetchConfigurationData()
{
return array(
// Note: file, class, expectsClass, (expected result array), whether there should be an exception
'Default configuration class' => array(JPATH_TEST_STUBS . '/configuration.php', null, 'JConfig', 'ConfigEval'),
'Custom file, invalid class' => array(JPATH_TEST_STUBS . '/config.wrongclass.php', 'noclass', false, array(), true),
);
}

/**
* Tests the JApplicationCli::fetchConfigurationData method.
*
* @param string $file The name of the configuration file.
* @param string $class The name of the class.
* @param boolean $expectsClass The result is expected to be a class.
* @param array $expects The expected result as an array.
* @param boolean $expectedException The expected exception
*
* @return void
*
* @dataProvider getFetchConfigurationData
* @since 11.3
*/
public function testFetchConfigurationData($file, $class, $expectsClass, $expects, $expectedException = false)
{
if ($expectedException)
{
$this->expectException('RuntimeException');
}

if (is_null($file) && is_null($class))
{
$config = TestReflection::invoke($this->class, 'fetchConfigurationData');
}
elseif (is_null($class))
{
$config = TestReflection::invoke($this->class, 'fetchConfigurationData', $file);
}
else
{
$config = TestReflection::invoke($this->class, 'fetchConfigurationData', $file, $class);
}

if ($expects == 'ConfigEval')
{
$expects = new JConfig;
$expects = (array) $expects;
}

if ($expectsClass)
{
$this->assertInstanceOf($expectsClass, $config, 'Checks the configuration object is the appropriate class.');
}

$this->assertEquals($expects, (array) $config, 'Checks the content of the configuration object.');
}

/**
* Tests the JApplicationCli::get method.
*
Expand Down Expand Up @@ -241,27 +177,4 @@ public function testGetInstanceForUnexistingClass()
{
JApplicationCli::getInstance('Foo');
}

/**
* Tests the JApplicationCli::loadConfiguration method.
*
* @return void
*
* @since 11.3
*/
public function testLoadConfiguration()
{
$this->assertSame(
$this->class, $this->class->loadConfiguration(array('foo' => 'bar')));

$this->assertEquals('bar', TestReflection::getValue($this->class, 'config')->get('foo'), 'Check the configuration array was loaded.');

$this->class->loadConfiguration(
(object) array(
'goo' => 'car',
)
);

$this->assertEquals('car', TestReflection::getValue($this->class, 'config')->get('goo'), 'Check the configuration object was loaded.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,70 +248,6 @@ public function testExecuteWithDocument()
$this->assertEquals('JWeb Body', $buffer);
}

/**
* Data for fetchConfigurationData method.
*
* @return array
*
* @since 11.3
*/
public function getFetchConfigurationData()
{
return array(
// Note: file, class, expectsClass, (expected result array), whether there should be an exception
'Default configuration class' => array(JPATH_TEST_STUBS . '/configuration.php', null, 'JConfig', 'ConfigEval'),
'Custom file, invalid class' => array(JPATH_TEST_STUBS . '/config.wrongclass.php', 'noclass', false, array(), true),
);
}

/**
* Tests the JCli::fetchConfigurationData method.
*
* @param string $file The name of the configuration file.
* @param string $class The name of the class.
* @param boolean $expectsClass The result is expected to be a class.
* @param array $expects The expected result as an array.
* @param bool $expectedException The expected exception.
*
* @return void
*
* @dataProvider getFetchConfigurationData
* @since 11.3
*/
public function testFetchConfigurationData($file, $class, $expectsClass, $expects, $expectedException = false)
{
if ($expectedException)
{
$this->expectException('RuntimeException');
}

if (is_null($file) && is_null($class))
{
$config = TestReflection::invoke($this->class, 'fetchConfigurationData');
}
elseif (is_null($class))
{
$config = TestReflection::invoke($this->class, 'fetchConfigurationData', $file);
}
else
{
$config = TestReflection::invoke($this->class, 'fetchConfigurationData', $file, $class);
}

if ($expects == 'ConfigEval')
{
$expects = new JConfig;
$expects = (array) $expects;
}

if ($expectsClass)
{
$this->assertInstanceOf($expectsClass, $config);
}

$this->assertEquals($expects, (array) $config);
}

/**
* Tests the JApplicationWeb::getInstance method.
*
Expand Down Expand Up @@ -340,29 +276,6 @@ public function testGetInstanceForUnexistingClass()
JApplicationWeb::getInstance('Foo');
}

/**
* Tests the JApplicationWeb::loadConfiguration method.
*
* @return void
*
* @since 11.3
*/
public function testLoadConfiguration()
{
$this->assertSame(
$this->class, $this->class->loadConfiguration(array('foo' => 'bar')));

$this->assertEquals('bar', TestReflection::getValue($this->class, 'config')->get('foo'), 'Check the configuration array was loaded.');

$this->class->loadConfiguration(
(object) array(
'goo' => 'car',
)
);

$this->assertEquals('car', TestReflection::getValue($this->class, 'config')->get('goo'), 'Check the configuration object was loaded.');
}

/**
* Tests the JApplicationWeb::loadDocument method.
*
Expand Down