You are here

function dfpDisplayTagTest::testTargeting in Doubleclick for Publishers (DFP) 7

Same name and namespace in other branches
  1. 7.2 tests/dfp.test \dfpDisplayTagTest::testTargeting()

File

tests/dfp_display_tag.test, line 103
Display tag test file for DFP module.

Class

dfpDisplayTagTest
@file Display tag test file for DFP module.

Code

function testTargeting() {
  $edit = $this
    ->dfpBasicTagEditValues();

  // Create a tag with a target with only one value.
  $tag = $this
    ->createTag($edit);
  $this
    ->assertPropertySet('Targeting', $edit['targeting[0][target]'], $edit['targeting[0][value]']);

  // Create a tag with a target with multiple values.
  $values = array(
    $this
      ->randomName(8),
    $this
      ->randomName(8),
    $this
      ->randomName(8),
  );
  $edit['targeting[0][target]'] = $this
    ->randomName(8);
  $edit['targeting[0][value]'] = implode(', ', $values);
  $this
    ->editTag($tag->machinename, $edit);
  $this
    ->assertPropertySet('Targeting', $edit['targeting[0][target]'], implode('","', $values));

  // Create a tag with a target but no value.
  $edit['targeting[0][target]'] = $this
    ->randomName(8);
  $edit['targeting[0][value]'] = '';
  $this
    ->editTag($tag->machinename, $edit);
  $this
    ->assertText(t('The value cannot be empty if a target exists.'), 'An error was correctly thrown when a target has no value.');

  // Create a tag with an empty target, but a value.
  $edit['targeting[0][target]'] = '';
  $edit['targeting[0][value]'] = $this
    ->randomName(8);
  $this
    ->editTag($tag->machinename, $edit);
  $this
    ->assertText(t('The target cannot be empty if a value exists.'), 'An error was correctly thrown when a target is blank, but a value has been entered.');

  // Create a tag with multiple targets.
  $count = 3;
  for ($i = 0; $i < $count; $i++) {
    $edit['targeting[' . $i . '][target]'] = $this
      ->randomName(8);
    $edit['targeting[' . $i . '][value]'] = $this
      ->randomName(8);
    $this
      ->drupalPost('admin/structure/dfp_ads/list/' . $tag->machinename . '/edit', $edit, t('Add another target'));
    $this
      ->editTag($tag->machinename, $edit);
  }
  for ($i = 0; $i < $count; $i++) {
    $this
      ->assertPropertySet('Targeting', $edit['targeting[' . $i . '][target]'], $edit['targeting[' . $i . '][value]']);
  }

  // Make sure that empty values are ignored.
  $this
    ->drupalPost('admin/structure/dfp_ads/list/' . $tag->machinename . '/edit', $edit, t('Add another target'));
  $this
    ->editTag($tag->machinename, $edit);
  $this
    ->assertPropertyNotSet('Targeting', '', '');

  // Test that target can be removed.
  $edit['targeting[0][target]'] = '';
  $edit['targeting[0][value]'] = '';
  $this
    ->editTag($tag->machinename, $edit);
  $this
    ->assertPropertyNotSet('Targeting', '', '');
}