Skip to content

Commit

Permalink
Fixes unit tests so they pass
Browse files Browse the repository at this point in the history
  • Loading branch information
daftspunk committed Mar 2, 2015
1 parent f0bc711 commit 83b54c0
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 48 deletions.
22 changes: 22 additions & 0 deletions config/testing/cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,26 @@

'convertLineEndings' => true,

/*
|--------------------------------------------------------------------------
| Local plugins path
|--------------------------------------------------------------------------
|
| Specifies the absolute local plugins path.
|
*/

'pluginsPathLocal' => base_path().'/tests/fixtures/plugins',

/*
|--------------------------------------------------------------------------
| Local themes path
|--------------------------------------------------------------------------
|
| Specifies the absolute local themes path.
|
*/

'themesPathLocal' => base_path().'/tests/fixtures/themes',

];
13 changes: 0 additions & 13 deletions phpdoc.dist.xml

This file was deleted.

3 changes: 0 additions & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ public function createApplication()
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();

$app['cache']->setDefaultDriver('array');

$app->setLocale('en');
$app->setPluginsPath(base_path().'/tests/fixtures/plugins');
$app->setThemesPath(base_path().'/tests/fixtures/themes');

return $app;
}
Expand Down
56 changes: 31 additions & 25 deletions tests/unit/cms/classes/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,61 +144,67 @@ protected function configAjaxRequestMock($handler, $partials = false)
return $requestMock;
}

/**
* @expectedException Cms\Classes\CmsException
* @expectedExceptionMessage AJAX handler 'onNoHandler' was not found.
*/
public function testAjaxHandlerNotFound()
{
Request::swap($this->configAjaxRequestMock('onNoHandler', ''));

$theme = Theme::load('test');
$controller = new Controller($theme);
$controller->run('/ajax-test');

$response = $controller->run('/ajax-test');
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
//
// This was the old approach, can remove this comment block if year >= 2017
//

$this->assertInternalType('string', $response->getOriginalContent());
$this->assertEquals(500, $response->getStatusCode());
$this->assertEquals("AJAX handler 'onNoHandler' was not found.", $response->getOriginalContent());
// $response = $controller->run('/ajax-test');
// $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);

// $this->assertInternalType('string', $response->getOriginalContent());
// $this->assertEquals(500, $response->getStatusCode());
// $this->assertEquals("AJAX handler 'onNoHandler' was not found.", $response->getOriginalContent());
}

/**
* @expectedException Cms\Classes\CmsException
* @expectedExceptionMessage Invalid AJAX handler name: delete.
*/
public function testAjaxInvalidHandlerName()
{
Request::swap($this->configAjaxRequestMock('delete'));

$theme = Theme::load('test');
$controller = new Controller($theme);
$response = $controller->run('/ajax-test');
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);

$this->assertInternalType('string', $response->getOriginalContent());
$this->assertEquals(500, $response->getStatusCode());
$this->assertEquals('Invalid AJAX handler name: delete.', $response->getOriginalContent());
$controller->run('/ajax-test');
}

/**
* @expectedException Cms\Classes\CmsException
* @expectedExceptionMessage Invalid partial name: p:artial.
*/
public function testAjaxInvalidPartial()
{
Request::swap($this->configAjaxRequestMock('onTest', 'p:artial'));

$theme = Theme::load('test');
$controller = new Controller($theme);
$response = $controller->run('/ajax-test');
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);

$this->assertInternalType('string', $response->getOriginalContent());
$this->assertEquals(500, $response->getStatusCode());
$this->assertEquals('Invalid partial name: p:artial.', $response->getOriginalContent());
$controller->run('/ajax-test');
}

/**
* @expectedException Cms\Classes\CmsException
* @expectedExceptionMessage The partial 'partial' is not found.
*/
public function testAjaxPartialNotFound()
{
Request::swap($this->configAjaxRequestMock('onTest', 'partial'));

$theme = Theme::load('test');
$controller = new Controller($theme);
$response = $controller->run('/ajax-test');
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);

$this->assertInternalType('string', $response->getOriginalContent());
$this->assertEquals(500, $response->getStatusCode());
$this->assertEquals("The partial 'partial' is not found.", $response->getOriginalContent());
$controller->run('/ajax-test');
}

public function testPageAjax()
Expand Down Expand Up @@ -332,10 +338,10 @@ public function testThemeUrl()
$controller = new Controller($theme);

$url = $controller->themeUrl();
$this->assertEquals('/tests/fixtures/themes/test', $url);
$this->assertEquals('http://localhost/themes/test', $url);

$url = $controller->themeUrl('foo/bar.css');
$this->assertEquals('/tests/fixtures/themes/test/foo/bar.css', $url);
$this->assertEquals('http://localhost/themes/test/foo/bar.css', $url);

//
// These tests seem to bear different results
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@
<directory>./</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing" />
<env name="CACHE_DRIVER" value="array" />
<env name="SESSION_DRIVER" value="array" />
</php>
</phpunit>
25 changes: 18 additions & 7 deletions tests/unit/system/classes/CombineAssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,24 @@ public function testCombiner()
public function testCombine()
{
$combiner = CombineAssets::instance();
$url = $combiner->combine(['assets/css/style1.css', 'assets/css/style2.css'], '/tests/fixtures/themes/test');
$this->assertNotNull($url);
$this->assertRegExp('/\w+[-]\d+/i', $url); // Must contain hash-number

$url = $combiner->combine(['assets/js/script1.js', 'assets/js/script2.js'], '/tests/fixtures/themes/test');
$url = $combiner->combine([
'assets/css/style1.css',
'assets/css/style2.css'
],
base_path().'/tests/fixtures/themes/test'
);
$this->assertNotNull($url);
$this->assertRegExp('/\w+[-]\d+/i', $url); // Must contain hash-number

$url = $combiner->combine([
'assets/js/script1.js',
'assets/js/script2.js'
],
base_path().'/tests/fixtures/themes/test'
);
$this->assertNotNull($url);
$this->assertRegExp('/\w+[-]\d+/i', $url); // Must contain hash-number
$this->assertRegExp('/\w+[-]\d+/i', $url); // Must contain hash-number
}

public function testPrepareRequest()
Expand Down Expand Up @@ -130,10 +141,10 @@ public function testGetTargetPath()
public function testMakeCacheId()
{
$sampleResources = ['assets/css/style1.css', 'assets/css/style2.css'];
$samplePath = '/tests/fixtures/Cms/themes/test';
$samplePath = base_path().'/tests/fixtures/cms/themes/test';

$combiner = CombineAssets::instance();
self::setProtectedProperty($combiner, 'path', $samplePath);
self::setProtectedProperty($combiner, 'localPath', $samplePath);

$value = self::callProtectedMethod($combiner, 'makeCacheId', [$sampleResources]);
$this->assertEquals(md5($samplePath.implode('|', $sampleResources)), $value);
Expand Down

0 comments on commit 83b54c0

Please sign in to comment.