Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
Fixed and updated test class for Zepto\Zepto
Browse files Browse the repository at this point in the history
  • Loading branch information
hassankhan committed Feb 4, 2014
1 parent 6788b54 commit 5070eea
Showing 1 changed file with 138 additions and 43 deletions.
181 changes: 138 additions & 43 deletions tests/Zepto/ZeptoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class ZeptoTest extends \PHPUnit_Framework_TestCase
*/
protected function setUp()
{
ob_start();
$_SERVER['DOCUMENT_ROOT'] = '/var/www';
$_SERVER['SCRIPT_FILENAME'] = '/var/www/zepto/index.php';
$_SERVER['SERVER_NAME'] = 'zepto';
Expand All @@ -31,8 +30,6 @@ protected function setUp()
// Change this to a dataprovider
include ROOT_DIR . 'config.php';
$this->config = $config;
ob_end_clean();
// $this->object = new Zepto($this->config);
}

/**
Expand All @@ -41,8 +38,6 @@ protected function setUp()
*/
protected function tearDown()
{
ob_start();
ob_end_clean();
}

/**
Expand All @@ -51,14 +46,54 @@ protected function tearDown()

/**
* @covers Zepto\Zepto::__construct()
* @covers Zepto\Zepto::load_content()
* @covers Zepto\Zepto::create_nav_links()
* @covers Zepto\Zepto::default_config()
* @covers Zepto\Zepto::validate_config()
*/
public function testConstructWithSettings()
{
ob_start();
$config = array(
'zepto' => array(
'environment' => 'prod',
'content_dir' => 'content',
'plugins_dir' => 'plugins',
'templates_dir' => 'templates',
'default_template' => 'base.twig',
'content_ext' => array('.md', '.markdown'),
'plugins_enabled' => true
),
'site' => array(
'site_root' => 'http://www.zepto.com/',
'site_title' => 'Zepto',
'date_format' => 'jS M Y',
'excerpt_length' => '50',
'nav' => array(
'class' => 'nav',
'dropdown_li_class' => 'dropdown',
'dropdown_ul_class' => 'dropdown-menu'
)
),
'twig' => array(
'charset' => 'utf-8',
'cache' => 'cache',
'strict_variables' => false,
'autoescape' => false,
'auto_reload' => true
)
);
$zepto = new Zepto($config);
$this->assertEquals($config, $zepto->container['settings']);
ob_end_clean();
}

/**
* @covers Zepto\Zepto::__construct()
* @covers Zepto\Zepto::default_config()
*/
public function testRouterAdded()
{
ob_start();
$zepto = new Zepto($this->config);
// $zepto = $this->object;
$zepto = new Zepto();
$this->assertArrayHasKey('router', $zepto->container);
$this->assertInstanceOf(
'Zepto\Router',
Expand All @@ -69,14 +104,12 @@ public function testRouterAdded()

/**
* @covers Zepto\Zepto::__construct()
* @covers Zepto\Zepto::load_content()
* @covers Zepto\Zepto::create_nav_links()
* @covers Zepto\Zepto::default_config()
*/
public function testPluginLoaderAdded()
{
ob_start();
$zepto = new Zepto($this->config);
// $zepto = $this->object;
$zepto = new Zepto();
$this->assertArrayHasKey('plugin_loader', $zepto->container);
$this->assertInstanceOf(
'Zepto\FileLoader\PluginLoader',
Expand All @@ -87,32 +120,28 @@ public function testPluginLoaderAdded()

/**
* @covers Zepto\Zepto::__construct()
* @covers Zepto\Zepto::load_content()
* @covers Zepto\Zepto::create_nav_links()
* @covers Zepto\Zepto::default_config()
*/
public function testFileLoaderAdded()
public function testContentLoaderAdded()
{
ob_start();
$zepto = new Zepto($this->config);
// $zepto = $this->object;
$this->assertArrayHasKey('file_loader', $zepto->container);
$zepto = new Zepto();
$this->assertArrayHasKey('content_loader', $zepto->container);
$this->assertInstanceOf(
'Zepto\FileLoader\MarkdownLoader',
$zepto->container['file_loader']
$zepto->container['content_loader']
);
ob_end_clean();
}

/**
* @covers Zepto\Zepto::__construct()
* @covers Zepto\Zepto::load_content()
* @covers Zepto\Zepto::create_nav_links()
* @covers Zepto\Zepto::default_config()
*/
public function testTwigAdded()
{
ob_start();
$zepto = new Zepto($this->config);
// $zepto = $this->object;
$zepto = new Zepto();
$this->assertArrayHasKey('twig', $zepto->container);
$this->assertInstanceOf(
'\Twig_Environment',
Expand All @@ -132,7 +161,7 @@ public function testLoadPlugins()
{
ob_start();
// Add assertion to check if plugins_enabled is true or not
$zepto = new Zepto($this->config);
$zepto = new Zepto();
$this->assertArrayHasKey('plugins', $zepto->container);
$plugins = $zepto->container['plugins'];
$this->assertArrayHasKey('ExamplePlugin', $zepto->container['plugins']);
Expand All @@ -147,7 +176,7 @@ public function testLoadPluginsWhenDisabled()
{
ob_start();
// Add assertion to check if plugins_enabled is true or not
$config = $this->config;
$config = Zepto::default_config();
$config['zepto']['plugins_enabled'] = false;
$zepto = new Zepto($config);
$this->assertArrayNotHasKey('plugins', $zepto->container);
Expand All @@ -161,7 +190,7 @@ public function testLoadPluginsWhenDisabled()
public function testLoadContent()
{
ob_start();
$zepto = new Zepto($this->config);
$zepto = new Zepto();
// $this->markTestIncomplete('Not yet implemented');
ob_end_clean();
}
Expand All @@ -173,31 +202,29 @@ public function testLoadContent()
public function testCreateNavLinks()
{
ob_start();
$zepto = new Zepto($this->config);
$zepto = new Zepto();

$expected = '<ul class="nav">' . PHP_EOL
. '<li><a href="Site root URL goes here/"> Welcome </a></li>' . PHP_EOL
. '<li><a href="http://localhost:8888/zepto/"> Welcome </a></li>' . PHP_EOL
. '<li class="dropdown">' . PHP_EOL
. '<a href="index.md" class="dropdown-toggle" data-toggle="dropdown"> Sub <b class="caret"></b></a>' . PHP_EOL
. '<ul class="dropdown-menu">' . PHP_EOL
. '<li><a href="Site root URL goes here/sub/"> Sub Page Index </a></li>' . PHP_EOL
. '<li><a href="Site root URL goes here/sub/page"> Sub Page </a></li>' . PHP_EOL
. '<li><a href="http://localhost:8888/zepto/sub/"> Sub Page Index </a></li>' . PHP_EOL
. '<li><a href="http://localhost:8888/zepto/sub/page"> Sub Page </a></li>' . PHP_EOL
. '</ul></li>' . PHP_EOL
. '</ul>' . PHP_EOL;

// $zepto = $this->object;
$this->assertEquals(array('nav' => $expected), $zepto->container['nav']);
ob_end_clean();
}

/**
* @covers Zepto\Zepto::router_setup()
* @covers Zepto\Zepto::setup_router()
*/
public function testRouterSetup()
{
ob_start();
$zepto = new Zepto($this->config);
// $zepto = $this->object;
$zepto = new Zepto();
$routes = $zepto->container['router']->routes();

// Check that routes were added as HTTP GET requests
Expand All @@ -207,7 +234,7 @@ public function testRouterSetup()
$expected = array('#^/404/$#', '#^/$#', '#^/sub/$#', '#^/sub/page/$#');

// Check that all routes have a callback function
// $this->assertContainsOnly('Closure', $routes['GET']);
$this->assertContainsOnly('Zepto\Route', $routes['GET']);

foreach ($expected as $route_regex) {
$this->assertArrayHasKey($route_regex, $routes['GET']);
Expand All @@ -222,7 +249,7 @@ public function testRouterSetup()
public function testRun()
{
ob_start();
$zepto = new Zepto($this->config);
$zepto = new Zepto();

// Check to see that the index page has loaded
// Remove the following lines when you implement this test.
Expand All @@ -234,16 +261,84 @@ public function testRun()

/**
* @covers Zepto\Zepto::run_hooks
* @todo Implement testRunHooks().
*/
public function testRunHooks()
{
ob_start();
$zepto = new Zepto($this->config);
// Remove the following lines when you implement this test.
// $this->markTestIncomplete(
// 'This test has not been implemented yet.'
// );
$zepto = new Zepto();
$this->assertTrue($zepto->run_hooks('before_response_send'));
ob_end_clean();
}

/**
* @covers Zepto\Zepto::run_hooks
*/
public function testRunHooksReturnsFalseWhenPluginsAreDisabled()
{
ob_start();
$config = Zepto::default_config();
$config['zepto']['plugins_enabled'] = false;
$zepto = new Zepto($config);
$this->assertFalse($zepto->run_hooks('before_response_send'));
ob_end_clean();
}

/**
* @covers Zepto\Zepto::validate_config()
*/
public function testValidateConfig()
{
ob_start();
$config = Zepto::default_config();
$this->assertTrue(Zepto::validate_config($config));
}

/**
* @covers Zepto\Zepto::validate_config()
* @expectedException InvalidArgumentException
*/
public function testConfigWithInvalidContentDir()
{
ob_start();
$config = Zepto::default_config();
$config['zepto']['content_dir'] = 'no_such_dir';
Zepto::validate_config($config);
}

/**
* @covers Zepto\Zepto::validate_config()
* @expectedException InvalidArgumentException
*/
public function testConfigWithInvalidPluginsDir()
{
ob_start();
$config = Zepto::default_config();
$config['zepto']['plugins_dir'] = 'no_such_dir';
Zepto::validate_config($config);
}

/**
* @covers Zepto\Zepto::validate_config()
* @expectedException InvalidArgumentException
*/
public function testConfigWithInvalidTemplatesDir()
{
ob_start();
$config = Zepto::default_config();
$config['zepto']['templates_dir'] = 'no_such_dir';
Zepto::validate_config($config);
}

/**
* @covers Zepto\Zepto::validate_config()
* @expectedException InvalidArgumentException
*/
public function testConfigWithInvalidSiteRoot()
{
ob_start();
$config = Zepto::default_config();
$config['site']['site_root'] = 'fuck://this@should?fail';
Zepto::validate_config($config);
}

}

0 comments on commit 5070eea

Please sign in to comment.