You are here

function dfpDisplayTagTest::testDisplayTagWithMapping in Doubleclick for Publishers (DFP) 7.2

Same name and namespace in other branches
  1. 7 tests/dfp_display_tag.test \dfpDisplayTagTest::testDisplayTagWithMapping()

File

tests/dfp.test, line 166
Test file for DFP module.

Class

dfpDisplayTagTest

Code

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

  // Create a simple tag with a mapping. Verify javascript on page.
  $tag = $this
    ->createTag($edit);
  $mapping_sizes = explode(',', $edit['breakpoints[0][ad_sizes]']);
  $size_count = count($mapping_sizes);

  // Calculate addSize mappings.
  $mapping_tag = '.addSize(';
  $mapping_tag .= '[' . str_replace('x', ', ', $edit['breakpoints[0][browser_size]']) . '], ';
  $mapping_tag .= $size_count > 1 ? '[' : '';
  for ($i = 0; $i < $size_count; $i++) {
    $mapping_sizes[$i] = '[' . str_replace('x', ', ', $mapping_sizes[$i]) . ']';
    $mapping_tag .= $i + 1 !== $size_count ? $mapping_sizes[$i] . ', ' : $mapping_sizes[$i];
  }
  $mapping_tag .= $size_count > 1 ? '])' : ')';
  $this
    ->assertRaw('googletag.sizeMapping()', 'The ad slot correctly attaches size mapping.');
  $this
    ->assertRaw('.defineSizeMapping(mapping)', 'The ad slot correctly defines size mapping.');
  $this
    ->assertRaw($mapping_tag, 'The ad slot correctly defines specific size mappings.');

  // Create a tag with invalid browser size mappings.
  $edit['breakpoints[0][browser_size]'] = $this
    ->randomName(8);
  $this
    ->editTag($tag->machinename, $edit);
  $this
    ->assertText(t('The browser size can only contain numbers and the character x.'), 'An error was correctly thrown when invalid characters.');

  // Create a tag with invalid ad size mappings.
  $edit['breakpoints[0][browser_size]'] = $this
    ->dfpGenerateSize();
  $edit['breakpoints[0][ad_sizes]'] = $this
    ->randomName(8);
  $this
    ->editTag($tag->machinename, $edit);
  $this
    ->assertText(t('The ad size(s) can only contain numbers, the character x and commas.'), 'An error was correctly thrown when invalid characters.');
}