class DfpHtmlResponseAttachmentsProcessorTest in Doubleclick for Publishers (DFP) 8
@coversDefaultClass \Drupal\dfp\DfpHtmlResponseAttachmentsProcessor @group dfp
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\dfp\Unit\DfpHtmlResponseAttachmentsProcessorTest
 
 
Expanded class hierarchy of DfpHtmlResponseAttachmentsProcessorTest
File
- tests/
src/ Unit/ DfpHtmlResponseAttachmentsProcessorTest.php, line 27  - Contains \Drupal\Tests\dfp\Unit\DfpHtmlResponseAttachmentsProcessorTest.
 
Namespace
Drupal\Tests\dfp\UnitView source
class DfpHtmlResponseAttachmentsProcessorTest extends UnitTestCase {
  /**
   * A mock core html attachment processor.
   *
   * @var \Drupal\Core\Render\AttachmentsResponseProcessorInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $attachmentProcessor;
  /**
   * A mock DFP token service.
   *
   * @var \Prophecy\Prophecy\ObjectProphecy
   */
  protected $token;
  /**
   * A mock asset resolver service.
   *
   * @var \Prophecy\Prophecy\ObjectProphecy
   */
  protected $assetResolver;
  /**
   * A mock CSS collection renderer.
   *
   * @var \Prophecy\Prophecy\ObjectProphecy
   */
  protected $cssCollectionRenderer;
  /**
   * A mock JS collection renderer.
   *
   * @var \Prophecy\Prophecy\ObjectProphecy
   */
  protected $jsCollectionRenderer;
  /**
   * A mock RequestStack.
   *
   * @var \Prophecy\Prophecy\ObjectProphecy
   */
  protected $requestStack;
  /**
   * A mock renderer.
   *
   * @var \Prophecy\Prophecy\ObjectProphecy
   */
  protected $renderer;
  /**
   * A mock module handler.
   *
   * @var \Prophecy\Prophecy\ObjectProphecy
   */
  protected $moduleHandler;
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    // Mock core attachment processor.
    $this->attachmentProcessor = $this
      ->getMockBuilder(AttachmentsResponseProcessorInterface::class)
      ->disableOriginalConstructor()
      ->getMock();
    $this->attachmentProcessor
      ->method('processAttachments')
      ->willReturnArgument(0);
    $this->token = $this
      ->prophesize(TokenInterface::class);
    $this->assetResolver = $this
      ->prophesize(AssetResolverInterface::class);
    $this->cssCollectionRenderer = $this
      ->prophesize(AssetCollectionRendererInterface::class);
    $this->jsCollectionRenderer = $this
      ->prophesize(AssetCollectionRendererInterface::class);
    $this->requestStack = $this
      ->prophesize(RequestStack::class);
    $this->renderer = $this
      ->prophesize(RendererInterface::class);
    $this->moduleHandler = $this
      ->prophesize(ModuleHandlerInterface::class);
  }
  /**
   * @covers ::processAttachments
   */
  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.');
  }
  /**
   * @covers ::processAttachments
   */
  public function testProcessAttachmentsNoSlots() {
    // Ensure that if there are no slots nothing is added to the attachments.
    $response = new HtmlResponse();
    $config_factory = $this
      ->getConfigFactoryStub();
    $response = $this
      ->getDfpAttachmentProcessor($config_factory)
      ->processAttachments($response);
    $this
      ->assertEmpty($response
      ->getAttachments());
  }
  /**
   * Creates a DfpHtmlResponseAttachmentsProcessor object.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   A mock config factory that can contain 'dfp.settings' configuration.
   *
   * @return \Drupal\dfp\DfpHtmlResponseAttachmentsProcessor
   *   The DfpHtmlResponseAttachmentsProcessor object.
   */
  protected function getDfpAttachmentProcessor(ConfigFactoryInterface $config_factory) {
    return new DfpHtmlResponseAttachmentsProcessor($this->attachmentProcessor, $this->token
      ->reveal(), $this->assetResolver
      ->reveal(), $config_factory, $this->cssCollectionRenderer
      ->reveal(), $this->jsCollectionRenderer
      ->reveal(), $this->requestStack
      ->reveal(), $this->renderer
      ->reveal(), $this->moduleHandler
      ->reveal());
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            DfpHtmlResponseAttachmentsProcessorTest:: | 
                  protected | property | A mock asset resolver service. | |
| 
            DfpHtmlResponseAttachmentsProcessorTest:: | 
                  protected | property | A mock core html attachment processor. | |
| 
            DfpHtmlResponseAttachmentsProcessorTest:: | 
                  protected | property | A mock CSS collection renderer. | |
| 
            DfpHtmlResponseAttachmentsProcessorTest:: | 
                  protected | property | A mock JS collection renderer. | |
| 
            DfpHtmlResponseAttachmentsProcessorTest:: | 
                  protected | property | A mock module handler. | |
| 
            DfpHtmlResponseAttachmentsProcessorTest:: | 
                  protected | property | A mock renderer. | |
| 
            DfpHtmlResponseAttachmentsProcessorTest:: | 
                  protected | property | A mock RequestStack. | |
| 
            DfpHtmlResponseAttachmentsProcessorTest:: | 
                  protected | property | A mock DFP token service. | |
| 
            DfpHtmlResponseAttachmentsProcessorTest:: | 
                  protected | function | Creates a DfpHtmlResponseAttachmentsProcessor object. | |
| 
            DfpHtmlResponseAttachmentsProcessorTest:: | 
                  protected | function | 
            Overrides UnitTestCase:: | 
                  |
| 
            DfpHtmlResponseAttachmentsProcessorTest:: | 
                  public | function | @covers ::processAttachments | |
| 
            DfpHtmlResponseAttachmentsProcessorTest:: | 
                  public | function | @covers ::processAttachments | |
| 
            PhpunitCompatibilityTrait:: | 
                  public | function | Returns a mock object for the specified class using the available method. | |
| 
            PhpunitCompatibilityTrait:: | 
                  public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
| 
            UnitTestCase:: | 
                  protected | property | The random generator. | |
| 
            UnitTestCase:: | 
                  protected | property | The app root. | 1 | 
| 
            UnitTestCase:: | 
                  protected | function | Asserts if two arrays are equal by sorting them first. | |
| 
            UnitTestCase:: | 
                  protected | function | Mocks a block with a block plugin. | 1 | 
| 
            UnitTestCase:: | 
                  protected | function | Returns a stub class resolver. | |
| 
            UnitTestCase:: | 
                  public | function | Returns a stub config factory that behaves according to the passed array. | |
| 
            UnitTestCase:: | 
                  public | function | Returns a stub config storage that returns the supplied configuration. | |
| 
            UnitTestCase:: | 
                  protected | function | Sets up a container with a cache tags invalidator. | |
| 
            UnitTestCase:: | 
                  protected | function | Gets the random generator for the utility methods. | |
| 
            UnitTestCase:: | 
                  public | function | Returns a stub translation manager that just returns the passed string. | |
| 
            UnitTestCase:: | 
                  public | function | Generates a unique random string containing letters and numbers. |