Skip to content

Commit

Permalink
Merge pull request joomla#1466 from realityking/tests
Browse files Browse the repository at this point in the history
Add additional unit tests.
  • Loading branch information
ianmacl committed Aug 23, 2012
2 parents 3224a4c + b7810c9 commit 1800abc
Show file tree
Hide file tree
Showing 17 changed files with 445 additions and 103 deletions.
2 changes: 1 addition & 1 deletion libraries/joomla/filesystem/stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @see http://php.net/manual/en/transports.php Socket Transports (used by some options, particularly HTTP proxy)
* @since 11.1
*/
class JStream
class JStream extends JObject
{
// Publicly settable vars (protected to let our parent read them)
/**
Expand Down
4 changes: 4 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,9 @@
// Register the core Joomla test classes.
JLoader::registerPrefix('Test', __DIR__ . '/core');

// Some classes still dependen on JVersion
// until that's fixed we need to load it
require_once __DIR__ . '/version.php';

// We need this to test JSession
ob_start();
34 changes: 33 additions & 1 deletion tests/suites/unit/joomla/access/JAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ protected function getDataSet()
* @return void
*
* @since 11.1
* @covers JAccess::getAuthorisedViewLevels
*/
public function testGetAuthorisedViewLevels()
{
Expand Down Expand Up @@ -229,6 +230,7 @@ function casesCheck()
*
* @since 11.1
* @dataProvider casesCheck()
* @covers JAccess::check
*/
public function testCheck($userId, $action, $assetId, $result, $message)
{
Expand Down Expand Up @@ -310,7 +312,7 @@ function casesCheckGroup()
}

/**
* Tests the JAccess::checkGroups method.
* Tests the JAccess::checkGroup method.
*
* @param integer group id
* @param string action to test
Expand All @@ -322,6 +324,7 @@ function casesCheckGroup()
*
* @since 11.1
* @dataProvider casesCheckGroup()
* @covers JAccess::checkGroup
*/
public function testCheckGroup($groupId, $action, $assetId, $result, $message)
{
Expand All @@ -338,6 +341,7 @@ public function testCheckGroup($groupId, $action, $assetId, $result, $message)
* @return void
*
* @since 11.1
* @covers JAccess::getAssetRules
*/
public function testGetAssetRulesValidTrue()
{
Expand All @@ -350,6 +354,10 @@ public function testGetAssetRulesValidTrue()
'Recursive rules from a valid asset. Line: ' . __LINE__
);
}

/**
* @covers JAccess::getAssetRules
*/
public function testGetAssetRulesValidFalse()
{
$access = new JAccess();
Expand All @@ -361,6 +369,10 @@ public function testGetAssetRulesValidFalse()
'Non recursive rules from a valid asset. Line: ' . __LINE__
);
}

/**
* @covers JAccess::getAssetRules
*/
public function testGetAssetRulesInvalidFalse()
{
$access = new JAccess();
Expand All @@ -372,6 +384,10 @@ public function testGetAssetRulesInvalidFalse()
'Invalid asset uses rule from root. Line: ' . __LINE__
);
}

/**
* @covers JAccess::getAssetRules
*/
public function testGetAssetRulesTextFalse()
{
$access = new JAccess();
Expand All @@ -383,6 +399,10 @@ public function testGetAssetRulesTextFalse()
'Invalid asset uses rule from root. Line: ' . __LINE__
);
}

/**
* @covers JAccess::getAssetRules
*/
public function testGetAssetRulesTextTrue()
{
$access = new JAccess();
Expand All @@ -401,6 +421,7 @@ public function testGetAssetRulesTextTrue()
* @return void
*
* @since 11.1
* @covers JAccess::getUsersByGroup
*/
public function testGetUsersByGroupSimple()
{
Expand All @@ -414,6 +435,10 @@ public function testGetUsersByGroupSimple()
'Get one user. Line: ' . __LINE__
);
}

/**
* @covers JAccess::getUsersByGroup
*/
public function testGetUsersByGroupTwoUsers()
{
$access = new JAccess();
Expand All @@ -429,6 +454,10 @@ public function testGetUsersByGroupTwoUsers()
'Get multiple users. Line: ' . __LINE__
);
}

/**
* @covers JAccess::getUsersByGroup
*/
public function testGetUsersByGroupInvalidGroup()
{
$access = new JAccess();
Expand All @@ -447,6 +476,7 @@ public function testGetUsersByGroupInvalidGroup()
* @return void
*
* @since 11.1
* @covers JAccess::getGroupsByUser
*/
public function testGetGroupsByUser()
{
Expand Down Expand Up @@ -562,6 +592,7 @@ public function casesGetActionsFromData()
* @since 12.1
*
* @dataProvider casesGetActionsFromData
* @covers JAccess::getActionsFromData
*/
public function testGetActionsFromData($data, $xpath, $expected, $msg)
{
Expand All @@ -578,6 +609,7 @@ public function testGetActionsFromData($data, $xpath, $expected, $msg)
* @return void
*
* @since 12.1
* @covers JAccess::getActionsFromFile
*/
public function testGetActionsFromFile()
{
Expand Down
21 changes: 21 additions & 0 deletions tests/suites/unit/joomla/access/JRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public function test__constructString()
'Checks input as an string.'
);
}

/**
* @covers JAccessRules::__construct
* @covers JAccessRules::__toString
*/
public function test__constructArray()
{
$array = array(
Expand All @@ -64,6 +69,11 @@ public function test__constructArray()
'Checks input as an array.'
);
}

/**
* @covers JAccessRules::__construct
* @covers JAccessRules::__toString
*/
public function test__constructObject()
{
$array = array(
Expand Down Expand Up @@ -196,6 +206,9 @@ public function testMerge()
);
}

/**
* @covers JAccessRules::merge
*/
public function testMergeArray()
{
$array1 = array(
Expand All @@ -216,6 +229,10 @@ public function testMergeArray()
'Input as a array'
);
}

/**
* @covers JAccessRules::merge
*/
public function testMergeRulesNull()
{
$array1 = array(
Expand All @@ -238,6 +255,10 @@ public function testMergeRulesNull()
'Merge by JRules where second rules are empty'
);
}

/**
* @covers JAccessRules::merge
*/
public function testMergeRules()
{
$array1 = array(
Expand Down
29 changes: 25 additions & 4 deletions tests/suites/unit/joomla/archive/JArchiveBzip2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
* @license GNU General Public License version 2 or later; see LICENSE
*/

include_once JPATH_PLATFORM . '/joomla/archive/bzip2.php';

/**
* Test class for JArchiveBzip2.
* Generated by PHPUnit on 2011-10-26 at 19:34:29.
*/
class JArchiveBzip2Test extends PHPUnit_Framework_TestCase {
class JArchiveBzip2Test extends PHPUnit_Framework_TestCase
{
protected static $outputPath;

/**
Expand Down Expand Up @@ -48,6 +47,7 @@ protected function tearDown() {
*
* @group JArchive
* @return void
* @covers JArchiveBzip2::extract
*/
public function testExtract()
{
Expand All @@ -66,6 +66,27 @@ public function testExtract()
}
}

/**
* Tests the extract Method.
*
* @group JArchive
* @return JArchiveBzip2::extract
*/
public function testExtractWithStreams()
{
if (!JArchiveBzip2::isSupported())
{
$this->markTestSkipped('Bzip2 files can not be extracted.');
return;
}

$this->object->extract(__DIR__ . '/logo.bz2', self::$outputPath . '/logo-bz2.png', array('use_streams' => true));
$this->assertTrue(is_file(self::$outputPath . '/logo-bz2.png'));

if (is_file(self::$outputPath . '/logo-bz2.png'))
{
unlink(self::$outputPath . '/logo-bz2.png');
}
}
}

?>
28 changes: 24 additions & 4 deletions tests/suites/unit/joomla/archive/JArchiveGzipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* @license GNU General Public License version 2 or later; see LICENSE
*/

include_once JPATH_PLATFORM . '/joomla/archive/gzip.php';

/**
* Test class for JArchiveGzip.
* Generated by PHPUnit on 2011-10-26 at 19:34:32.
Expand Down Expand Up @@ -49,6 +47,7 @@ protected function tearDown() {
*
* @group JArchive
* @return void
* @covers JArchiveGzip::extract
*/
public function testExtract() {
if (!JArchiveGzip::isSupported())
Expand All @@ -66,6 +65,29 @@ public function testExtract() {
}
}

/**
* Tests the extract Method.
*
* @group JArchive
* @return void
* @covers JArchiveGzip::extract
*/
public function testExtractWithStreams() {
if (!JArchiveGzip::isSupported())
{
$this->markTestSkipped('Gzip files can not be extracted.');
return;
}

$this->object->extract(__DIR__ . '/logo.gz', self::$outputPath . '/logo-gz.png', array('use_streams' => true));
$this->assertTrue(is_file(self::$outputPath . '/logo-gz.png'));

if (is_file(self::$outputPath . '/logo-gz.png'))
{
unlink(self::$outputPath . '/logo-gz.png');
}
}

/**
* @todo Implement test_getFilePosition().
*/
Expand All @@ -77,5 +99,3 @@ public function test_getFilePosition() {
}

}

?>
12 changes: 5 additions & 7 deletions tests/suites/unit/joomla/archive/JArchiveTarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @license GNU General Public License version 2 or later; see LICENSE
*/

include_once JPATH_PLATFORM . '/joomla/archive/tar.php';

/**
* Test class for JArchiveTar.
Expand All @@ -25,7 +24,8 @@ class JArchiveTarTest extends PHPUnit_Framework_TestCase
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp() {
protected function setUp()
{
self::$outputPath = __DIR__ . '/output';

if (!is_dir(self::$outputPath)) {
Expand All @@ -39,15 +39,16 @@ protected function setUp() {
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown() {

protected function tearDown()
{
}

/**
* Tests the extract Method.
*
* @group JArchive
* @return void
* @covers JArchiveTar::extract
*/
public function testExtract() {
if (!JArchiveTar::isSupported())
Expand All @@ -64,7 +65,4 @@ public function testExtract() {
unlink(self::$outputPath . '/logo-tar.png');
}
}

}

?>
Loading

0 comments on commit 1800abc

Please sign in to comment.