class DataLayerUnitTests in dataLayer 7
@file Tests the functionality of the DataLayer module.
Hierarchy
- class \DrupalTestCase- class \DrupalUnitTestCase- class \DataLayerUnitTests
 
 
- class \DrupalUnitTestCase
Expanded class hierarchy of DataLayerUnitTests
File
- tests/datalayer.unit.test, line 7 
- Tests the functionality of the DataLayer module.
View source
class DataLayerUnitTests extends DrupalUnitTestCase {
  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'DataLayer Unit Tests',
      'description' => 'Tests to ensure data makes it client-side.',
      'group' => 'DataLayer',
    );
  }
  /**
   * {@inheritdoc}
   */
  public function setUp() {
    drupal_load('module', 'datalayer');
    parent::setUp();
  }
  /**
   * Test DataLayer Defaults function.
   */
  public function testDataLayerDefaults() {
    $this
      ->setupMockLanguage();
    $this
      ->assertEqual(array(
      'drupalLanguage' => 'en-us',
      'drupalCountry' => '',
    ), _datalayer_defaults());
  }
  /**
   * Test DataLayer Add Will Add Data.
   */
  public function testDataLayerAddWillAddData() {
    $this
      ->setupEmptyDataLayer();
    $this
      ->assertEqual(array(
      'foo' => 'bar',
    ), datalayer_add(array(
      'foo' => 'bar',
    )));
  }
  /**
   * Test DataLayer Add Does Not Overwrite By Default.
   */
  public function testDataLayerAddDoesNotOverwriteByDefault() {
    $this
      ->setupEmptyDataLayer();
    datalayer_add(array(
      'foo' => 'bar',
    ));
    $this
      ->assertEqual(array(
      'foo' => 'bar',
    ), datalayer_add(array(
      'foo' => 'baz',
    )));
  }
  /**
   * Test DataLayer Add Will Overwrite With Flag.
   */
  public function testDataLayerAddWillOverwriteWithFlag() {
    $this
      ->setupEmptyDataLayer();
    datalayer_add(array(
      'foo' => 'bar',
    ));
    $this
      ->assertEqual(array(
      'foo' => 'baz',
    ), datalayer_add(array(
      'foo' => 'baz',
    ), TRUE));
  }
  /**
   * Test DataLayer Menu Get Any Object.
   *
   * Returns False Without Load Functions.
   */
  public function testDataLayerMenuGetAnyObjectReturnsFalseWithoutLoadFunctions() {
    $item = $this
      ->setupMockNode();
    $item['node/1']['load_functions'] = NULL;
    $item_static =& drupal_static('menu_get_item');
    $item_static = $item;
    $return_type = FALSE;
    $result = _datalayer_menu_get_any_object($return_type);
    $this
      ->assertEqual($return_type, FALSE);
    $this
      ->assertEqual($result, FALSE);
  }
  /**
   * Test DataLayer Menu Get Any Object.
   *
   * Returns False Without Load Function Match.
   */
  public function testDataLayerMenuGetAnyObjectReturnsFalseWithoutLoadFunctionMatch() {
    $item = $this
      ->setupMockNode();
    $item['node/1']['load_functions'] = array(
      1 => 'user_load',
    );
    $item_static =& drupal_static('menu_get_item');
    $item_static = $item;
    $return_type = FALSE;
    $result = _datalayer_menu_get_any_object($return_type);
    $this
      ->assertEqual($return_type, FALSE);
    $this
      ->assertEqual($result, FALSE);
  }
  /**
   * Test DataLayer Menu Get Any Object.
   *
   * Returns False With Incorrect Arg Position.
   */
  public function testDataLayerMenuGetAnyObjectReturnsFalseWithIncorrectArgPosition() {
    $item = $this
      ->setupMockNode();
    $item['node/1']['load_functions'] = array(
      'user_load',
    );
    $item_static =& drupal_static('menu_get_item');
    $item_static = $item;
    $return_type = FALSE;
    $result = _datalayer_menu_get_any_object($return_type);
    $this
      ->assertEqual($return_type, FALSE);
    $this
      ->assertEqual($result, FALSE);
  }
  /**
   * Test DataLayer Menu Get Any Object Returns Object.
   */
  public function testDataLayerMenuGetAnyObjectReturnsObject() {
    $item = $this
      ->setupMockNode();
    $return_type = FALSE;
    $object = _datalayer_menu_get_any_object($return_type);
    $this
      ->assertEqual($return_type, 'node');
    $this
      ->assertEqual($object, $item['node/1']['map'][1]);
  }
  /**
   * Test DataLayer Get Entity Terms Returns Empty Array.
   */
  public function testDataLayerGetEntityTermsReturnsEmptyArray() {
    $item = $this
      ->setupMockNode();
    $this
      ->setupMockFieldMap();
    $terms = _datalayer_get_entity_terms('node', 'page', $item['node/1']['map'][1]);
    $this
      ->assertEqual(array(), $terms);
  }
  /**
   * Test DataLayer Get Entity Terms Returns Term Array.
   */
  public function testDataLayerGetEntityTermsReturnsTermArray() {
    $item = $this
      ->setupMockNode();
    $this
      ->setupMockEntityTerms();
    $terms = _datalayer_get_entity_terms('node', 'article', $item['node/1']['map'][1]);
    $this
      ->assertEqual(array(
      'tags' => array(
        1 => 'someTag',
      ),
    ), $terms);
  }
  /**
   * Test DataLayer Get Entity Terms Returns Entity Data Array.
   */
  public function testDataLayerGetEntityDataReturnsEntityDataArray() {
    $this
      ->setupEmptyDataLayer();
    $item = $this
      ->setupMockNode();
    $this
      ->setupMockEntityTerms();
    $entity_data = _datalayer_get_entity_data($item['node/1']['map'][1], 'node');
    $this
      ->assertEqual($this
      ->getExpectedEntityDataArray(), $entity_data);
  }
  /**
   * Setup user.
   */
  public function setupMockUser() {
    global $user;
    $user->uid = 1;
  }
  /**
   * Setup language.
   */
  public function setupMockLanguage($lang = 'en-us') {
    global $language;
    $language->language = $lang;
  }
  /**
   * Setup empty datalayer.
   */
  public function setupEmptyDataLayer() {
    $data =& drupal_static('datalayer_add', array());
  }
  /**
   * Setup mock node.
   */
  public function setupMockNode() {
    // Hijack static cache for menu_get_item call.
    $item =& drupal_static('menu_get_item');
    $_GET['q'] = 'node/1';
    $item = array(
      'node/1' => array(
        'load_functions' => array(
          1 => 'node_load',
        ),
        'map' => array(
          'node',
          (object) array(
            'vid' => 1,
            'uid' => 1,
            'title' => 'My Article',
            'status' => 1,
            'nid' => 1,
            'type' => 'article',
            'language' => 'und',
            'created' => '1435019805',
            'changed' => '1435019805',
            'tnid' => 0,
            'name' => 'admin',
            'field_tags' => array(
              'und' => array(
                array(
                  'tid' => 1,
                  'taxonomy_term' => (object) array(
                    'name' => 'someTag',
                  ),
                ),
              ),
            ),
          ),
        ),
      ),
    );
    // Hijack static cache for entity_get_info call.
    $entity =& drupal_static('entity_get_info');
    $entity = array(
      'node' => array(
        'load hook' => 'node_load',
      ),
    );
    return $item;
  }
  /**
   * Setup Mock Field Map.
   */
  public function setupMockFieldMap() {
    $field_map =& drupal_static('_field_info_field_cache');
    $field_map = new DataLayerMockFieldInfo();
  }
  /**
   * Setup Mock Field Language.
   */
  public function setupMockFieldLanguage() {
    $field_language =& drupal_static('field_language');
    $field_language = array(
      'node' => array(
        1 => array(
          'en' => array(
            'field_tags' => 'und',
          ),
        ),
      ),
    );
  }
  /**
   * Setup Mock Entity Info.
   */
  public function setupMockEntityInfo() {
    $entity_info =& drupal_static('entity_get_info');
    $entity_info = array(
      'node' => array(
        'entity keys' => array(
          'id' => 'nid',
          'revision' => 'vid',
          'bundle' => 'type',
          'label' => 'title',
          'language' => 'language',
        ),
      ),
      'taxonomy_term' => array(
        'controller class' => 'TaxonomyTermController',
        'base table' => 'taxonomy_term_data',
        'uri callback' => 'taxonomy_term_uri',
        'entity keys' => array(
          'id' => 'tid',
          'bundle' => 'vocabulary_machine_name',
          'label' => 'name',
          'revision' => '',
        ),
        'bundles' => array(
          'tags' => array(
            'label' => 'Tags',
            'admin' => array(
              'path' => 'admin/structure/taxonomy/%taxonomy_vocabulary_machine_name',
              'real path' => 'admin/structure/taxonomy/tags',
              'bundle argument' => 3,
              'access arguments' => array(
                0 => 'administer taxonomy',
              ),
            ),
          ),
        ),
      ),
    );
  }
  /**
   * Setup Mock Entity Controller.
   */
  public function setupMockEntityController() {
    $entity_contoller =& drupal_static('entity_get_controller');
    $entity_contoller = array(
      'taxonomy_term' => new DataLayerMockEntityController(),
    );
  }
  /**
   * Setup Mock Entity Terms.
   */
  public function setupMockEntityTerms() {
    $this
      ->setupMockFieldMap();
    $this
      ->setupMockLanguage('en');
    $this
      ->setupMockFieldLanguage();
    $this
      ->setupMockEntityInfo();
    $this
      ->setupMockEntityController();
  }
  /**
   * Get expected entity data array.
   */
  public function getExpectedEntityDataArray() {
    return array(
      'entityType' => 'node',
      'entityBundle' => 'article',
      'entityId' => 1,
      'entityLabel' => 'My Article',
      'entityTaxonomy' => array(
        'tags' => array(
          1 => 'someTag',
        ),
      ),
    );
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| DataLayerUnitTests:: | public | function | Get expected entity data array. | |
| DataLayerUnitTests:: | public static | function | ||
| DataLayerUnitTests:: | public | function | Sets up unit test environment. Overrides DrupalUnitTestCase:: | |
| DataLayerUnitTests:: | public | function | Setup empty datalayer. | |
| DataLayerUnitTests:: | public | function | Setup Mock Entity Controller. | |
| DataLayerUnitTests:: | public | function | Setup Mock Entity Info. | |
| DataLayerUnitTests:: | public | function | Setup Mock Entity Terms. | |
| DataLayerUnitTests:: | public | function | Setup Mock Field Language. | |
| DataLayerUnitTests:: | public | function | Setup Mock Field Map. | |
| DataLayerUnitTests:: | public | function | Setup language. | |
| DataLayerUnitTests:: | public | function | Setup mock node. | |
| DataLayerUnitTests:: | public | function | Setup user. | |
| DataLayerUnitTests:: | public | function | Test DataLayer Add Does Not Overwrite By Default. | |
| DataLayerUnitTests:: | public | function | Test DataLayer Add Will Add Data. | |
| DataLayerUnitTests:: | public | function | Test DataLayer Add Will Overwrite With Flag. | |
| DataLayerUnitTests:: | public | function | Test DataLayer Defaults function. | |
| DataLayerUnitTests:: | public | function | Test DataLayer Get Entity Terms Returns Entity Data Array. | |
| DataLayerUnitTests:: | public | function | Test DataLayer Get Entity Terms Returns Empty Array. | |
| DataLayerUnitTests:: | public | function | Test DataLayer Get Entity Terms Returns Term Array. | |
| DataLayerUnitTests:: | public | function | Test DataLayer Menu Get Any Object. | |
| DataLayerUnitTests:: | public | function | Test DataLayer Menu Get Any Object. | |
| DataLayerUnitTests:: | public | function | Test DataLayer Menu Get Any Object. | |
| DataLayerUnitTests:: | public | function | Test DataLayer Menu Get Any Object Returns Object. | |
| DrupalTestCase:: | protected | property | Assertions thrown in that test case. | |
| DrupalTestCase:: | protected | property | The database prefix of this test run. | |
| DrupalTestCase:: | protected | property | The original file directory, before it was changed for testing purposes. | |
| DrupalTestCase:: | public | property | Current results of this test case. | |
| DrupalTestCase:: | protected | property | Flag to indicate whether the test has been set up. | |
| DrupalTestCase:: | protected | property | ||
| DrupalTestCase:: | protected | property | ||
| DrupalTestCase:: | protected | property | This class is skipped when looking for the source of an assertion. | |
| DrupalTestCase:: | protected | property | The test run ID. | |
| DrupalTestCase:: | protected | property | Time limit for the test. | |
| DrupalTestCase:: | public | property | Whether to cache the installation part of the setUp() method. | |
| DrupalTestCase:: | public | property | Whether to cache the modules installation part of the setUp() method. | |
| DrupalTestCase:: | protected | property | URL to the verbose output file directory. | |
| DrupalTestCase:: | protected | function | Internal helper: stores the assert. | |
| DrupalTestCase:: | protected | function | Check to see if two values are equal. | |
| DrupalTestCase:: | protected | function | Check to see if a value is false (an empty string, 0, NULL, or FALSE). | |
| DrupalTestCase:: | protected | function | Check to see if two values are identical. | |
| DrupalTestCase:: | protected | function | Check to see if two values are not equal. | |
| DrupalTestCase:: | protected | function | Check to see if two values are not identical. | |
| DrupalTestCase:: | protected | function | Check to see if a value is not NULL. | |
| DrupalTestCase:: | protected | function | Check to see if a value is NULL. | |
| DrupalTestCase:: | protected | function | Check to see if a value is not false (not an empty string, 0, NULL, or FALSE). | |
| DrupalTestCase:: | public static | function | Delete an assertion record by message ID. | |
| DrupalTestCase:: | protected | function | Fire an error assertion. | 1 | 
| DrupalTestCase:: | public | function | Handle errors during test runs. | 1 | 
| DrupalTestCase:: | protected | function | Handle exceptions. | |
| DrupalTestCase:: | protected | function | Fire an assertion that is always negative. | |
| DrupalTestCase:: | public static | function | Converts a list of possible parameters into a stack of permutations. | |
| DrupalTestCase:: | protected | function | Cycles through backtrace until the first non-assertion method is found. | |
| DrupalTestCase:: | public static | function | Returns the database connection to the site running Simpletest. | |
| DrupalTestCase:: | public static | function | Store an assertion from outside the testing context. | |
| DrupalTestCase:: | protected | function | Fire an assertion that is always positive. | |
| DrupalTestCase:: | public static | function | Generates a random string containing letters and numbers. | |
| DrupalTestCase:: | public static | function | Generates a random string of ASCII characters of codes 32 to 126. | |
| DrupalTestCase:: | public | function | Run all tests in this class. | |
| DrupalTestCase:: | protected | function | Logs a verbose message in a text file. | |
| DrupalUnitTestCase:: | protected | function | 1 | |
| DrupalUnitTestCase:: | function | Constructor for DrupalUnitTestCase. Overrides DrupalTestCase:: | 
