public function GlobalSettingsTest::testGlobalSettings in Doubleclick for Publishers (DFP) 8
Tests \Drupal\dfp\Form\AdminSettings form and dfp_page_attachments().
File
- tests/
src/ Functional/ GlobalSettingsTest.php, line 34
Class
- GlobalSettingsTest
- Tests DFP global configuration.
Namespace
Drupal\Tests\dfp\FunctionalCode
public function testGlobalSettings() {
$edit = [
'adunit_pattern' => 'example.com',
'network_id' => '123456789',
'async_rendering' => TRUE,
'single_request' => TRUE,
'collapse_empty_divs' => '1',
'targeting[0][target]' => '<em>test target</em>',
'targeting[0][value]' => '<em>test value</em>, test value 2 ',
];
$this
->drupalPostForm('admin/structure/dfp/settings', $edit, t('Save configuration'));
$this
->drupalGet('<front>');
$this
->assertNoRaw('googletag', 'With no DFP tags set up there is no additional JS added');
// Create a tag.
$tag = $this
->dfpCreateTag();
$tag
->set('adunit', '');
$tag
->save();
$this
->drupalGet('<front>');
$this
->assertRaw('googletag.pubads().enableAsyncRendering();', 'Asynchronous rendering is turned on.');
$this
->assertRaw('googletag.pubads().enableSingleRequest();', 'Single request is turned on.');
$this
->assertRaw('googletag.pubads().collapseEmptyDivs();', 'Collapse empty divs is turned on.');
$this
->assertRaw("googletag.pubads().setTargeting('<em>test target</em>', ['<em>test value</em>','test value 2']);", 'Global targeting values appear correclty in javascript.');
$this
->assertRaw('/123456789/example.com');
$edit = [
'network_id' => '123456789',
'async_rendering' => FALSE,
'single_request' => FALSE,
'collapse_empty_divs' => '0',
'click_url' => '/custom_click_url',
'targeting[0][target]' => 'test target ',
'targeting[0][value]' => 'test value 3',
'targeting[1][target]' => 'test target 2',
'targeting[1][value]' => 'test value 4',
];
$this
->drupalPostForm('admin/structure/dfp/settings', $edit, t('Save configuration'));
$this
->drupalGet('<front>');
$this
->assertNoRaw('googletag.pubads().enableAsyncRendering();', 'Asynchronous rendering is turned on.');
$this
->assertNoRaw('googletag.pubads().enableSingleRequest();', 'Single request is turned on.');
$this
->assertNoRaw('googletag.pubads().collapseEmptyDivs();', 'Collapse empty divs is turned on.');
$this
->assertRaw("googletag.pubads().setTargeting('test target', ['test value 3']);", 'Global targeting values appear correctly in javascript.');
$this
->assertRaw("googletag.pubads().setTargeting('test target 2', ['test value 4']);", 'Global targeting values appear correctly in javascript.');
$this
->assertEqual('/custom_click_url', \Drupal::config('dfp.settings')
->get('click_url'));
$edit = [
'async_rendering' => TRUE,
'click_url' => '/custom_click_url',
'adunit_pattern' => '$has_an_illegal_character',
];
$this
->drupalPostForm('admin/structure/dfp/settings', $edit, t('Save configuration'));
$this
->assertText(t('Setting a click URL does not work with async rendering.'));
$this
->assertText(t('Ad Unit Patterns can only include letters, numbers, hyphens, dashes, periods, slashes and tokens.'));
}