You are here

dfp_ad_categories.test in Doubleclick for Publishers (DFP) 7

Ad Categories test file for DFP module.

File

tests/dfp_ad_categories.test
View source
<?php

/**
 * @file
 * Ad Categories test file for DFP module.
 */
class dfpAdCategoriesTest extends dfpBaseTest {

  /**
   * Implements getInfo().
   */
  public static function getInfo() {
    return array(
      'name' => t('DFP Ad Categories'),
      'description' => t('Tests the functionality of DFP ad categories.'),
      'group' => t('DFP'),
    );
  }
  function testEnableDisableAdCategories() {

    // Check that enabling DFP Ad Categories for the "tags" vocabulary works.
    $edit = array(
      'dfp_enable_ad_categories' => 1,
      'dfp_enable_ad_categories_bundles[tags]' => 'tags',
    );
    $this
      ->drupalPost('admin/structure/dfp_ads/settings', $edit, t('Save configuration'));
    $this
      ->drupalGet('admin/structure/taxonomy/tags/add');
    $this
      ->assertFieldByName('field_dfp_ad_categories[und]');

    // Check that disabling DFP Ad Categories vocabulary works even when a
    // bundle is selected.
    $edit = array(
      'dfp_enable_ad_categories' => 0,
    );
    $this
      ->drupalPost('admin/structure/dfp_ads/settings', $edit, t('Save configuration'));
    $this
      ->drupalGet('admin/structure/taxonomy/tags/add');
    $this
      ->assertNoFieldByName('field_dfp_ad_categories[und]');

    // Check that disabling DFP Ad Categories on a specific vocabulary works.
    // For this test to be valid, we first need to re-enable DFP Ad Categories.
    $edit = array(
      'dfp_enable_ad_categories' => 1,
      'dfp_enable_ad_categories_bundles[tags]' => 'tags',
    );
    $this
      ->drupalPost('admin/structure/dfp_ads/settings', $edit, t('Save configuration'));
    $this
      ->drupalGet('admin/structure/taxonomy/tags/add');
    $edit = array(
      'dfp_enable_ad_categories_bundles[tags]' => 0,
    );
    $this
      ->drupalPost('admin/structure/dfp_ads/settings', $edit, t('Save configuration'));
    $this
      ->drupalGet('admin/structure/taxonomy/tags/add');
    $this
      ->assertNoFieldByName('field_dfp_ad_categories[und]');
  }

  // Test that DFP Categories are displayed properly.
  function testDisplayAdCategories() {
    $dfp_add_categories_vocabulary = taxonomy_vocabulary_machine_name_load('dfp_ad_categories');
    $tags_vocabulary = taxonomy_vocabulary_machine_name_load('tags');

    // Turn on DFP ad categories for the "tags" vocabulary.
    $edit = array(
      'dfp_enable_ad_categories' => 1,
      'dfp_enable_ad_categories_bundles[tags]' => 'tags',
    );
    $this
      ->drupalPost('admin/structure/dfp_ads/settings', $edit, t('Save configuration'));

    // Create a new DFP Ad Category term.
    $dfp_category = $this
      ->createTerm($dfp_add_categories_vocabulary);
    $control_tag = $this
      ->createTerm($tags_vocabulary);
    $test_tag = $this
      ->createTerm($tags_vocabulary);

    // Create a new "Article" node with these two tags.
    $edit = array(
      'title' => $this
        ->randomName(8),
      'field_tags[und]' => $control_tag->name . ', ' . $test_tag->name,
    );
    $this
      ->drupalPost('node/add/article', $edit, t('Save'));

    // Edit one the new tags and tag it with a DFP Ad Category.
    $edit = array(
      'field_dfp_ad_categories[und]' => $dfp_category->tid,
    );
    $this
      ->drupalPost('taxonomy/term/' . $test_tag->tid . '/edit', $edit, t('Save'));

    // Create a DFP ad slot that targets the [dfp_tag:ad_categories] token.
    $edit = $this
      ->dfpBasicTagEditValues();

    // Create a tag that uses the slot token in a target.
    $edit['slot'] = $this
      ->randomName(8);
    $edit['targeting[0][target]'] = 'categories';
    $edit['targeting[0][value]'] = '[dfp_tag:ad_categories]';
    $tag = $this
      ->createTag($edit);

    // Check that when we are on the node page, that the DFP Ad Category is used
    // and that the control tag is also displayed.
    $this
      ->drupalGet('node/1');
    $this
      ->assertPropertySet('Targeting', 'categories', $control_tag->name);
    $this
      ->assertPropertySet('Targeting', 'categories', $dfp_category->name);

    // Check that when we are on the term page for one of DFP Ad Categories that
    // it is correctly included.
    $this
      ->drupalGet('taxonomy/term/' . $dfp_category->tid);
    $this
      ->assertPropertySet('Targeting', 'categories', $dfp_category->name);

    // Check that when we are on a term page for a term with a corresponding
    // DFP Ad Categories the DFP Ad Category is included.
    $this
      ->drupalGet('taxonomy/term/' . $test_tag->tid);
    $this
      ->assertPropertySet('Targeting', 'categories', $dfp_category->name);
  }

}

Classes

Namesort descending Description
dfpAdCategoriesTest @file Ad Categories test file for DFP module.