You are here

class GAPushUnitTestCase in GA Push 7

Same name and namespace in other branches
  1. 8 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 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)');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalTestCase::$assertions protected property Assertions thrown in that test case.
DrupalTestCase::$databasePrefix protected property The database prefix of this test run.
DrupalTestCase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
DrupalTestCase::$results public property Current results of this test case.
DrupalTestCase::$setup protected property Flag to indicate whether the test has been set up.
DrupalTestCase::$setupDatabasePrefix protected property
DrupalTestCase::$setupEnvironment protected property
DrupalTestCase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
DrupalTestCase::$testId protected property The test run ID.
DrupalTestCase::$timeLimit protected property Time limit for the test.
DrupalTestCase::$useSetupInstallationCache public property Whether to cache the installation part of the setUp() method.
DrupalTestCase::$useSetupModulesCache public property Whether to cache the modules installation part of the setUp() method.
DrupalTestCase::$verboseDirectoryUrl protected property URL to the verbose output file directory.
DrupalTestCase::assert protected function Internal helper: stores the assert.
DrupalTestCase::assertEqual protected function Check to see if two values are equal.
DrupalTestCase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertIdentical protected function Check to see if two values are identical.
DrupalTestCase::assertNotEqual protected function Check to see if two values are not equal.
DrupalTestCase::assertNotIdentical protected function Check to see if two values are not identical.
DrupalTestCase::assertNotNull protected function Check to see if a value is not NULL.
DrupalTestCase::assertNull protected function Check to see if a value is NULL.
DrupalTestCase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
DrupalTestCase::deleteAssert public static function Delete an assertion record by message ID.
DrupalTestCase::error protected function Fire an error assertion. 1
DrupalTestCase::errorHandler public function Handle errors during test runs. 1
DrupalTestCase::exceptionHandler protected function Handle exceptions.
DrupalTestCase::fail protected function Fire an assertion that is always negative.
DrupalTestCase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
DrupalTestCase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
DrupalTestCase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
DrupalTestCase::insertAssert public static function Store an assertion from outside the testing context.
DrupalTestCase::pass protected function Fire an assertion that is always positive.
DrupalTestCase::randomName public static function Generates a random string containing letters and numbers.
DrupalTestCase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
DrupalTestCase::run public function Run all tests in this class.
DrupalTestCase::verbose protected function Logs a verbose message in a text file.
DrupalUnitTestCase::tearDown protected function 1
DrupalUnitTestCase::__construct function Constructor for DrupalUnitTestCase. Overrides DrupalTestCase::__construct
GAPushUnitTestCase::$pushes protected property
GAPushUnitTestCase::getInfo public static function
GAPushUnitTestCase::setUp public function Sets up unit test environment. Overrides DrupalUnitTestCase::setUp
GAPushUnitTestCase::testGaPushMethodAnalyticsJSPushScriptEcommerce public function Unit test for ga_push_method_analytics_js_push_script(): Ecommerce.
GAPushUnitTestCase::testGaPushMethodAnalyticsJSPushScriptEvent public function Unit test for ga_push_method_analytics_js_push_script(): Event.
GAPushUnitTestCase::testGaPushMethodAnalyticsJSPushScriptException public function Unit test for ga_push_method_analytics_js_push_script(): Exception.
GAPushUnitTestCase::testGaPushMethodAnalyticsJSPushScriptPageview public function Unit test for ga_push_method_analytics_js_push_script(): Pageview.
GAPushUnitTestCase::testGaPushMethodAnalyticsJSPushScriptSocial public function Unit test for ga_push_method_analytics_js_push_script(): Social.