Update tests with minor API changes for Halcyon implementation

This commit is contained in:
Samuel Georges 2016-03-17 07:58:42 +11:00
parent 864d38b77e
commit 8e3ff0c700
9 changed files with 77 additions and 61 deletions

View File

@ -187,7 +187,7 @@ abstract class PluginTestCase extends Illuminate\Foundation\Testing\TestCase
{ {
$reflect = new ReflectionClass($this); $reflect = new ReflectionClass($this);
$path = $reflect->getFilename(); $path = $reflect->getFilename();
$basePath = plugins_path(); $basePath = $this->app->pluginsPath();
$result = false; $result = false;

View File

@ -6,26 +6,26 @@ use Cms\Classes\CmsCompoundObject;
class TestCmsCompoundObject extends CmsCompoundObject class TestCmsCompoundObject extends CmsCompoundObject
{ {
protected function parseSettings() {} protected $dirName = 'testobjects';
public static function getObjectTypeDirName() protected function parseSettings() {}
{
return 'testobjects';
}
} }
class TestTemporaryCmsCompoundObject extends CmsCompoundObject class TestTemporaryCmsCompoundObject extends CmsCompoundObject
{ {
protected function parseSettings() {} protected $dirName = 'temporary';
public static function getObjectTypeDirName() protected function parseSettings() {}
{
return 'temporary';
}
} }
class CmsCompoundObjectTest extends TestCase class CmsCompoundObjectTest extends TestCase
{ {
public function tearDown()
{
parent::tearDown();
TestCmsCompoundObject::flushEventListeners();
}
public function testLoadFile() public function testLoadFile()
{ {
$theme = Theme::load('test'); $theme = Theme::load('test');
@ -159,9 +159,7 @@ class CmsCompoundObjectTest extends TestCase
public function testUndefinedProperty() public function testUndefinedProperty()
{ {
$theme = Theme::load('test'); $obj = new TestCmsCompoundObject;
$obj = new TestCmsCompoundObject($theme);
$this->assertNull($obj->something); $this->assertNull($obj->something);
} }
@ -175,7 +173,7 @@ class CmsCompoundObjectTest extends TestCase
$this->assertFileNotExists($destFilePath); $this->assertFileNotExists($destFilePath);
$obj = new TestCmsCompoundObject($theme); $obj = TestCmsCompoundObject::inTheme($theme);
$obj->fill([ $obj->fill([
'markup' => '<p>Hello, world!</p>', 'markup' => '<p>Hello, world!</p>',
'fileName'=>'compound-markup' 'fileName'=>'compound-markup'
@ -199,7 +197,7 @@ class CmsCompoundObjectTest extends TestCase
$this->assertFileNotExists($destFilePath); $this->assertFileNotExists($destFilePath);
$obj = new TestCmsCompoundObject($theme); $obj = TestCmsCompoundObject::inTheme($theme);
$obj->fill([ $obj->fill([
'settings'=>['var'=>'value'], 'settings'=>['var'=>'value'],
'markup' => '<p>Hello, world!</p>', 'markup' => '<p>Hello, world!</p>',
@ -225,7 +223,7 @@ class CmsCompoundObjectTest extends TestCase
$this->assertFileNotExists($destFilePath); $this->assertFileNotExists($destFilePath);
$obj = new TestCmsCompoundObject($theme); $obj = TestCmsCompoundObject::inTheme($theme);
$obj->fill([ $obj->fill([
'fileName'=>'compound', 'fileName'=>'compound',
'settings'=>['var'=>'value'], 'settings'=>['var'=>'value'],

View File

@ -67,7 +67,7 @@ class CmsExceptionTest extends TestCase
$exception = new CmsException($page, 300); $exception = new CmsException($page, 300);
$exception->setMask($foreignException); $exception->setMask($foreignException);
$this->assertEquals($page->getFullPath(), $exception->getFile()); $this->assertEquals($page->getFilePath(), $exception->getFile());
$this->assertEquals('PHP Content', $exception->getErrorType()); $this->assertEquals('PHP Content', $exception->getErrorType());
$this->assertEquals('This is a general error', $exception->getMessage()); $this->assertEquals('This is a general error', $exception->getMessage());
} }

View File

@ -1,10 +1,21 @@
<?php <?php
use Cms\Classes\Page; use Cms\Classes\Page;
use Cms\Classes\Theme;
use Cms\Classes\Layout; use Cms\Classes\Layout;
class CmsObjectQueryTest extends TestCase class CmsObjectQueryTest extends TestCase
{ {
public function setUp()
{
parent::setUp();
// Register theme with Halcyon
Theme::load('test');
TestCmsCompoundObject::flushEventListeners();
}
public function testWhere() public function testWhere()
{ {
$page = Page::where('layout', 'caramba')->first(); $page = Page::where('layout', 'caramba')->first();
@ -90,7 +101,10 @@ class CmsObjectQueryTest extends TestCase
"placeholder", "placeholder",
"sidebar", "sidebar",
], $layouts); ], $layouts);
}
public function testListsNonExistentTheme()
{
$pages = Page::inTheme('NON_EXISTENT_THEME')->lists('baseFileName'); $pages = Page::inTheme('NON_EXISTENT_THEME')->lists('baseFileName');
$this->assertEmpty($pages); $this->assertEmpty($pages);
} }

View File

@ -5,18 +5,12 @@ use Cms\Classes\Theme;
class TestCmsObject extends CmsObject class TestCmsObject extends CmsObject
{ {
public static function getObjectTypeDirName() protected $dirName = 'testobjects';
{
return 'testobjects';
}
} }
class TestTemporaryCmsObject extends CmsObject class TestTemporaryCmsObject extends CmsObject
{ {
public static function getObjectTypeDirName() protected $dirName = 'temporary';
{
return 'temporary';
}
} }
class CmsObjectTest extends TestCase class CmsObjectTest extends TestCase
@ -30,7 +24,7 @@ class CmsObjectTest extends TestCase
$this->assertEquals('plain.html', $obj->getFileName()); $this->assertEquals('plain.html', $obj->getFileName());
$path = $theme->getPath().'/testobjects/plain.html'; $path = $theme->getPath().'/testobjects/plain.html';
$this->assertEquals($path, $obj->getFullPath()); $this->assertEquals($path, $obj->getFilePath());
$this->assertEquals(filemtime($path), $obj->mtime); $this->assertEquals(filemtime($path), $obj->mtime);
} }
@ -43,7 +37,7 @@ class CmsObjectTest extends TestCase
$this->assertEquals('subdir/obj.html', $obj->getFileName()); $this->assertEquals('subdir/obj.html', $obj->getFileName());
$path = $theme->getPath().'/testobjects/subdir/obj.html'; $path = $theme->getPath().'/testobjects/subdir/obj.html';
$this->assertEquals($path, $obj->getFullPath()); $this->assertEquals($path, $obj->getFilePath());
$this->assertEquals(filemtime($path), $obj->mtime); $this->assertEquals(filemtime($path), $obj->mtime);
} }
@ -129,30 +123,28 @@ class CmsObjectTest extends TestCase
$theme = Theme::load('apitest'); $theme = Theme::load('apitest');
$testContents = 'mytestcontent'; $testContents = 'mytestcontent';
$obj = new TestCmsObject($theme); $obj = TestCmsObject::inTheme($theme);
$obj->fill([ $obj->fill([
'fileName'=>'mytestobj', 'fileName' => 'mytestobj',
'content'=>$testContents 'content' => $testContents
]); ]);
$this->assertEquals($testContents, $obj->getContent()); $this->assertEquals($testContents, $obj->getContent());
$this->assertEquals('mytestobj.htm', $obj->getFileName()); $this->assertEquals('mytestobj.htm', $obj->getFileName());
} }
/**
* @expectedException \October\Rain\Exception\ApplicationException
* @expectedExceptionMessage The property 'something' cannot be set
*/
public function testFillNotFillable() public function testFillNotFillable()
{ {
$theme = Theme::load('apitest'); $theme = Theme::load('apitest');
$testContents = 'mytestcontent'; $testContents = 'mytestcontent';
$obj = new TestCmsObject($theme); $obj = TestCmsObject::inTheme($theme);
$obj->fill([ $obj->fill([
'something'=>'mytestobj', 'something' => 'mytestobj',
'content'=>$testContents 'content' => $testContents
]); ]);
$this->assertNull($obj->something);
} }
/** /**
@ -164,10 +156,11 @@ class CmsObjectTest extends TestCase
$theme = Theme::load('apitest'); $theme = Theme::load('apitest');
$testContents = 'mytestcontent'; $testContents = 'mytestcontent';
$obj = new TestCmsObject($theme); $obj = TestCmsObject::inTheme($theme);
$obj->fill([ $obj->fill([
'fileName'=>'@name' 'fileName' => '@name'
]); ]);
$obj->save();
} }
/** /**
@ -179,13 +172,13 @@ class CmsObjectTest extends TestCase
$theme = Theme::load('apitest'); $theme = Theme::load('apitest');
$testContents = 'mytestcontent'; $testContents = 'mytestcontent';
$obj = new TestCmsObject($theme); $obj = TestCmsObject::inTheme($theme);
$obj->fill([ $obj->fill([
'fileName'=>'../somefile' 'fileName' => '../somefile'
]); ]);
$obj->save();
} }
/** /**
* @expectedException \October\Rain\Exception\ValidationException * @expectedException \October\Rain\Exception\ValidationException
* @expectedExceptionMessage Invalid file name * @expectedExceptionMessage Invalid file name
@ -195,10 +188,11 @@ class CmsObjectTest extends TestCase
$theme = Theme::load('apitest'); $theme = Theme::load('apitest');
$testContents = 'mytestcontent'; $testContents = 'mytestcontent';
$obj = new TestCmsObject($theme); $obj = TestCmsObject::inTheme($theme);
$obj->fill([ $obj->fill([
'fileName'=>'/somefile' 'fileName' => '/somefile'
]); ]);
$obj->save();
} }
/** /**
@ -210,10 +204,11 @@ class CmsObjectTest extends TestCase
$theme = Theme::load('apitest'); $theme = Theme::load('apitest');
$testContents = 'mytestcontent'; $testContents = 'mytestcontent';
$obj = new TestCmsObject($theme); $obj = TestCmsObject::inTheme($theme);
$obj->fill([ $obj->fill([
'fileName'=>' ' 'fileName' => ' '
]); ]);
$obj->save();
} }
public function testSave() public function testSave()
@ -227,10 +222,10 @@ class CmsObjectTest extends TestCase
$this->assertFileNotExists($destFilePath); $this->assertFileNotExists($destFilePath);
$testContents = 'mytestcontent'; $testContents = 'mytestcontent';
$obj = new TestCmsObject($theme); $obj = TestCmsObject::inTheme($theme);
$obj->fill([ $obj->fill([
'fileName'=>'mytestobj', 'fileName' => 'mytestobj',
'content'=>$testContents 'content' => $testContents
]); ]);
$obj->save(); $obj->save();
@ -257,7 +252,7 @@ class CmsObjectTest extends TestCase
$this->assertEquals($testContents, $obj->getContent()); $this->assertEquals($testContents, $obj->getContent());
$obj->fill([ $obj->fill([
'fileName'=>'anotherobj' 'fileName' => 'anotherobj'
]); ]);
$obj->save(); $obj->save();
@ -284,7 +279,7 @@ class CmsObjectTest extends TestCase
$this->assertFileExists($destFilePath); $this->assertFileExists($destFilePath);
$obj = TestCmsObject::load($theme, 'anotherobj.htm'); $obj = TestCmsObject::load($theme, 'anotherobj.htm');
$obj->fill(['fileName'=>'existingobj']); $obj->fill(['fileName' => 'existingobj']);
$obj->save(); $obj->save();
} }
@ -302,8 +297,8 @@ class CmsObjectTest extends TestCase
$obj = TestCmsObject::load($theme, 'anotherobj.htm'); $obj = TestCmsObject::load($theme, 'anotherobj.htm');
$obj->fill([ $obj->fill([
'fileName'=>'anotherobj', 'fileName' => 'anotherobj',
'content'=>$testContents 'content' => $testContents
]); ]);
$obj->save(); $obj->save();
@ -327,10 +322,10 @@ class CmsObjectTest extends TestCase
$this->assertFileNotExists($destDirPath); $this->assertFileNotExists($destDirPath);
$testContents = 'mytestcontent'; $testContents = 'mytestcontent';
$obj = new TestCmsObject($theme); $obj = TestCmsObject::inTheme($theme);
$obj->fill([ $obj->fill([
'fileName'=>'testsubdir/mytestobj.htm', 'fileName' => 'testsubdir/mytestobj.htm',
'content'=>$testContents 'content' => $testContents
]); ]);
$obj->save(); $obj->save();

View File

@ -95,7 +95,7 @@ class CodeParserTest extends TestCase
* Test caching - update the file modification time and reset the internal cache. The file should be parsed. * Test caching - update the file modification time and reset the internal cache. The file should be parsed.
*/ */
$this->assertTrue(@touch($layout->getFullPath())); $this->assertTrue(@touch($layout->getFilePath()));
$layout = Layout::load($theme, 'php-parser-test.htm'); $layout = Layout::load($theme, 'php-parser-test.htm');
$this->assertNotEmpty($layout); $this->assertNotEmpty($layout);
$parser = new CodeParser($layout); $parser = new CodeParser($layout);

View File

@ -2,9 +2,15 @@
use Cms\Classes\Theme; use Cms\Classes\Theme;
use Cms\Classes\Controller; use Cms\Classes\Controller;
use Cms\Classes\CmsCompoundObject;
class ControllerTest extends TestCase class ControllerTest extends TestCase
{ {
public function tearDown()
{
parent::tearDown();
CmsCompoundObject::flushEventListeners();
}
public function testThemeUrl() public function testThemeUrl()
{ {

View File

@ -7,8 +7,10 @@ class RouterTest extends TestCase
{ {
protected static $theme = null; protected static $theme = null;
public static function setUpBeforeClass() public function setUp()
{ {
parent::setUp();
self::$theme = Theme::load('test'); self::$theme = Theme::load('test');
} }

View File

@ -41,7 +41,8 @@ class ThemeTest extends TestCase
{ {
$theme = Theme::load('test'); $theme = Theme::load('test');
$pages = $theme->listPages(); $pageCollection = $theme->listPages();
$pages = array_values($pageCollection->all());
$this->assertInternalType('array', $pages); $this->assertInternalType('array', $pages);
$expectedPageNum = $this->countThemePages(base_path().'/tests/fixtures/themes/test/pages'); $expectedPageNum = $this->countThemePages(base_path().'/tests/fixtures/themes/test/pages');