Perforce Chronicle 2012.2/486814
API Documentation
|
Test the Analytics configure controller. More...
Public Member Functions | |
setUp () | |
Perform setup. | |
testLoadModule () | |
Test of loading the module. |
Test the Analytics configure controller.
Because the analytics service is outside of our control, all we can test is that the analytics code was injected accurately - we cannot test that it is working. Cannot easily test content id and type here, see SnippetAdditionTest.php
Analytics_Test_LoadSnippetTest::setUp | ( | ) |
Perform setup.
{ $this->view = new Zend_View; Zend_Dojo::enableView($this->view); parent::setUp(); if (!defined('TEST_ACCOUNT_NUMBER')) { define('TEST_ACCOUNT_NUMBER', 'UA-XXXXX-1'); } }
Analytics_Test_LoadSnippetTest::testLoadModule | ( | ) |
Test of loading the module.
{ $this->utility->impersonate('administrator'); $analyticsModule = P4Cms_Module::fetch('Analytics'); $analyticsModule->enable(); $analyticsModule->saveConfig( new Zend_Config( array( 'accountNumber' => TEST_ACCOUNT_NUMBER, 'customVars' => array('userId', 'userRole', 'contentId', 'contentType') ) ) ); // load module, verify that page contains expected. $analyticsModule->load(); $headContent = Zend_Layout::getMvcInstance()->getView()->headScript()->toString(); // verify account number, custom variables, and values $tests = array( "/_gaq\.push\(\['_setAccount', '" . TEST_ACCOUNT_NUMBER . "'\]\);/", "/\['_setCustomVar', 0, 'userId', 'mweiss'\]/", "/\['_setCustomVar', 1, 'userRole', 'administrator'\]/" ); foreach ($tests as $regex) { $this->assertRegExp( $regex, $headContent, 'Could not match regex with head content ' . $headContent ); } }