/ */ class Analytics_Test_LoadSnippetTest extends ModuleTest { /** * Perform setup */ public function 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'); } } /** * Test of loading the module */ public function testLoadModule() { $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 ); } } }