You are here

class EckEntityTest in Entity Construction Kit (ECK) 8

Same name in this branch
  1. 8 tests/src/Unit/EckEntityTest.php \Drupal\Tests\eck\Unit\EckEntityTest
  2. 8 tests/src/Kernel/EckEntityTest.php \Drupal\Tests\eck\Kernel\EckEntityTest
  3. 8 tests/src/Kernel/Plugin/migrate/source/d7/EckEntityTest.php \Drupal\Tests\eck\Kernel\Plugin\migrate\source\d7\EckEntityTest

Tests eck entities.

@group eck

Hierarchy

Expanded class hierarchy of EckEntityTest

File

tests/src/Unit/EckEntityTest.php, line 16

Namespace

Drupal\Tests\eck\Unit
View source
class EckEntityTest extends UnitTestBase {

  /**
   * Provides test base field definition data.
   *
   * @return array
   *   The test data.
   */
  public function baseFieldDefinitionTestDataProvider() {
    return [
      'default' => [
        'config' => [],
        'expectedFieldIds' => [
          'id',
          'uuid',
          'langcode',
          'type',
        ],
      ],
      'with title field' => [
        'config' => [
          'title' => TRUE,
        ],
        'expectedFieldIds' => [
          'id',
          'uuid',
          'langcode',
          'type',
          'title',
        ],
      ],
      'with uid field' => [
        'config' => [
          'uid' => TRUE,
        ],
        'expectedFieldIds' => [
          'id',
          'uuid',
          'langcode',
          'type',
          'uid',
        ],
      ],
      'with created field' => [
        'config' => [
          'created' => TRUE,
        ],
        'expectedFieldIds' => [
          'id',
          'uuid',
          'langcode',
          'type',
          'created',
        ],
      ],
      'with changed field' => [
        'config' => [
          'changed' => TRUE,
        ],
        'expectedFieldIds' => [
          'id',
          'uuid',
          'langcode',
          'type',
          'changed',
        ],
      ],
    ];
  }

  /**
   * Tests base field definitions.
   *
   * @param array $config
   *   The configuration.
   * @param array $expectedBaseFieldDefinitionIds
   *   The expected base field definition ids.
   *
   * @dataProvider baseFieldDefinitionTestDataProvider
   *
   * @throws \ReflectionException
   */
  public function testBaseFieldDefinitions(array $config, array $expectedBaseFieldDefinitionIds) {
    $configs = [
      'eck.eck_entity_type.eck_entity_type' => $config,
    ];
    $this
      ->registerServiceWithContainerMock('config.factory', $this
      ->getConfigFactoryStub($configs));
    $annotationReader = new SimpleAnnotationReader();
    $annotationReader
      ->addNamespace((new \ReflectionClass(Translation::class))
      ->getNamespaceName());
    $annotationReader
      ->addNamespace((new \ReflectionClass(ConfigEntityType::class))
      ->getNamespaceName());
    $definition = $annotationReader
      ->getClassAnnotation(new \ReflectionClass(EckEntityType::class), ConfigEntityType::class);
    $this
      ->assertArrayKeysEqual($expectedBaseFieldDefinitionIds, EckEntity::baseFieldDefinitions($definition
      ->get()));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EckEntityTest::baseFieldDefinitionTestDataProvider public function Provides test base field definition data.
EckEntityTest::testBaseFieldDefinitions public function Tests base field definitions.
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.
UnitTestBase::$entities protected property The entities.
UnitTestBase::$services private property The services.
UnitTestBase::addEntityToStorage protected function Adds an entity to the mock storage.
UnitTestBase::assertArrayKeysEqual protected function Asserts that the array keys of an array equal the expected keys.
UnitTestBase::containerMockGetServiceCallback public function Callback for the get method on the mocked service container.
UnitTestBase::createEckEntityType protected function Creates a test entity type.
UnitTestBase::createLanguageManagerMock protected function Creates the language manager mock.
UnitTestBase::entityStorageLoadMultiple public function Callback for entity storage load multiple.
UnitTestBase::getEntityManagerMock private function Retrieves the entity manager mock.
UnitTestBase::getEntityStorageMock private function Retrieves the entity storage mock.
UnitTestBase::getEntityTypeManagerMock private function Retrieves the entity type manager mock.
UnitTestBase::getEntityTypeRepositoryMock private function Retrieves the entity type repository mock.
UnitTestBase::getNewUserMock private function Creates and returns a mocked user.
UnitTestBase::prepareContainer private function Prepares a mocked service container.
UnitTestBase::registerServiceWithContainerMock protected function Registers a (mocked) service with the mocked service container.
UnitTestBase::setUp protected function Overrides UnitTestCase::setUp 1
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.