load('apitest');
$controller = new Controller($theme);
$response = $controller->run('/some-page-that-doesnt-exist');
$this->assertNotEmpty($response);
$this->assertInstanceOf('\Illuminate\Http\Response', $response);
ob_start();
include base_path().'/modules/cms/views/404.php';
$page404Content = ob_get_contents();
ob_end_clean();
$this->assertEquals($page404Content, $response->getContent());
/*
* Test the theme 404 page
*/
$theme = new Theme();
$theme->load('test');
$controller = new Controller($theme);
$response = $controller->run('/some-page-that-doesnt-exist');
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
$content = $response->getContent();
$this->assertInternalType('string', $content);
$this->assertEquals('
Page not found
', $content);
}
public function testRoot()
{
/*
* Test the / route and the fallback layout
*/
$theme = new Theme();
$theme->load('test');
$controller = new Controller($theme);
$response = $controller->run('/');
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
$content = $response->getContent();
$this->assertInternalType('string', $content);
$this->assertEquals('My Webpage
', trim($content));
}
/**
* @expectedException Cms\Classes\CmsException
* @expectedExceptionMessage is not found
*/
public function testLayoutNotFound()
{
$theme = new Theme();
$theme->load('test');
$controller = new Controller($theme);
$response = $controller->run('/no-layout');
}
public function testExistingLayout()
{
/*
* Test existing layout
*/
$theme = new Theme();
$theme->load('test');
$controller = new Controller($theme);
$response = $controller->run('/with-layout');
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
$content = $response->getContent();
$this->assertEquals('', $content);
}
public function testPartials()
{
/*
* Test partials referred in the layout and page
*/
$theme = new 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);
}
public function testContent()
{
$theme = new Theme();
$theme->load('test');
$controller = new Controller($theme);
$response = $controller->run('/with-content')->getContent();
$this->assertEquals('LAYOUT CONTENT
Hey PAGE CONTENT A content
', $response);
}
public function testBlocks()
{
$theme = new 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);
}
public function testLayoutInSubdirectory()
{
$theme = new Theme();
$theme->load('test');
$controller = new Controller($theme);
$response = $controller->run('/apage')->getContent();
$this->assertEquals("LAYOUT CONTENT
This page is a subdirectory
", $response);
}
/**
* @expectedException Cms\Classes\CmsException
* @expectedExceptionMessage is not found
*/
public function testPartialNotFound()
{
$theme = new Theme();
$theme->load('test');
$controller = new Controller($theme);
$response = $controller->run('/no-partial')->getContent();
}
public function testPageLifeCycle()
{
$theme = new Theme();
$theme->load('test');
$controller = new Controller($theme);
$response = $controller->run('/cycle-test')->getContent();
$this->assertEquals('12345', $response);
}
protected function configAjaxRequestMock($handler, $partials = false)
{
$requestMock = $this->getMock('Illuminate\Http\Request', array('header'));
$requestMock->expects($this->at(0))->
method('header')->
with($this->stringContains('X_OCTOBER_REQUEST_HANDLER'), $this->anything())->
will($this->returnValue($handler));
if ($partials !== false)
$requestMock->expects($this->at(1))->
method('header')->
with($this->stringContains('X_OCTOBER_REQUEST_PARTIALS'), $this->anything())->
will($this->returnValue($partials));
return $requestMock;
}
public function testAjaxHandlerNotFound()
{
App::instance('request', $this->configAjaxRequestMock('onNoHandler', ''));
$theme = new 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("AJAX handler 'onNoHandler' was not found.", $response->getOriginalContent());
}
public function testAjaxInvalidHandlerName()
{
App::instance('request', $this->configAjaxRequestMock('delete'));
$theme = new 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());
}
public function testAjaxInvalidPartial()
{
App::instance('request', $this->configAjaxRequestMock('onTest', 'p:artial'));
$theme = new 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());
}
public function testAjaxPartialNotFound()
{
App::instance('request', $this->configAjaxRequestMock('onTest', 'partial'));
$theme = new 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());
}
public function testPageAjax()
{
App::instance('request', $this->configAjaxRequestMock('onTest', 'ajax-result'));
$theme = new Theme();
$theme->load('test');
$controller = new Controller($theme);
$response = $controller->run('/ajax-test');
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
$content = $response->getOriginalContent();
$this->assertInternalType('array', $content);
$this->assertEquals(200, $response->getStatusCode());
$this->assertCount(1, $content);
$this->assertArrayHasKey('ajax-result', $content);
$this->assertEquals('page', $content['ajax-result']);
}
public function testLayoutAjax()
{
App::instance('request', $this->configAjaxRequestMock('onTestLayout', 'ajax-result'));
$theme = new Theme();
$theme->load('test');
$controller = new Controller($theme);
$response = $controller->run('/ajax-test');
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
$content = $response->getOriginalContent();
$this->assertInternalType('array', $content);
$this->assertEquals(200, $response->getStatusCode());
$this->assertCount(1, $content);
$this->assertArrayHasKey('ajax-result', $content);
$this->assertEquals('layout-test', $content['ajax-result']);
}
public function testAjaxMultiplePartials()
{
App::instance('request', $this->configAjaxRequestMock('onTest', 'ajax-result&ajax-second-result'));
$theme = new Theme();
$theme->load('test');
$controller = new Controller($theme);
$response = $controller->run('/ajax-test');
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
$content = $response->getOriginalContent();
$this->assertInternalType('array', $content);
$this->assertEquals(200, $response->getStatusCode());
$this->assertCount(2, $content);
$this->assertArrayHasKey('ajax-result', $content);
$this->assertArrayHasKey('ajax-second-result', $content);
$this->assertEquals('page', $content['ajax-result']);
$this->assertEquals('second', $content['ajax-second-result']);
}
public function testBasicComponents()
{
$theme = new Theme();
$theme->load('test');
$controller = new Controller($theme);
$response = $controller->run('/with-component')->getContent();
$page = PHPUnit_Framework_Assert::readAttribute($controller, 'page');
$this->assertArrayHasKey('testArchive', $page->components);
$component = $page->components['testArchive'];
$details = $component->componentDetails();
$content = <<LAYOUT CONTENTThis page uses components.
Lorum ipsum
Post Content #1
La Playa Nudista
Second Post Content
ESC;
$this->assertEquals($content, $response);
$this->assertEquals(69, $component->property('posts-per-page'));
$this->assertEquals('Blog Archive Dummy Component', $details['name']);
$this->assertEquals('Displays an archive of blog posts.', $details['description']);
}
public function testComponentAliases()
{
include_once base_path() . '/tests/fixtures/System/plugins/October/Test/Components/Archive.php';
$theme = new Theme();
$theme->load('test');
$controller = new Controller($theme);
$response = $controller->run('/with-components')->getContent();
$page = PHPUnit_Framework_Assert::readAttribute($controller, 'page');
$this->assertArrayHasKey('firstAlias', $page->components);
$this->assertArrayHasKey('secondAlias', $page->components);
$component = $page->components['firstAlias'];
$component2 = $page->components['secondAlias'];
$content = <<LAYOUT CONTENTThis page uses components.
Lorum ipsum
Post Content #1
La Playa Nudista
Second Post Content
ESC;
$this->assertEquals($content, $response);
$this->assertEquals(6, $component->property('posts-per-page'));
$this->assertEquals(9, $component2->property('posts-per-page'));
}
public function testComponentAjax()
{
App::instance('request', $this->configAjaxRequestMock('testArchive::onTestAjax', 'ajax-result'));
$theme = new Theme();
$theme->load('test');
$controller = new Controller($theme);
$response = $controller->run('/with-component');
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
$content = $response->getOriginalContent();
$this->assertInternalType('array', $content);
$this->assertEquals(200, $response->getStatusCode());
$this->assertCount(1, $content);
$this->assertArrayHasKey('ajax-result', $content);
$this->assertEquals('page', $content['ajax-result']);
}
}