You are here

class GAPushUnitTestCase in GA Push 8

Same name and namespace in other branches
  1. 7 test/ga_push.test \GAPushUnitTestCase

Functional tests for the GA Push module.

Hierarchy

Expanded class hierarchy of GAPushUnitTestCase

File

test/ga_push.test, line 13
Test case for testing the GA Push module.

View source
class GAPushUnitTestCase extends DrupalUnitTestCase {
  protected $pushes;

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return [
      '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 = [];

    // Events:
    $this->pushes[GA_PUSH_TYPE_EVENT]['calv'] = [
      'eventCategory' => 'Videos',
      'eventAction' => 'Play',
      'eventLabel' => 'Gone With the Wind',
      'eventValue' => 1,
      'nonInteraction' => FALSE,
    ];
    $this->pushes[GA_PUSH_TYPE_EVENT]['calvn'] = [
      'eventCategory' => 'Videos',
      'eventAction' => 'Play',
      'eventLabel' => 'Gone With the Wind',
      'eventValue' => 1,
      'nonInteraction' => TRUE,
    ];
    $this->pushes[GA_PUSH_TYPE_EVENT]['ca'] = [
      'eventCategory' => 'Videos',
      'eventAction' => 'Play',
    ];

    // Social:
    $this->pushes[GA_PUSH_TYPE_SOCIAL]['nat'] = [
      'socialNetwork' => 'facebook',
      'socialAction' => 'like',
      'socialTarget' => 'http://mycoolpage.com',
    ];
    $this->pushes[GA_PUSH_TYPE_SOCIAL]['n'] = [
      '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)');
  }

}

Members