You are here

protected function VueBlockTest::setUp in Decoupled Blocks: Vue.js 8

Create the setup for constants and configFactory stub.

Overrides UnitTestCase::setUp

File

tests/src/Unit/Plugin/Block/VueBlockTest.php, line 34

Class

VueBlockTest
@coversDefaultClass \Drupal\pdb_vue\Plugin\Block\VueBlock @group pdb_vue

Namespace

Drupal\Tests\pdb_vue\Unit\Plugin\Block

Code

protected function setUp() {
  parent::setUp();

  // Stub the Config Factory.
  $this->configFactory = $this
    ->getConfigFactoryStub([
    'pdb_vue.settings' => [
      'version' => 'vue2',
      'development_mode' => 1,
      'use_spa' => 1,
      'spa_element' => '#page-wrapper',
    ],
  ]);

  // Mock the UUID service.
  $uuid = $this
    ->prophesize(UuidInterface::CLASS);
  $uuid
    ->generate()
    ->willReturn('uuid');

  // Create a container needed by PdbBlock.
  $container = new ContainerBuilder();
  $container
    ->set('uuid', $uuid
    ->reveal());
  \Drupal::setContainer($container);
  $configuration = [
    'pdb_configuration' => [
      'testField' => 'test',
      'second_field' => 1,
    ],
  ];
  $plugin_id = 'pdb_vue';
  $plugin_definition = [
    'provider' => 'pdb_vue',
    'info' => [
      'machine_name' => 'vue-example-1',
      'component' => TRUE,
    ],
  ];
  $this->plugin = new VueBlock($configuration, $plugin_id, $plugin_definition, $this->configFactory);
}