ContentEntityStorageBaseTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace Drupal\KernelTests\Core\Entity;
  3. use Drupal\KernelTests\KernelTestBase;
  4. /**
  5. * @coversDefaultClass \Drupal\Core\Entity\ContentEntityStorageBase
  6. *
  7. * @group Entity
  8. */
  9. class ContentEntityStorageBaseTest extends KernelTestBase {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. protected static $modules = ['entity_test', 'user'];
  14. /**
  15. * {@inheritdoc}
  16. */
  17. protected function setUp() {
  18. parent::setUp();
  19. $this->installEntitySchema('entity_test');
  20. $this->installEntitySchema('user');
  21. }
  22. /**
  23. * @covers ::create
  24. *
  25. * @dataProvider providerTestCreate
  26. */
  27. public function testCreate($bundle) {
  28. $storage = $this->container->get('entity_type.manager')->getStorage('entity_test');
  29. $entity = $storage->create(['type' => $bundle]);
  30. $this->assertEquals('test_bundle', $entity->bundle());
  31. }
  32. /**
  33. * Provides test data for testCreate().
  34. */
  35. public function providerTestCreate() {
  36. return [
  37. ['scalar' => 'test_bundle'],
  38. ['array keyed by delta' => [0 => ['value' => 'test_bundle']]],
  39. ['array keyed by main property name' => ['value' => 'test_bundle']],
  40. ];
  41. }
  42. /**
  43. * @covers ::create
  44. */
  45. public function testReCreate() {
  46. $storage = $this->container->get('entity_type.manager')->getStorage('entity_test');
  47. $values = $storage->create(['type' => 'test_bundle'])->toArray();
  48. $entity = $storage->create($values);
  49. $this->assertEquals('test_bundle', $entity->bundle());
  50. }
  51. }