Perforce Chronicle 2012.2/486814
API Documentation

Site_Test_IndexControllerTest Class Reference

Test the site index controller. More...

List of all members.

Public Member Functions

 testIndexGet ()
 Test general site settings display.
 testIndexGoodPost ()
 Test providing good POST parameters.
 testIndexNoSiteTitle ()
 Test providing an empty site title.
 testRobots ()
 Test the robots action.

Protected Member Functions

 _getRequestHttpHost ()
 A helper method to determine the request's hostname.

Detailed Description

Test the site index controller.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

Site_Test_IndexControllerTest::_getRequestHttpHost ( ) [protected]

A helper method to determine the request's hostname.

Returns:
string The request's current hostname
    {
        $host = $this->request->getHttpHost();
        if (preg_match('#:\d+$#', $host, $result) === 1) {
            $host = substr($host, 0, -strlen($result[0]));
        }

        return $host;
    }
Site_Test_IndexControllerTest::testIndexGet ( )

Test general site settings display.

    {
        $this->utility->impersonate('administrator');
        $site = P4Cms_Site::fetchActive();

        // test that basic list renders correctly.
        $this->dispatch('/site/config');
        $body = $this->response->getBody();
        $this->assertModule(
            'site',
            'Last module should be site, got "'. $this->request->getModuleName() .'", body: '. $body
        );
        $this->assertController(
            'index',
            'Expected index controller, got "'. $this->request->getControllerName() .'", body: '. $body
        );
        $this->assertAction(
            'config',
            'Expected index action, got "'. $this->request->getActionName() .'", body: '. $body
        );
    }
Site_Test_IndexControllerTest::testIndexGoodPost ( )

Test providing good POST parameters.

    {
        $this->utility->impersonate('administrator');

        // test that basic list renders correctly.
        $host  = $this->_getRequestHttpHost();
        $title = 'my site';
        $settings = array(
            'title' => $title
        );
        $this->request->setPost($settings);
        $this->request->setMethod('POST');
        $this->dispatch('/site/config');
        $body = $this->response->getBody();
        $this->assertModule(
            'site',
            'Last module should be site, got "'. $this->request->getModuleName() .'", body: '. $body
        );
        $this->assertController(
            'index',
            'Expected index controller, got "'. $this->request->getControllerName() .'", body: '. $body
        );
        $this->assertAction(
            'config',
            'Expected index action, got "'. $this->request->getActionName() .'", body: '. $body
        );
        $this->assertRedirectTo('/site/config', __LINE__ .': Expect redirect to site/index/config.'. $body);

        $config = P4Cms_Site::fetchActive()->getConfig();
        $this->assertEquals($title, $config->getTitle(), 'Expected value for title.');
    }
Site_Test_IndexControllerTest::testIndexNoSiteTitle ( )

Test providing an empty site title.

    {
        $this->utility->impersonate('administrator');

        // test that basic list renders correctly.
        $settings = array(
            'title' => ''
        );
        $this->request->setPost($settings);
        $this->request->setMethod('POST');
        $this->dispatch('/site/config');
        $body = $this->response->getBody();
        $this->assertModule(
            'site',
            'Last module should be site, got "'. $this->request->getModuleName() .'", body: '. $body
        );
        $this->assertController(
            'index',
            'Expected index controller, got "'. $this->request->getControllerName() .'", body: '. $body
        );
        $this->assertAction(
            'config',
            'Expected index action, got "'. $this->request->getActionName() .'", body: '. $body
        );

        $this->assertQueryContentContains(
            "dd[id='title-element'] ul.errors li",
            "Value is required and can't be empty",
            'Expected an error for the title field in: '. $body
        );
    }
Site_Test_IndexControllerTest::testRobots ( )

Test the robots action.

    {
        $this->dispatch('/site/robots');
        $body = $this->response->getBody();
        $this->assertEquals("User-agent: *\nDisallow:\n", $body, 'Expected default robots.txt');

        // change robots.txt
        $this->resetRequest()->resetResponse();
        $this->utility->impersonate('administrator');

        $settings = array(
            'title'     => 'my site',
            'robots'    => "User-agent: google\nDisallow: yahoo"
        );
        $this->request->setPost($settings);
        $this->request->setMethod('POST');
        $this->dispatch('/site/config');
        $this->assertModule('site', 'Expected module');
        $this->assertController('index', 'Expected controller');
        $this->assertAction('config', 'Expected action');

        // verify the change
        $this->resetRequest()->resetResponse();
        $this->dispatch('/site/robots');
        $body = $this->response->getBody();
        $this->assertEquals("User-agent: google\nDisallow: yahoo", $body, 'Expected modified robots.txt');
    }

The documentation for this class was generated from the following file: