Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
98 additions
and
0 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,98 @@ | ||
<?php | ||
/** | ||
* PHP.Gt (http://php.gt) | ||
* @copyright Copyright Ⓒ 2014 Bright Flair Ltd. (http://brightflair.com) | ||
* @license Apache Version 2.0, January 2004. http://www.apache.org/licenses | ||
*/ | ||
namespace Gt\Logic; | ||
|
||
use \Gt\Core\Path; | ||
use \Gt\Request\Request; | ||
|
||
class LogicFactory_Test extends \PHPUnit_Framework_TestCase { | ||
|
||
private $uriList = [ | ||
"/index", | ||
"/test-page", | ||
"/directory/inner-page", | ||
"/directory/subdirectory/nested-page", | ||
]; | ||
private $apiFactory; | ||
private $dbFactory; | ||
|
||
public function setUp() { | ||
$_SERVER["DOCUMENT_ROOT"] = sys_get_temp_dir() . "/www"; | ||
|
||
$cfg = $this->getMock("\Gt\Core\ConfigObj"); | ||
$this->apiFactory = $this->getMock("\Gt\Api\ApiFactory", null, [$cfg]); | ||
$this->dbFactory = $this->getMock("\Gt\Database\DatabaseFactory", null, [ | ||
$cfg | ||
]); | ||
} | ||
|
||
public function tearDown() { | ||
|
||
} | ||
|
||
public function data_uri() { | ||
$return = []; | ||
|
||
foreach ($this->uriList as $uri) { | ||
$return []= [$uri]; | ||
} | ||
|
||
return $return; | ||
} | ||
|
||
/** | ||
* @dataProvider data_uri | ||
*/ | ||
public function testGetLogicFileArrayGivesCommons($uri) { | ||
$topPath = Path::get(Path::PAGELOGIC); | ||
$filename = basename($uri); | ||
$path = pathinfo($topPath . $uri, PATHINFO_DIRNAME); | ||
|
||
$logicFileArray = LogicFactory::getLogicFileArray( | ||
$filename, | ||
$path, | ||
$topPath | ||
); | ||
|
||
$directory = dirname($topPath . $uri); | ||
$commonPath = $directory . "/_common.php"; | ||
|
||
$this->assertContains($commonPath, $logicFileArray); | ||
} | ||
|
||
/** | ||
* @dataProvider data_uri | ||
*/ | ||
public function testGetLogicFileArray($uri) { | ||
$topPath = Path::get(Path::PAGELOGIC); | ||
$filename = basename($uri); | ||
$path = pathinfo($topPath . $uri, PATHINFO_DIRNAME); | ||
|
||
$logicFileArray = LogicFactory::getLogicFileArray( | ||
$filename, | ||
$path, | ||
$topPath | ||
); | ||
|
||
// Assert that there is a _Common Page Logic class filename for each | ||
// directory, plus the name of the requested file. | ||
$directoryCount = substr_count($uri, "/"); | ||
$this->assertCount($directoryCount + 1, $logicFileArray); | ||
} | ||
|
||
// public function testCreatesPageLogicForTestPage($uri) { | ||
// $logicList = LogicFactory::create( | ||
// "TestApp", | ||
// $uri, | ||
// Request::TYPE_PAGE, | ||
// $this->apiFactory, | ||
// $this->dbFactory, | ||
// $this->content | ||
// ); | ||
// } | ||
|
||
}# |