You are here

class VueBlockDeriverTest in Decoupled Blocks: Vue.js 8

@coversDefaultClass \Drupal\pdb_vue\Plugin\Derivative\VueBlockDeriver @group pdb_vue

Hierarchy

Expanded class hierarchy of VueBlockDeriverTest

File

tests/src/Unit/Plugin/Derivative/VueBlockDeriverTest.php, line 14

Namespace

Drupal\Tests\pdb_vue\Unit\Plugin\Derivative
View source
class VueBlockDeriverTest extends UnitTestCase {

  /**
   * Mocked Component Discovery.
   *
   * @var \Drupal\pdb\ComponentDiscoveryInterface
   */
  protected $componentDiscovery;

  /**
   * The mocked config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactory|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $configFactory;

  /**
   * Instance of the Block Deriver.
   *
   * @var \Drupal\pdb_vue\Plugin\Derivative\VueBlockDeriver
   */
  protected $deriver;

  /**
   * Create the setup for constants and configFactory stub.
   */
  protected function setUp() {
    parent::setUp();

    // Stub the Config Factory.
    $this->configFactory = $this
      ->getConfigFactoryStub([
      'pdb_vue.settings' => [
        'development_mode' => 0,
      ],
    ]);

    // Mock the UUID service.
    $this->componentDiscovery = $this
      ->prophesize(ComponentDiscoveryInterface::CLASS);
    $this->componentDiscovery
      ->getComponents()
      ->willReturn([
      'block_1' => (object) [
        'type' => 'pdb',
        'info' => [
          'name' => 'Block 1',
          'machine_name' => 'block_1',
          'presentation' => 'vue',
        ],
      ],
      'vue_example_1' => (object) [
        'type' => 'pdb',
        'info' => [
          'name' => 'Vue Example 1',
          'type' => 'vue-example-1',
          'presentation' => 'vue',
        ],
      ],
    ]);
    $this->deriver = new VueBlockDeriver($this->componentDiscovery
      ->reveal(), $this->configFactory);
  }

  /**
   * Tests the create method.
   *
   * @see ::create()
   */
  public function testCreate() {
    $base_plugin_id = 'pdb_vue';
    $container = $this
      ->prophesize(ContainerInterface::CLASS);
    $container
      ->get('pdb.component_discovery')
      ->willReturn($this->componentDiscovery);
    $container
      ->get('config.factory')
      ->willReturn($this->configFactory);
    $instance = VueBlockDeriver::create($container
      ->reveal(), $base_plugin_id);
    $this
      ->assertInstanceOf('Drupal\\pdb_vue\\Plugin\\Derivative\\VueBlockDeriver', $instance);
  }

  /**
   * Tests the getDerivativeDefinitions() method.
   */
  public function testGetDerivativeDefinitions() {
    $base_plugin_definition = [
      'provider' => 'pdb_vue',
    ];

    // vue_example_1 should not appear due to debug mode being off.
    $expected = [
      'block_1' => [
        'info' => [
          'name' => 'Block 1',
          'machine_name' => 'block_1',
          'presentation' => 'vue',
        ],
        'provider' => 'pdb_vue',
        'admin_label' => 'Block 1',
        'cache' => [
          'max-age' => 0,
        ],
      ],
    ];
    $return = $this->deriver
      ->getDerivativeDefinitions($base_plugin_definition);
    $this
      ->assertArrayEquals($expected, $return);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
VueBlockDeriverTest::$componentDiscovery protected property Mocked Component Discovery.
VueBlockDeriverTest::$configFactory protected property The mocked config factory.
VueBlockDeriverTest::$deriver protected property Instance of the Block Deriver.
VueBlockDeriverTest::setUp protected function Create the setup for constants and configFactory stub. Overrides UnitTestCase::setUp
VueBlockDeriverTest::testCreate public function Tests the create method.
VueBlockDeriverTest::testGetDerivativeDefinitions public function Tests the getDerivativeDefinitions() method.