Fixes various unit tests so they pass (Tested in Windows)

This commit is contained in:
Samuel Georges 2015-01-05 12:37:04 +11:00
parent 2160ddf3e5
commit 415f07eb1d
10 changed files with 83 additions and 17 deletions

View File

@ -96,4 +96,16 @@ return array(
*/
'twigNoCache' => true,
/*
|--------------------------------------------------------------------------
| Convert Line Endings
|--------------------------------------------------------------------------
|
| Determines if October should convert line endings from the windows style
| \r\n to the unix style \n.
|
*/
'convertLineEndings' => true,
);

View File

@ -1,5 +1,7 @@
<?php namespace Cms\Classes;
use Str;
/**
* This class parses CMS object files (pages, partials and layouts).
* Returns the structured file information.
@ -72,6 +74,7 @@ class SectionParser
*/
public static function parseOffset($content)
{
$content = Str::normalizeEol($content);
$sections = preg_split('/^={2,}\s*/m', $content, -1);
$count = count($sections);

View File

@ -1,6 +1,7 @@
<?php namespace System\Behaviors;
use Cache;
use DbDongle;
use System\Classes\ModelBehavior;
use System\Classes\ApplicationException;
@ -100,7 +101,7 @@ class SettingsModel extends ModelBehavior
*/
public function isConfigured()
{
return $this->getSettingsRecord() !== null;
return DbDongle::hasDatabase() && $this->getSettingsRecord() !== null;
}
/**

View File

@ -1,5 +1,6 @@
<?php namespace System\Classes;
use App;
use Log;
/**
@ -14,6 +15,12 @@ class SystemException extends ExceptionBase
public function __construct($message = "", $code = 0, \Exception $previous = null)
{
parent::__construct($message, $code, $previous);
Log::error($this);
/*
* Log the exception
*/
if (!App::runningUnitTests()) {
Log::error($this);
}
}
}

View File

@ -162,7 +162,7 @@ class CmsCompoundObjectTest extends TestCase
$this->assertFileExists($referenceFilePath);
$this->assertFileExists($destFilePath);
$this->assertFileEquals($referenceFilePath, $destFilePath);
$this->assertFileEqualsNormalized($referenceFilePath, $destFilePath);
}
public function testSaveMarkupAndSettings()
@ -187,7 +187,7 @@ class CmsCompoundObjectTest extends TestCase
$this->assertFileExists($referenceFilePath);
$this->assertFileExists($destFilePath);
$this->assertFileEquals($referenceFilePath, $destFilePath);
$this->assertFileEqualsNormalized($referenceFilePath, $destFilePath);
}
public function testSaveFull()
@ -195,8 +195,9 @@ class CmsCompoundObjectTest extends TestCase
$theme = Theme::load('apitest');
$destFilePath = $theme->getPath().'/testobjects/compound.htm';
if (file_exists($destFilePath))
if (file_exists($destFilePath)) {
unlink($destFilePath);
}
$this->assertFileNotExists($destFilePath);
@ -213,6 +214,22 @@ class CmsCompoundObjectTest extends TestCase
$this->assertFileExists($referenceFilePath);
$this->assertFileExists($destFilePath);
$this->assertFileEquals($referenceFilePath, $destFilePath);
$this->assertFileEqualsNormalized($referenceFilePath, $destFilePath);
}
//
// Helpers
//
protected function assertFileEqualsNormalized($expected, $actual)
{
$expected = file_get_contents($expected);
$expected = preg_replace('~\R~u', PHP_EOL, $expected); // Normalize EOL
$actual = file_get_contents($actual);
$actual = preg_replace('~\R~u', PHP_EOL, $actual); // Normalize EOL
$this->assertEquals($expected, $actual);
}
}

View File

@ -141,7 +141,7 @@ class CmsObjectTest extends TestCase
/**
* @expectedException \System\Classes\ApplicationException
* @expectedExceptionMessage The property "something" cannot be set
* @expectedExceptionMessage The property 'something' cannot be set
*/
public function testFillNotFillable()
{

View File

@ -253,10 +253,22 @@ class CodeParserTest extends TestCase
$referenceFilePath = base_path().'/tests/fixtures/cms/reference/namespaces.php';
$this->assertFileExists($referenceFilePath);
$referenceContents = file_get_contents($referenceFilePath);
$referenceContents = $this->getContents($referenceFilePath);
$referenceContents = str_replace('{className}', $info['className'], $referenceContents);
$this->assertEquals($referenceContents, file_get_contents($info['filePath']));
$this->assertEquals($referenceContents, $this->getContents($info['filePath']));
}
//
// Helpers
//
protected function getContents($path)
{
$content = file_get_contents($path);
$content = preg_replace('~\R~u', PHP_EOL, $content); // Normalize EOL
return $content;
}
}

View File

@ -28,7 +28,7 @@ class FileHelperTest extends TestCase
$str = FileHelper::formatIniString($data);
$this->assertNotEmpty($str);
$this->assertEquals(file_get_contents($path), $str);
$this->assertEquals($this->getContents($path), $str);
$data = [
'section' => [
@ -47,7 +47,7 @@ class FileHelperTest extends TestCase
$this->assertFileExists($path);
$str = FileHelper::formatIniString($data);
$this->assertEquals(file_get_contents($path), $str);
$this->assertEquals($this->getContents($path), $str);
$data = [
'section' => [
@ -75,6 +75,21 @@ class FileHelperTest extends TestCase
$this->assertFileExists($path);
$str = FileHelper::formatIniString($data);
$this->assertEquals(file_get_contents($path), $str);
$this->assertEquals($this->getContents($path), $str);
}
//
// Helpers
//
protected function getContents($path)
{
$content = file_get_contents($path);
// Normalize EOL
$content = preg_replace('~\R~u', PHP_EOL, $content);
return $content;
}
}

View File

@ -6,11 +6,10 @@ use Cms\Classes\Theme;
class RouterTest extends TestCase
{
protected static $theme = null;
public static function setUpBeforeClass()
{
self::$theme = new Theme();
self::$theme->load('test');
self::$theme = Theme::load('test');
}
protected static function getMethod($name)
@ -28,7 +27,7 @@ class RouterTest extends TestCase
$property->setAccessible(true);
return $property;
}
public function testLoadUrlMap()
{
$method = self::getMethod('loadUrlMap');

View File

@ -2,7 +2,7 @@
use Cms\Classes\Theme;
class ThemeTest extends TestCase
class ThemeTest extends TestCase
{
public function setUp()
{