Perforce Chronicle 2012.2/486814
API Documentation
|
Test the content index controller. More...
Public Member Functions | |
setUp () | |
Perform setup. | |
testBadConfigPost () | |
Test non integer tunables. | |
testGoodConfigPost () | |
Test the search queries. | |
testIndex () | |
Test view action. | |
Public Attributes | |
$bootstrap = array('Bootstrap', 'run') | |
Protected Member Functions | |
_createContent () | |
Create several test content entries. |
Test the content index controller.
Search_Test_ManageControllerTest::_createContent | ( | ) | [protected] |
Create several test content entries.
{ // test type content $entry = new P4Cms_Content; $entry->setId('test123') ->setContentType('test-type') ->setValue('title', 'My Title') ->setValue('body', 'My content body') ->save(); // test type w. id content $entry = new P4Cms_Content; $entry->setId('test456') ->setContentType('test-type-w-id') ->setValue('title', 'My Title') ->setValue('body', 'My content body') ->save(); // test type w. file $entry = new P4Cms_Content; $entry->setId('test789') ->setContentType('test-type-w-file') ->setValue('title', 'My Title') ->setValue('file', 'test file content') ->setFieldMetadata( 'file', array('filename' => 'myfile.txt', 'mimeType' => 'text/plain') ) ->save(); // test type w. image $entry = new P4Cms_Content; $entry->setId('test5309') ->setContentType('test-type-w-file') ->setValue('title', 'Test Image') ->setValue('file', 'test image content') ->setFieldMetadata( 'file', array('filename' => 'image.jpg', 'mimeType' => 'image/jpg') ) ->save(); }
Search_Test_ManageControllerTest::setUp | ( | ) |
Perform setup.
{ parent::setUp(); $searchModule = P4Cms_Module::fetch('Search'); $searchModule->enable(); $searchModule->load(); P4Cms_Content_Type::installDefaultTypes(); // install default ACL $acl = P4Cms_Site::fetchActive()->getAcl(); $acl->installDefaults()->save(); // ensure a type is present for testing. $type = new P4Cms_Content_Type; $type->setId('test-type') ->setLabel('Test Type') ->setElements( array( "title" => array( "type" => "text", "options" => array("label" => "Title", "required" => true) ), "body" => array( "type" => "textarea", "options" => array("label" => "Body") ) ) ) ->setValue('icon', file_get_contents(TEST_ASSETS_PATH . "/images/content-type-icon.png")) ->setFieldMetadata('icon', array("mimeType" => "image/png")) ->setValue('group', 'test') ->save(); // ensure a type w. id is present for testing. $type = new P4Cms_Content_Type; $type->setId('test-type-w-id') ->setLabel('Test Type') ->setElements( array( "id" => array( "type" => "text", "options" => array("label" => "Title", "required" => true) ), "title" => array( "type" => "text", "options" => array("label" => "Title", "required" => true) ), "body" => array( "type" => "textarea", "options" => array("label" => "Body") ) ) ) ->setValue('icon', file_get_contents(TEST_ASSETS_PATH . "/images/content-type-icon.png")) ->setFieldMetadata('icon', array("mimeType" => "image/png")) ->setValue('group', 'test') ->save(); // ensure a type w. a file is present for testing. $type = new P4Cms_Content_Type; $type->setId('test-type-w-file') ->setLabel('Test Type') ->setElements( array( "title" => array( "type" => "text", "options" => array("label" => "Title", "required" => true) ), "name" => array( "type" => "file", "options" => array("label" => "File") ) ) ) ->setValue('icon', file_get_contents(TEST_ASSETS_PATH . "/images/content-type-icon.png")) ->setFieldMetadata('icon', array("mimeType" => "image/png")) ->setValue('group', 'test2') ->save(); }
Search_Test_ManageControllerTest::testBadConfigPost | ( | ) |
Test non integer tunables.
{ $this->utility->impersonate('administrator'); // test 1 $maxBufferedDocs = 'string'; $maxMergeDocs = '12000000'; $mergeFactor = '100'; $params = array( 'maxBufferedDocs' => $maxBufferedDocs, 'maxMergeDocs' => $maxMergeDocs, 'mergeFactor' => $mergeFactor, ); $this->request->setMethod('POST'); $this->request->setPost($params); $this->dispatch('/search/manage'); $responseBody = $this->response->getBody(); $this->assertModule('search', 'Last module run should be content module.' . $responseBody); $this->assertController('manage', 'Expected controller.' . $responseBody); $this->assertAction('index', 'Expected action.' . $responseBody); $this->assertResponseCode(200, 'Expected response code.' . $responseBody); // verify there is an error message $this->assertQueryContentContains( 'ul.errors', "'$maxBufferedDocs' does not appear to be an integer" ); $this->resetRequest(); $this->resetResponse(); // test 2 $maxBufferedDocs = '2222'; $maxMergeDocs = '12000000ss'; $mergeFactor = '100'; $params = array( 'maxBufferedDocs' => $maxBufferedDocs, 'maxMergeDocs' => $maxMergeDocs, 'mergeFactor' => $mergeFactor, ); $this->request->setMethod('POST'); $this->request->setPost($params); $this->dispatch('/search/manage'); $responseBody = $this->response->getBody(); $this->assertModule('search', 'Last module run should be content module.' . $responseBody); $this->assertController('manage', 'Expected controller.' . $responseBody); $this->assertAction('index', 'Expected action.' . $responseBody); $this->assertResponseCode(200, 'Expected response code.' . $responseBody); // verify there is an error message $this->assertQueryContentContains( 'ul.errors', "'$maxMergeDocs' does not appear to be an integer" ); $this->resetRequest(); $this->resetResponse(); // test 3 $maxBufferedDocs = '2222'; $maxMergeDocs = '12000000'; $mergeFactor = '100.01'; $params = array( 'maxBufferedDocs' => $maxBufferedDocs, 'maxMergeDocs' => $maxMergeDocs, 'mergeFactor' => $mergeFactor, ); $this->request->setMethod('POST'); $this->request->setPost($params); $this->dispatch('/search/manage'); $responseBody = $this->response->getBody(); $this->assertModule('search', 'Last module run should be content module.' . $responseBody); $this->assertController('manage', 'Expected controller.' . $responseBody); $this->assertAction('index', 'Expected action.' . $responseBody); $this->assertResponseCode(200, 'Expected response code.' . $responseBody); // verify there is an error message $this->assertQueryContentContains( 'ul.errors', "'$mergeFactor' does not appear to be an integer" ); }
Search_Test_ManageControllerTest::testGoodConfigPost | ( | ) |
Test the search queries.
{ $this->utility->impersonate('administrator'); $maxBufferedDocs = '1000'; $maxMergeDocs = '12000000'; $mergeFactor = '100'; $params = array( 'maxBufferedDocs' => $maxBufferedDocs, 'maxMergeDocs' => $maxMergeDocs, 'mergeFactor' => $mergeFactor, ); $this->request->setMethod('POST'); $this->request->setPost($params); $this->dispatch('/search/manage'); $responseBody = $this->response->getBody(); $this->assertModule('search', 'Last module run should be content module.' . $responseBody); $this->assertController('manage', 'Expected controller.' . $responseBody); $this->assertAction('index', 'Expected action.' . $responseBody); $this->assertRedirectTo('/search/manage', 'Expected redirecting back to manage page.'); $this->assertSame($maxBufferedDocs, Search_Module::getMaxBufferedDocs()); $this->assertSame($maxMergeDocs, Search_Module::getMaxMergeDocs()); $this->assertSame($mergeFactor, Search_Module::getMergeFactor()); }
Search_Test_ManageControllerTest::testIndex | ( | ) |
Test view action.
{ $this->utility->impersonate('administrator'); $this->dispatch('/search/manage'); $body = $this->response->getBody(); $this->assertModule('search', 'Last module run should be content module.' . $body); $this->assertController('manage', 'Expected controller' . $body); $this->assertAction('index', 'Expected action' . $body); // check that output looks sane. $this->assertQueryContentRegex( '#layout-top h1', '/Manage Search/', 'Expect the page title.' ); }
Search_Test_ManageControllerTest::$bootstrap = array('Bootstrap', 'run') |