|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\Tests\Driver\Kernel\Drupal8\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Driver\Wrapper\Entity\DriverEntityDrupal8; |
|
6
|
|
|
use Drupal\Tests\Driver\Kernel\Drupal8\Entity\DriverEntityKernelTestBase; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Tests the driver's handling of generic content entities using 'entity_test'. |
|
10
|
|
|
* We provide no specific handling for this entity type, so this tests the |
|
11
|
|
|
* fallback handling for generic content entities. |
|
12
|
|
|
* |
|
13
|
|
|
* @group Driver |
|
14
|
|
|
*/ |
|
15
|
|
|
class GenericContentEntityTest extends DriverEntityKernelTestBase |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Machine name of the entity type being tested. |
|
20
|
|
|
* |
|
21
|
|
|
* @string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $entityType = 'entity_test'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Test that an entity_test can be created and deleted. |
|
27
|
|
|
*/ |
|
28
|
|
|
public function testEntityTestCreateDelete() |
|
29
|
|
|
{ |
|
30
|
|
|
$name = $this->randomString(); |
|
31
|
|
|
$entity_test = (object) [ |
|
32
|
|
|
'name' => $name, |
|
33
|
|
|
]; |
|
34
|
|
|
$entity_test = $this->driver->createEntity('entity_test', $entity_test); |
|
35
|
|
|
|
|
36
|
|
|
// The test driverfield plugin has been matched, which mutates the text. |
|
37
|
|
|
$processedName = 'now' . $name . 'processed'; |
|
38
|
|
|
$entities = $this->storage->loadByProperties(['name' => $processedName]); |
|
39
|
|
|
$this->assertEquals(1, count($entities)); |
|
40
|
|
|
|
|
41
|
|
|
// Check the id of the new entity has been added to the returned object. |
|
42
|
|
|
$entity = reset($entities); |
|
43
|
|
|
$this->assertEquals($entity->id(), $entity_test->id); |
|
44
|
|
|
|
|
45
|
|
|
// Check the entity can be deleted. |
|
46
|
|
|
$this->driver->entityDelete('entity_test', $entity_test); |
|
47
|
|
|
$entities = $this->storage->loadByProperties(['name' => $processedName]); |
|
48
|
|
|
$this->assertEquals(0, count($entities)); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Test that an entity_test can be created and deleted. |
|
53
|
|
|
*/ |
|
54
|
|
|
public function testEntityTestCreateDeleteByWrapper() |
|
55
|
|
|
{ |
|
56
|
|
|
$name = $this->randomString(); |
|
57
|
|
|
$fields = [ |
|
58
|
|
|
'name' => [$name], |
|
59
|
|
|
]; |
|
60
|
|
|
$entity_test = DriverEntityDrupal8::create($fields, $this->entityType)->save(); |
|
61
|
|
|
|
|
62
|
|
|
// The test driverfield plugin has been matched, which mutates the text. |
|
63
|
|
|
$processedName = 'now' . $name . 'processed'; |
|
64
|
|
|
$entities = $this->storage->loadByProperties(['name' => $processedName]); |
|
65
|
|
|
$this->assertEquals(1, count($entities)); |
|
66
|
|
|
|
|
67
|
|
|
// Check the id of the new entity has been added to the returned object. |
|
68
|
|
|
$entity = reset($entities); |
|
69
|
|
|
$this->assertEquals($entity->id(), $entity_test->id); |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
// Check the entity can be deleted. |
|
72
|
|
|
$entity_test->delete(); |
|
73
|
|
|
$entities = $this->storage->loadByProperties(['name' => $name]); |
|
74
|
|
|
$this->assertEquals(0, count($entities)); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.