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);
$path = $reflect->getFilename();
$basePath = plugins_path();
$basePath = $this->app->pluginsPath();
$result = false;

View File

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

View File

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

View File

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

View File

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

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.
*/
$this->assertTrue(@touch($layout->getFullPath()));
$this->assertTrue(@touch($layout->getFilePath()));
$layout = Layout::load($theme, 'php-parser-test.htm');
$this->assertNotEmpty($layout);
$parser = new CodeParser($layout);

View File

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

View File

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

View File

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