You are here

MultiversionIndexFactoryTest.php in Multiversion 8.2

Same filename and directory in other branches
  1. 8 tests/src/Kernel/MultiversionIndexFactoryTest.php

File

tests/src/Kernel/MultiversionIndexFactoryTest.php
View source
<?php

namespace Drupal\Tests\multiversion\Kernel;

use Drupal\KernelTests\KernelTestBase;
use Drupal\multiversion\Entity\Index\EntityIndexInterface;
use Drupal\multiversion\Entity\Index\RevisionIndexInterface;
use Drupal\multiversion\Entity\Index\RevisionTreeIndexInterface;
use Drupal\multiversion\Entity\Index\SequenceIndexInterface;
use Drupal\multiversion\Entity\Index\UuidIndexInterface;
use Drupal\workspaces\Entity\Workspace;

/**
 * @group multiversion
 */
class MultiversionIndexFactoryTest extends KernelTestBase {

  /**
   * {@inheritdoc}
   */
  public static $modules = [
    'multiversion',
    'workspaces',
    'key_value',
    'serialization',
    'user',
    'system',
  ];

  /** @var  \Drupal\multiversion\Entity\Index\MultiversionIndexFactory */
  protected $multiversionIndexFactory;

  /** @var  \Drupal\multiversion\Entity\WorkspaceInterface */
  protected $workspace;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this
      ->installEntitySchema('workspace');
    $this
      ->installConfig('multiversion');
    $this->multiversionIndexFactory = \Drupal::service('multiversion.entity_index.factory');
    $this->workspace = Workspace::create([
      'id' => 'le_workspace',
      'label' => 'Le Workspace',
    ]);
    $this->workspace
      ->save();
  }

  /**
   * Tests the factory.
   */
  public function testFactory() {

    // With workspace
    $sequence_index = $this->multiversionIndexFactory
      ->get('multiversion.entity_index.sequence', $this->workspace);
    $this
      ->assertTrue($sequence_index instanceof SequenceIndexInterface);
    $id_index = $this->multiversionIndexFactory
      ->get('multiversion.entity_index.id', $this->workspace);
    $this
      ->assertTrue($id_index instanceof EntityIndexInterface);
    $uuid_index = $this->multiversionIndexFactory
      ->get('multiversion.entity_index.uuid', $this->workspace);
    $this
      ->assertTrue($uuid_index instanceof UuidIndexInterface);
    $rev_index = $this->multiversionIndexFactory
      ->get('multiversion.entity_index.rev', $this->workspace);
    $this
      ->assertTrue($rev_index instanceof RevisionIndexInterface);
    $rev_tree_index = $this->multiversionIndexFactory
      ->get('multiversion.entity_index.rev.tree', $this->workspace);
    $this
      ->assertTrue($rev_tree_index instanceof RevisionTreeIndexInterface);

    // Without a workspace
    $sequence_index = $this->multiversionIndexFactory
      ->get('multiversion.entity_index.sequence');
    $this
      ->assertTrue($sequence_index instanceof SequenceIndexInterface);
    $id_index = $this->multiversionIndexFactory
      ->get('multiversion.entity_index.id');
    $this
      ->assertTrue($id_index instanceof EntityIndexInterface);
    $uuid_index = $this->multiversionIndexFactory
      ->get('multiversion.entity_index.uuid');
    $this
      ->assertTrue($uuid_index instanceof UuidIndexInterface);
    $rev_index = $this->multiversionIndexFactory
      ->get('multiversion.entity_index.rev');
    $this
      ->assertTrue($rev_index instanceof RevisionIndexInterface);
    $rev_tree_index = $this->multiversionIndexFactory
      ->get('multiversion.entity_index.rev.tree');
    $this
      ->assertTrue($rev_tree_index instanceof RevisionTreeIndexInterface);

    // Expecting an exception
    $this
      ->setExpectedException(\InvalidArgumentException::class);
    $this->multiversionIndexFactory
      ->get('non.existant.service.name');
  }

}

Classes

Namesort descending Description
MultiversionIndexFactoryTest @group multiversion