ga_push.test in GA Push 7
Same filename and directory in other branches
Test case for testing the GA Push module.
File
test/ga_push.testView source
<?php
/**
* @file
* Test case for testing the GA Push module.
*/
/**
* Functional tests for the GA Push module.
*
* @ingroup ga_push
*/
class GAPushUnitTestCase extends DrupalUnitTestCase {
protected $pushes;
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'GA Push functionality',
'description' => 'Test the JS push types output.',
'group' => 'GA Push',
);
}
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp('ga_push', 'googleanalytics');
// $ua_code = 'UA-123456-1';
// variable_set('googleanalytics_account', $ua_code);
// Get defined vars:
module_load_include('module', 'ga_push');
// Common pushes:
$this->pushes = array();
// Events:
$this->pushes[GA_PUSH_TYPE_EVENT]['calv'] = array(
'eventCategory' => 'Videos',
'eventAction' => 'Play',
'eventLabel' => 'Gone With the Wind',
'eventValue' => 1,
'nonInteraction' => FALSE,
);
$this->pushes[GA_PUSH_TYPE_EVENT]['calvn'] = array(
'eventCategory' => 'Videos',
'eventAction' => 'Play',
'eventLabel' => 'Gone With the Wind',
'eventValue' => 1,
'nonInteraction' => TRUE,
);
$this->pushes[GA_PUSH_TYPE_EVENT]['ca'] = array(
'eventCategory' => 'Videos',
'eventAction' => 'Play',
);
// Social:
$this->pushes[GA_PUSH_TYPE_SOCIAL]['nat'] = array(
'socialNetwork' => 'facebook',
'socialAction' => 'like',
'socialTarget' => 'http://mycoolpage.com',
);
$this->pushes[GA_PUSH_TYPE_SOCIAL]['n'] = array(
'socialNetwork' => 'facebook',
);
}
/**
* Unit test for ga_push_method_analytics_js_push_script(): Ecommerce.
*/
public function testGaPushMethodAnalyticsJSPushScriptEcommerce() {
$type = GA_PUSH_TYPE_ECOMMERCE;
// @TODO!
}
/**
* Unit test for ga_push_method_analytics_js_push_script(): Event.
*/
public function testGaPushMethodAnalyticsJSPushScriptEvent() {
$type = GA_PUSH_TYPE_EVENT;
// Load library:
module_load_include('inc', 'ga_push', 'inc/ga_push.analytics_js');
$push = $this->pushes[$type]['calv'];
$script = ga_push_method_analytics_js_push_script($push, $type);
$expected = 'ga(\'send\', {"eventCategory":"Videos","eventAction":"Play","eventLabel":"Gone With the Wind","eventValue":1,"hitType":"event"});' . "\n";
$this
->assertTrue($expected === $script, 'GA Push Analytics js: event (calv)');
$push = $this->pushes[$type]['calvn'];
$script = ga_push_method_analytics_js_push_script($push, $type);
$expected = 'ga(\'send\', {"eventCategory":"Videos","eventAction":"Play","eventLabel":"Gone With the Wind","eventValue":1,"nonInteraction":true,"hitType":"event"});' . "\n";
$this
->assertTrue($expected === $script, 'GA Push Analytics js: event (calvn)');
$push = $this->pushes[$type]['ca'];
$script = ga_push_method_analytics_js_push_script($push, $type);
$expected = 'ga(\'send\', {"eventCategory":"Videos","eventAction":"Play","eventValue":1,"hitType":"event"});' . "\n";
$this
->assertTrue($expected === $script, 'GA Push Analytics js: event (ca)');
}
/**
* Unit test for ga_push_method_analytics_js_push_script(): Exception.
*/
public function testGaPushMethodAnalyticsJSPushScriptException() {
$type = GA_PUSH_TYPE_EXCEPTION;
// @TODO!
}
/**
* Unit test for ga_push_method_analytics_js_push_script(): Pageview.
*/
public function testGaPushMethodAnalyticsJSPushScriptPageview() {
$type = GA_PUSH_TYPE_PAGEVIEW;
// @TODO!
}
/**
* Unit test for ga_push_method_analytics_js_push_script(): Social.
*/
public function testGaPushMethodAnalyticsJSPushScriptSocial() {
$type = GA_PUSH_TYPE_SOCIAL;
// Load library:
module_load_include('inc', 'ga_push', 'inc/ga_push.analytics_js');
$push = $this->pushes[$type]['nat'];
$script = ga_push_method_analytics_js_push_script($push, $type);
$expected = 'ga(\'send\', {"socialNetwork":"facebook","socialAction":"like","socialTarget":"http:\\/\\/mycoolpage.com","hitType":"social"});' . "\n";
$this
->assertTrue($expected === $script, 'GA Push Analytics js: social (nat)');
$push = $this->pushes[$type]['n'];
$script = ga_push_method_analytics_js_push_script($push, $type);
$expected = 'ga(\'send\', {"socialNetwork":"facebook","hitType":"social"});' . "\n";
$this
->assertTrue($expected === $script, 'GA Push Analytics js: social (n)');
}
}
Classes
Name | Description |
---|---|
GAPushUnitTestCase | Functional tests for the GA Push module. |