forked from joomla/joomla-platform
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added JRules mock; improved code coverage of JRules; fixed code
formatting in JRule and JRules test files.
- Loading branch information
Andrew Eddie
committed
Oct 21, 2011
1 parent
a34b024
commit 2960cf1
Showing
3 changed files
with
181 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
/** | ||
* @package Joomla.UnitTest | ||
* @copyright Copyright (C) 2005 - 2011 Open Source Matters. All rights reserved. | ||
* @license GNU General Public License | ||
*/ | ||
|
||
/** | ||
* Mock class for JRules. | ||
* | ||
* @package Joomla.UnitTest | ||
* @since 11.3 | ||
*/ | ||
class JRulesGlobalMock | ||
{ | ||
/** | ||
* Creates an instance of the mock JDatabase object. | ||
* | ||
* @param object $test A test object. | ||
* | ||
* @return object | ||
* | ||
* @since 11.3 | ||
*/ | ||
public static function create($test) | ||
{ | ||
// Mock all the public methods. | ||
$methods = array( | ||
'allow', | ||
); | ||
|
||
// Create the mock. | ||
$mockObject = $test->getMock( | ||
'JRules', | ||
$methods, | ||
// Constructor arguments. | ||
array(), | ||
// Mock class name. | ||
'', | ||
// Call original constructor. | ||
false | ||
); | ||
|
||
$test->assignMockCallbacks( | ||
$mockObject, | ||
array( | ||
'allow' => array(get_called_class(), 'mockAllow'), | ||
) | ||
); | ||
|
||
return $mockObject; | ||
} | ||
|
||
/** | ||
* Mocking the allow method. | ||
* | ||
* @param string $action The action. | ||
* | ||
* @return mixed Boolean or null. | ||
* | ||
* @since 11.3 | ||
*/ | ||
public function mockAllow($action, $identity) | ||
{ | ||
switch ($action) | ||
{ | ||
case 'run': | ||
if ($identity == 0) | ||
{ | ||
return null; | ||
} | ||
else | ||
{ | ||
// Odds return true, evens false. | ||
return (boolean) ($identity % 2); | ||
} | ||
return false; | ||
|
||
case 'walk': | ||
if ($identity == 0) | ||
{ | ||
return null; | ||
} | ||
else | ||
{ | ||
// Odds return false, evens true. | ||
return (boolean) (1 - ($identity % 2)); | ||
} | ||
|
||
default: | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters