From 65845686c41132d8bccd9afb645193dc20f72ca5 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Wed, 10 Dec 2014 17:42:50 +1100 Subject: [PATCH] Fixes unit tests --- .../cms/classes/CmsCompoundObjectTest.php | 21 ++---- tests/unit/cms/classes/CmsExceptionTest.php | 3 +- tests/unit/cms/classes/CmsObjectTest.php | 48 +++++--------- tests/unit/cms/classes/CodeParserTest.php | 15 ++--- .../unit/cms/classes/ComponentManagerTest.php | 3 +- tests/unit/cms/classes/ControllerTest.php | 66 +++++++------------ tests/unit/cms/classes/ThemeTest.php | 6 +- .../unit/system/classes/CombineAssetsTest.php | 3 +- 8 files changed, 55 insertions(+), 110 deletions(-) diff --git a/tests/unit/cms/classes/CmsCompoundObjectTest.php b/tests/unit/cms/classes/CmsCompoundObjectTest.php index 87a6d69b6..d5628d798 100644 --- a/tests/unit/cms/classes/CmsCompoundObjectTest.php +++ b/tests/unit/cms/classes/CmsCompoundObjectTest.php @@ -28,8 +28,7 @@ class CmsCompoundObjectTest extends TestCase { public function testLoadFile() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $obj = TestCmsCompoundObject::load($theme, 'compound.htm'); $this->assertContains("\$controller->data['something'] = 'some value'", $obj->code); @@ -53,8 +52,7 @@ class CmsCompoundObjectTest extends TestCase public function testParseComponentSettings() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $obj = TestCmsCompoundObject::load($theme, 'component.htm'); $this->assertArrayHasKey('components', $obj->settings); @@ -66,8 +64,7 @@ class CmsCompoundObjectTest extends TestCase public function testCache() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $themePath = $theme->getPath(); /* @@ -138,8 +135,7 @@ class CmsCompoundObjectTest extends TestCase public function testUndefinedProperty() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $obj = new TestCmsCompoundObject($theme); $this->assertNull($obj->something); @@ -147,8 +143,7 @@ class CmsCompoundObjectTest extends TestCase public function testSaveMarkup() { - $theme = new Theme(); - $theme->load('apitest'); + $theme = Theme::load('apitest'); $destFilePath = $theme->getPath().'/testobjects/compound-markup.htm'; if (file_exists($destFilePath)) @@ -172,8 +167,7 @@ class CmsCompoundObjectTest extends TestCase public function testSaveMarkupAndSettings() { - $theme = new Theme(); - $theme->load('apitest'); + $theme = Theme::load('apitest'); $destFilePath = $theme->getPath().'/testobjects/compound-markup-settings.htm'; if (file_exists($destFilePath)) @@ -198,8 +192,7 @@ class CmsCompoundObjectTest extends TestCase public function testSaveFull() { - $theme = new Theme(); - $theme->load('apitest'); + $theme = Theme::load('apitest'); $destFilePath = $theme->getPath().'/testobjects/compound.htm'; if (file_exists($destFilePath)) diff --git a/tests/unit/cms/classes/CmsExceptionTest.php b/tests/unit/cms/classes/CmsExceptionTest.php index 22074864d..31736bbdf 100644 --- a/tests/unit/cms/classes/CmsExceptionTest.php +++ b/tests/unit/cms/classes/CmsExceptionTest.php @@ -82,8 +82,7 @@ class CmsExceptionTest extends TestCase public function testCmsExceptionPhp() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $router = new Router($theme); $page = $router->findByUrl('/throw-php'); diff --git a/tests/unit/cms/classes/CmsObjectTest.php b/tests/unit/cms/classes/CmsObjectTest.php index a6fe497e4..f74193b16 100644 --- a/tests/unit/cms/classes/CmsObjectTest.php +++ b/tests/unit/cms/classes/CmsObjectTest.php @@ -23,8 +23,7 @@ class CmsObjectTest extends TestCase { public function testLoad() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $obj = TestCmsObject::load($theme, 'plain.html'); $this->assertEquals('

This is a test HTML content file.

', $obj->getContent()); @@ -37,8 +36,7 @@ class CmsObjectTest extends TestCase public function testLoadFromSubdirectory() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $obj = TestCmsObject::load($theme, 'subdir/obj.html'); $this->assertEquals('

This is an object in a subdirectory.

', $obj->getContent()); @@ -51,24 +49,21 @@ class CmsObjectTest extends TestCase public function testValidateLoadInvalidTheme() { - $theme = new Theme(); - $theme->load('none'); + $theme = Theme::load('none'); $this->assertNull(TestCmsObject::load($theme, 'plain.html')); } public function testValidateLoadInvalidFile() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $this->assertNull(TestCmsObject::load($theme, 'none')); } public function testCache() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $themePath = $theme->getPath(); $filePath = $themePath .= '/temporary/test.htm'; @@ -131,8 +126,7 @@ class CmsObjectTest extends TestCase public function testFillFillable() { - $theme = new Theme(); - $theme->load('apitest'); + $theme = Theme::load('apitest'); $testContents = 'mytestcontent'; $obj = new TestCmsObject($theme); @@ -151,8 +145,7 @@ class CmsObjectTest extends TestCase */ public function testFillNotFillable() { - $theme = new Theme(); - $theme->load('apitest'); + $theme = Theme::load('apitest'); $testContents = 'mytestcontent'; $obj = new TestCmsObject($theme); @@ -168,8 +161,7 @@ class CmsObjectTest extends TestCase */ public function testFillInvalidFileNameSymbol() { - $theme = new Theme(); - $theme->load('apitest'); + $theme = Theme::load('apitest'); $testContents = 'mytestcontent'; $obj = new TestCmsObject($theme); @@ -184,8 +176,7 @@ class CmsObjectTest extends TestCase */ public function testFillInvalidFileNamePath() { - $theme = new Theme(); - $theme->load('apitest'); + $theme = Theme::load('apitest'); $testContents = 'mytestcontent'; $obj = new TestCmsObject($theme); @@ -201,8 +192,7 @@ class CmsObjectTest extends TestCase */ public function testFillInvalidFileSlash() { - $theme = new Theme(); - $theme->load('apitest'); + $theme = Theme::load('apitest'); $testContents = 'mytestcontent'; $obj = new TestCmsObject($theme); @@ -217,8 +207,7 @@ class CmsObjectTest extends TestCase */ public function testFillEmptyFileName() { - $theme = new Theme(); - $theme->load('apitest'); + $theme = Theme::load('apitest'); $testContents = 'mytestcontent'; $obj = new TestCmsObject($theme); @@ -229,8 +218,7 @@ class CmsObjectTest extends TestCase public function testSave() { - $theme = new Theme(); - $theme->load('apitest'); + $theme = Theme::load('apitest'); $destFilePath = $theme->getPath().'/testobjects/mytestobj.htm'; if (file_exists($destFilePath)) @@ -255,8 +243,7 @@ class CmsObjectTest extends TestCase */ public function testRename() { - $theme = new Theme(); - $theme->load('apitest'); + $theme = Theme::load('apitest'); $srcFilePath = $theme->getPath().'/testobjects/mytestobj.htm'; $this->assertFileExists($srcFilePath); @@ -286,8 +273,7 @@ class CmsObjectTest extends TestCase */ public function testRenameToExistingFile() { - $theme = new Theme(); - $theme->load('apitest'); + $theme = Theme::load('apitest'); $srcFilePath = $theme->getPath().'/testobjects/anotherobj.htm'; $this->assertFileExists($srcFilePath); @@ -307,8 +293,7 @@ class CmsObjectTest extends TestCase */ public function testSaveSameName() { - $theme = new Theme(); - $theme->load('apitest'); + $theme = Theme::load('apitest'); $filePath = $theme->getPath().'/testobjects/anotherobj.htm'; $this->assertFileExists($filePath); @@ -328,8 +313,7 @@ class CmsObjectTest extends TestCase public function testSaveNewDir() { - $theme = new Theme(); - $theme->load('apitest'); + $theme = Theme::load('apitest'); $destFilePath = $theme->getPath().'/testobjects/testsubdir/mytestobj.htm'; if (file_exists($destFilePath)) diff --git a/tests/unit/cms/classes/CodeParserTest.php b/tests/unit/cms/classes/CodeParserTest.php index 932e6088d..e87d79e1d 100644 --- a/tests/unit/cms/classes/CodeParserTest.php +++ b/tests/unit/cms/classes/CodeParserTest.php @@ -19,8 +19,7 @@ class CodeParserTest extends TestCase public function testParser() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $layout = Layout::load($theme, 'php-parser-test.htm'); $this->assertNotEmpty($layout); @@ -110,8 +109,7 @@ class CodeParserTest extends TestCase public function testParseNoPhp() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $layout = Layout::load($theme, 'no-php.htm'); $this->assertNotEmpty($layout); @@ -137,8 +135,7 @@ class CodeParserTest extends TestCase public function testParsePage() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $page = Page::load($theme, 'cycle-test.htm'); $this->assertNotEmpty($page); @@ -168,8 +165,7 @@ class CodeParserTest extends TestCase public function testOptionalPhpTags() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); /* * Test short PHP tags @@ -237,8 +233,7 @@ class CodeParserTest extends TestCase public function testNamespaces() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $page = Page::load($theme, 'code-namespaces.htm'); $this->assertNotEmpty($page); diff --git a/tests/unit/cms/classes/ComponentManagerTest.php b/tests/unit/cms/classes/ComponentManagerTest.php index e01814e1b..125181aa4 100644 --- a/tests/unit/cms/classes/ComponentManagerTest.php +++ b/tests/unit/cms/classes/ComponentManagerTest.php @@ -104,8 +104,7 @@ class ComponentManagerTest extends TestCase private function spoofPageCode() { // Spoof all the objects we need to make a page object - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $page = Page::load($theme, 'index.htm'); $layout = Layout::load($theme, 'content.htm'); $controller = new Controller($theme); diff --git a/tests/unit/cms/classes/ControllerTest.php b/tests/unit/cms/classes/ControllerTest.php index c199487ab..16237c22a 100644 --- a/tests/unit/cms/classes/ControllerTest.php +++ b/tests/unit/cms/classes/ControllerTest.php @@ -10,8 +10,7 @@ class ControllerTest extends TestCase /* * Test the built-in 404 page */ - $theme = new Theme(); - $theme->load('apitest'); + $theme = Theme::load('apitest'); $controller = new Controller($theme); $response = $controller->run('/some-page-that-doesnt-exist'); $this->assertNotEmpty($response); @@ -25,8 +24,7 @@ class ControllerTest extends TestCase /* * Test the theme 404 page */ - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/some-page-that-doesnt-exist'); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response); @@ -40,8 +38,7 @@ class ControllerTest extends TestCase /* * Test the / route and the fallback layout */ - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/'); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response); @@ -56,8 +53,7 @@ class ControllerTest extends TestCase */ public function testLayoutNotFound() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/no-layout'); } @@ -67,8 +63,7 @@ class ControllerTest extends TestCase /* * Test existing layout */ - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/with-layout'); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response); @@ -81,8 +76,7 @@ class ControllerTest extends TestCase /* * Test partials referred in the layout and page */ - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/with-partials')->getContent(); $this->assertEquals('
LAYOUT PARTIAL

Hey PAGE PARTIAL Homer Simpson A partial

', $response); @@ -90,8 +84,7 @@ class ControllerTest extends TestCase public function testContent() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/with-content')->getContent(); $this->assertEquals('
LAYOUT CONTENT

Hey PAGE CONTENT A content

', $response); @@ -99,8 +92,7 @@ class ControllerTest extends TestCase public function testBlocks() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/with-placeholder')->getContent(); $this->assertEquals("
LAYOUT CONTENT BLOCK\n DEFAULT

Hey PAGE CONTENT

SECOND BLOCK", $response); @@ -108,8 +100,7 @@ class ControllerTest extends TestCase public function testLayoutInSubdirectory() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/apage')->getContent(); $this->assertEquals("
LAYOUT CONTENT

This page is a subdirectory

", $response); @@ -121,16 +112,14 @@ class ControllerTest extends TestCase */ public function testPartialNotFound() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/no-partial')->getContent(); } public function testPageLifeCycle() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/cycle-test')->getContent(); $this->assertEquals('12345', $response); @@ -158,8 +147,7 @@ class ControllerTest extends TestCase { App::instance('request', $this->configAjaxRequestMock('onNoHandler', '')); - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/ajax-test'); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response); @@ -173,8 +161,7 @@ class ControllerTest extends TestCase { App::instance('request', $this->configAjaxRequestMock('delete')); - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/ajax-test'); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response); @@ -188,8 +175,7 @@ class ControllerTest extends TestCase { App::instance('request', $this->configAjaxRequestMock('onTest', 'p:artial')); - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/ajax-test'); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response); @@ -203,8 +189,7 @@ class ControllerTest extends TestCase { App::instance('request', $this->configAjaxRequestMock('onTest', 'partial')); - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/ajax-test'); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response); @@ -218,8 +203,7 @@ class ControllerTest extends TestCase { App::instance('request', $this->configAjaxRequestMock('onTest', 'ajax-result')); - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/ajax-test'); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response); @@ -236,8 +220,7 @@ class ControllerTest extends TestCase { App::instance('request', $this->configAjaxRequestMock('onTestLayout', 'ajax-result')); - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/ajax-test'); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response); @@ -254,8 +237,7 @@ class ControllerTest extends TestCase { App::instance('request', $this->configAjaxRequestMock('onTest', 'ajax-result&ajax-second-result')); - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/ajax-test'); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response); @@ -272,8 +254,7 @@ class ControllerTest extends TestCase public function testBasicComponents() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/with-component')->getContent(); $page = PHPUnit_Framework_Assert::readAttribute($controller, 'page'); @@ -301,8 +282,7 @@ ESC; { include_once base_path() . '/tests/fixtures/system/plugins/october/tester/components/Archive.php'; - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/with-components')->getContent(); $page = PHPUnit_Framework_Assert::readAttribute($controller, 'page'); @@ -331,8 +311,7 @@ ESC; { App::instance('request', $this->configAjaxRequestMock('testArchive::onTestAjax', 'ajax-result')); - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/with-component'); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response); @@ -347,8 +326,7 @@ ESC; public function testThemeUrl() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $url = $controller->themeUrl(); diff --git a/tests/unit/cms/classes/ThemeTest.php b/tests/unit/cms/classes/ThemeTest.php index c019af495..3c5b65c20 100644 --- a/tests/unit/cms/classes/ThemeTest.php +++ b/tests/unit/cms/classes/ThemeTest.php @@ -30,16 +30,14 @@ class ThemeTest extends TestCase public function testGetPath() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $this->assertEquals(base_path().'/tests/fixtures/cms/themes/test', $theme->getPath()); } public function testListPages() { - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $pages = $theme->listPages(); $this->assertInternalType('array', $pages); diff --git a/tests/unit/system/classes/CombineAssetsTest.php b/tests/unit/system/classes/CombineAssetsTest.php index 0ed46eedb..39b4ede33 100644 --- a/tests/unit/system/classes/CombineAssetsTest.php +++ b/tests/unit/system/classes/CombineAssetsTest.php @@ -167,8 +167,7 @@ class CombineAssetsTest extends TestCase { $this->markTestIncomplete('Unfinished.'); - $theme = new Theme(); - $theme->load('test'); + $theme = Theme::load('test'); $controller = new Controller($theme); $response = $controller->run('/combine/xxxxxxxxx');