Perforce Chronicle 2012.2/486814
API Documentation
|
Test the url -> content integration. More...
Public Member Functions | |
setUp () | |
Activate url module. | |
testDelete () | |
Test deleting urls. | |
testDispatch () | |
Test dispatching a custom url. | |
testDispatchDeleted () | |
Test dispatching a custom url for a deleted content entry. | |
testDispatchOutdated () | |
Test dispatching an outdated custom url. | |
testMakeUnique () | |
Exercise helper function for making a url path unique in the system. | |
testSave () | |
Exercise saving content. | |
Protected Member Functions | |
_createContent () | |
Make a content entry. |
Test the url -> content integration.
Url_Test_ContentIntegrationTest::_createContent | ( | ) | [protected] |
Make a content entry.
{ // install default types and disable workflow on basic page. // this makes basic pages implicitly published allowing anonymous // users to get access to them. P4Cms_Content_Type::installDefaultTypes(); $type = P4Cms_Content_Type::fetch('basic-page'); $type->setValue('workflow', null) ->save(); $content = new P4Cms_Content; $content->setValues( array( 'id' => 1, 'contentType' => 'basic-page', 'title' => 'My Page', 'body' => 'My page body text.', 'url' => array( 'auto' => true, 'path' => '/my-page' ) ) ); return $content->save(); }
Url_Test_ContentIntegrationTest::setUp | ( | ) |
Activate url module.
{ parent::setUp(); P4Cms_Module::fetch('Url')->enable()->load(); // turn off exiting in the redirector P4Cms_Controller_Action_Helper_Redirector::$unitTestEnabled = true; }
Url_Test_ContentIntegrationTest::testDelete | ( | ) |
Test deleting urls.
{ $content = $this->_createContent(); // delete the content. $content->delete(); // ensure the associated url record is gone too. $this->assertFalse(Url_Model_Url::exists('my-page')); // ensure we can't fetch it by params. try { Url_Model_Url::fetchByContent($content); $this->fail('Unexpected success fetching url for deleted content'); } catch (P4Cms_Record_NotFoundException $e) { $this->assertTrue(true); } // ensure we can fetch if we include deleted. $this->assertTrue(Url_Model_Url::exists('my-page', array('includeDeleted' => true))); // ensure we can fetch by content if we include deleted. $url = Url_Model_Url::fetchByContent($content, array('includeDeleted' => true)); $this->assertTrue($url instanceof Url_Model_Url); }
Url_Test_ContentIntegrationTest::testDispatch | ( | ) |
Test dispatching a custom url.
{ $this->utility->impersonate('anonymous'); $content = $this->_createContent(); $this->dispatch('/my-page'); $this->assertRoute(Url_Module::ROUTE); $this->assertModule('content'); $this->assertController('index'); $this->assertAction('view'); $this->assertSame('1', $this->request->getParam('id')); $this->resetRequest() ->resetResponse(); $this->dispatch('/my-page?action=download'); $this->assertModule('content'); $this->assertController('index'); $this->assertAction('download'); $this->assertSame('1', $this->request->getParam('id')); }
Url_Test_ContentIntegrationTest::testDispatchDeleted | ( | ) |
Test dispatching a custom url for a deleted content entry.
{ $this->utility->impersonate('anonymous'); $content = $this->_createContent(); $content->delete(); $this->dispatch('/my-page'); // verify custom url mapping is gone. $this->assertFalse(Url_Model_Url::exists('my-page')); $this->assertRoute(Url_Module::ROUTE); $this->assertModule('error'); $this->assertController('index'); $this->assertAction('page-not-found'); $this->assertResponseCode(404); }
Url_Test_ContentIntegrationTest::testDispatchOutdated | ( | ) |
Test dispatching an outdated custom url.
{ $this->utility->impersonate('anonymous'); $content = $this->_createContent(); $content->setValue('url', array('path' => 'my-new-url'))->save(); $this->dispatch('/my-page'); // verify custom url mapping is gone. $this->assertFalse(Url_Model_Url::exists('my-page')); $this->assertRoute(Url_Module::ROUTE); $this->assertRedirectTo('/my-new-url'); $this->assertResponseCode(301); }
Url_Test_ContentIntegrationTest::testMakeUnique | ( | ) |
Exercise helper function for making a url path unique in the system.
Also tests isPathRouted() - indirectly.
{ // test resolving conflicts against custom urls. $params = array('a' => 1, 'b' => 2, 'c' => 3); $url = new Url_Model_Url; $url->setPath('foo') ->setParams($params) ->save(); // test simple cases. $this->assertSame('bar', Url_Module::makePathUnique('bar')); $this->assertSame('foo', Url_Module::makePathUnique('foo', $params)); $this->assertSame('foo-2', Url_Module::makePathUnique('foo')); // make some more entries. $url->setPath('foo-1')->save(); $url->setPath('foo-10')->save(); $url->setPath('foo-2')->save(); $url->setPath('foo-bar')->save(); // test resolvable conflict against other custom urls. $this->assertSame('foo-11', Url_Module::makePathUnique('foo')); // test resolvable conflict against internal route (user module). $this->assertSame('user-2', Url_Module::makePathUnique('user')); // test resolvable conflict against both internal route and custom url $url->setPath('user-2')->save(); $this->assertSame('user-3', Url_Module::makePathUnique('user')); // test un-resolvable conflict against internal route (user/login) $this->assertSame('user/login', Url_Module::makePathUnique('user/login')); // test resolvable conflict where we have already been assigned a number. $url->setParams(array()); $url->setPath('bar')->save(); $url->setPath('bar-5')->save(); $url->setPath('bar-4')->setParams($params)->save(); $this->assertSame('foo', Url_Module::makePathUnique('foo', $params)); }
Url_Test_ContentIntegrationTest::testSave | ( | ) |
Exercise saving content.
{ $content = $this->_createContent(); // ensure we have a corresponding url record. $this->assertTrue(Url_Model_Url::exists('my-page')); // ensure we can fetch it by params. $this->assertTrue(Url_Model_Url::fetchByContent($content) instanceof Url_Model_Url); }