function dfpDisplayTagTest::testTargeting in Doubleclick for Publishers (DFP) 7        
                          
                  
                        Same name and namespace in other branches
- 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();
  
  $tag = $this
    ->createTag($edit);
  $this
    ->assertPropertySet('Targeting', $edit['targeting[0][target]'], $edit['targeting[0][value]']);
  
  $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));
  
  $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.');
  
  $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.');
  
  $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]']);
  }
  
  $this
    ->drupalPost('admin/structure/dfp_ads/list/' . $tag->machinename . '/edit', $edit, t('Add another target'));
  $this
    ->editTag($tag->machinename, $edit);
  $this
    ->assertPropertyNotSet('Targeting', '', '');
  
  $edit['targeting[0][target]'] = '';
  $edit['targeting[0][value]'] = '';
  $this
    ->editTag($tag->machinename, $edit);
  $this
    ->assertPropertyNotSet('Targeting', '', '');
}