/** * @covers Nodrew\Bundle\DfpBundle\Model\AdUnit::print */ public function testWillBuildPrintProperly() { $unit = new AdUnit('path', array(300, 200)); $unit->setDivId('divId'); $expected = <<<EXPECTED <div id="divId" class="class" style="width:300px; height:200px;"> <script type="text/javascript"> googletag.cmd.push(function() { googletag.display('divId'); }); </script> </div> EXPECTED; $this->assertSame($expected, $unit->output(new Settings('0000', 'class'))); }
/** * @covers Nodrew\Bundle\DfpBundle\EventListener\ControlCodeListener::onKernelResponse */ public function testResponseEventWillPrintTargetArrayIntoAdUnit() { $content = '<!-- NodrewDfpBundle Control Code -->'; $result = <<<RESPONSE <script type="text/javascript"> var googletag = googletag || {}; googletag.cmd = googletag.cmd || []; (function() { var gads = document.createElement('script'); gads.async = true; gads.type = 'text/javascript'; var useSSL = 'https:' == document.location.protocol; gads.src = (useSSL ? 'https:' : 'http:') + '//www.googletagservices.com/tag/js/gpt.js'; var node = document.getElementsByTagName('script')[0]; node.parentNode.insertBefore(gads, node); })(); </script> <script type="text/javascript"> googletag.cmd.push(function() { googletag.defineSlot('/0000/path/path', [300, 255], 'divId').addService(googletag.pubads()); googletag.pubads().enableSingleRequest(); googletag.enableServices(); googletag.target('SSS', ['blue','green']); }); </script> RESPONSE; $this->collection->add($unit = new AdUnit('path/path', array(300, 255))); $unit->setDivId('divId'); $unit->addTarget('SSS', array('blue', 'green')); $this->listener->onKernelResponse($this->event($content)); $this->assertSame($result, trim($this->response->getContent())); }
/** * Get the control block for an individual ad. * * @return string */ protected function getOutOfPageAdControlBlock(AdUnit $unit) { $publisherId = trim($this->settings->getPublisherId(), '/'); $targets = $this->getTargetsBlock($unit->getTargets()); $divId = $unit->getDivId(); $path = $unit->getPath(); return <<<BLOCK <script type="text/javascript"> googletag.cmd.push(function() { googletag.defineOutOfPageSlot('/{$publisherId}/{$path}', '{$divId}').addService(googletag.pubads()); googletag.pubads().enableSingleRequest(); googletag.enableServices();{$targets} }); </script> BLOCK; }