public function DfpHtmlResponseAttachmentsProcessorTest::testProcessAttachments in Doubleclick for Publishers (DFP) 8
@covers ::processAttachments
File
- tests/
src/ Unit/ DfpHtmlResponseAttachmentsProcessorTest.php, line 107 - Contains \Drupal\Tests\dfp\Unit\DfpHtmlResponseAttachmentsProcessorTest.
Class
- DfpHtmlResponseAttachmentsProcessorTest
- @coversDefaultClass \Drupal\dfp\DfpHtmlResponseAttachmentsProcessor @group dfp
Namespace
Drupal\Tests\dfp\UnitCode
public function testProcessAttachments() {
// Create a response with two dfp_slot attachments and ensure that the
// they are converted to html_head attachments. Also ensure that the other
// html_head elements are added to create the necessary javascript in the
// right order.
$response = new HtmlResponse();
for ($i = 1; $i < 3; $i++) {
$tag = $this
->prophesize(TagView::class);
$tag
->id()
->willReturn($i);
$attachments['dfp_slot'][] = $tag
->reveal();
}
$response
->setAttachments($attachments);
$config_factory = $this
->getConfigFactoryStub([
'dfp.settings' => [
'targeting' => [],
],
]);
$response = $this
->getDfpAttachmentProcessor($config_factory)
->processAttachments($response);
$this
->assertEquals('dfp-js-head-top', $response
->getAttachments()['html_head'][0][1]);
$this
->assertEquals('dfp-slot-definition-1', $response
->getAttachments()['html_head'][1][1]);
$this
->assertEquals('dfp-slot-definition-2', $response
->getAttachments()['html_head'][2][1]);
$this
->assertEquals('dfp-js-head-bottom', $response
->getAttachments()['html_head'][3][1]);
$this
->assertArrayNotHasKey('dfp_slot', $response
->getAttachments(), 'The dfp_slot attachments are converted to html_head attachments.');
}