diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 59c9d04..886eebf 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -8,5 +8,6 @@ require_once realpath(__DIR__ . '/../vendor/autoload.php'); + // Usually, this would be defined in ``Zepto\Zepto->container['ROOT_DIR'] defined('ROOT_DIR') || define('ROOT_DIR', realpath(dirname(__FILE__) . '/..') . '/'); diff --git a/tests/Zepto/HelperTest.php b/tests/Zepto/HelperTest.php new file mode 100644 index 0000000..cc40ea4 --- /dev/null +++ b/tests/Zepto/HelperTest.php @@ -0,0 +1,163 @@ +helper = new Helper($zepto->app); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + /** + * @covers Zepto\Helper::default_config + */ + public function testDefaultConfig() + { + $expected = array( + 'zepto' => array( + 'environment' => 'dev', + '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://localhost:8888/zepto/', + '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 + ) + ); + $this->assertEquals($expected, Helper::default_config()); + } + + /** + * @covers Zepto\Helper::validate_config() + */ + public function testValidateConfig() + { + ob_start(); + $config = Helper::default_config(); + $this->assertTrue(Helper::validate_config($config)); + } + + /** + * @covers Zepto\Helper::validate_config() + * @expectedException InvalidArgumentException + */ + public function testConfigWithInvalidContentDir() + { + ob_start(); + $config = Helper::default_config(); + $config['zepto']['content_dir'] = 'no_such_dir'; + Helper::validate_config($config); + } + + /** + * @covers Zepto\Helper::validate_config() + * @expectedException InvalidArgumentException + */ + public function testConfigWithInvalidPluginsDir() + { + ob_start(); + $config = Helper::default_config(); + $config['zepto']['plugins_dir'] = 'no_such_dir'; + Helper::validate_config($config); + } + + /** + * @covers Zepto\Helper::validate_config() + * @expectedException InvalidArgumentException + */ + public function testConfigWithInvalidTemplatesDir() + { + ob_start(); + $config = Helper::default_config(); + $config['zepto']['templates_dir'] = 'no_such_dir'; + Helper::validate_config($config); + } + + /** + * @covers Zepto\Helper::validate_config() + * @expectedException InvalidArgumentException + */ + public function testConfigWithInvalidDefaultTemplate() + { + ob_start(); + $config = Helper::default_config(); + $config['zepto']['default_template'] = 'no_such_file'; + Helper::validate_config($config); + } + + /** + * @covers Zepto\Helper::validate_config() + * @expectedException InvalidArgumentException + */ + public function testConfigWithInvalidSiteRoot() + { + ob_start(); + $config = Helper::default_config(); + $config['zepto']['environment'] = 'production'; + $config['site']['site_root'] = 'fuck://this@should?fail'; + Helper::validate_config($config); + } + + /** + * @covers Zepto\Helper::url_for + * @todo Implement testUrl_for(). + */ + public function testUrl_for() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers Zepto\Helper::link_for + * @todo Implement testLink_for(). + */ + public function testLink_for() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} diff --git a/tests/Zepto/ZeptoTest.php b/tests/Zepto/ZeptoTest.php index 5b8cab8..9500acf 100644 --- a/tests/Zepto/ZeptoTest.php +++ b/tests/Zepto/ZeptoTest.php @@ -46,8 +46,6 @@ protected function tearDown() /** * @covers Zepto\Zepto::__construct() - * @covers Zepto\Zepto::default_config() - * @covers Zepto\Zepto::validate_config() */ public function testConstructWithSettings() { @@ -82,70 +80,66 @@ public function testConstructWithSettings() ) ); $zepto = new Zepto($config); - $this->assertEquals($config, $zepto->container['settings']); + $this->assertEquals($config, $zepto->app['settings']); ob_end_clean(); } /** * @covers Zepto\Zepto::__construct() - * @covers Zepto\Zepto::default_config() */ public function testRouterAdded() { ob_start(); $zepto = new Zepto(); - $this->assertArrayHasKey('router', $zepto->container); + $this->assertArrayHasKey('router', $zepto->app); $this->assertInstanceOf( 'Zepto\Router', - $zepto->container['router'] + $zepto->app['router'] ); ob_end_clean(); } /** * @covers Zepto\Zepto::__construct() - * @covers Zepto\Zepto::default_config() */ public function testPluginLoaderAdded() { ob_start(); $zepto = new Zepto(); - $this->assertArrayHasKey('plugin_loader', $zepto->container); + $this->assertArrayHasKey('plugin_loader', $zepto->app); $this->assertInstanceOf( 'Zepto\FileLoader\PluginLoader', - $zepto->container['plugin_loader'] + $zepto->app['plugin_loader'] ); ob_end_clean(); } /** * @covers Zepto\Zepto::__construct() - * @covers Zepto\Zepto::default_config() */ public function testContentLoaderAdded() { ob_start(); $zepto = new Zepto(); - $this->assertArrayHasKey('content_loader', $zepto->container); + $this->assertArrayHasKey('content_loader', $zepto->app); $this->assertInstanceOf( 'Zepto\FileLoader\MarkdownLoader', - $zepto->container['content_loader'] + $zepto->app['content_loader'] ); ob_end_clean(); } /** * @covers Zepto\Zepto::__construct() - * @covers Zepto\Zepto::default_config() */ public function testTwigAdded() { ob_start(); $zepto = new Zepto(); - $this->assertArrayHasKey('twig', $zepto->container); + $this->assertArrayHasKey('twig', $zepto->app); $this->assertInstanceOf( '\Twig_Environment', - $zepto->container['twig'] + $zepto->app['twig'] ); ob_end_clean(); } @@ -162,10 +156,10 @@ public function testLoadPlugins() ob_start(); // Add assertion to check if plugins_enabled is true or not $zepto = new Zepto(); - $this->assertArrayHasKey('plugins', $zepto->container); - $plugins = $zepto->container['plugins']; - $this->assertArrayHasKey('ExamplePlugin', $zepto->container['plugins']); - $this->assertArrayHasKey('OtherExamplePlugin', $zepto->container['plugins']); + $this->assertArrayHasKey('plugins', $zepto->app); + $plugins = $zepto->app['plugins']; + $this->assertArrayHasKey('ExamplePlugin', $zepto->app['plugins']); + $this->assertArrayHasKey('OtherExamplePlugin', $zepto->app['plugins']); ob_end_clean(); } @@ -176,37 +170,10 @@ public function testLoadPluginsWhenDisabled() { ob_start(); // Add assertion to check if plugins_enabled is true or not - $config = Zepto::default_config(); + $config = Helper::default_config(); $config['zepto']['plugins_enabled'] = false; $zepto = new Zepto($config); - $this->assertArrayNotHasKey('plugins', $zepto->container); - ob_end_clean(); - } - - /** - * @covers Zepto\Zepto::create_nav_links() - * @covers Zepto\Zepto::generate_nav_html() - */ - public function testCreateNavLinks() - { - ob_start(); - $zepto = new Zepto(); - - $expected = '' . PHP_EOL; - - - // $this->assertEquals(array('nav' => $expected), $zepto->container['nav']); - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->assertArrayNotHasKey('plugins', $zepto->app); ob_end_clean(); } @@ -217,7 +184,7 @@ public function testRouterSetup() { ob_start(); $zepto = new Zepto(); - $routes = $zepto->container['router']->routes(); + $routes = $zepto->app['router']->routes(); // Check that routes were added as HTTP GET requests $this->assertArrayHasKey('GET', $routes); @@ -268,81 +235,11 @@ public function testRunHooks() public function testRunHooksReturnsFalseWhenPluginsAreDisabled() { ob_start(); - $config = Zepto::default_config(); + $config = Helper::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 testConfigWithInvalidDefaultTemplate() - { - ob_start(); - $config = Zepto::default_config(); - $config['zepto']['default_template'] = 'no_such_file'; - 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); - } - }