|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\Tests\Driver\Kernel\Drupal8\Field; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Tests\Driver\Kernel\Drupal8\Field\DriverFieldKernelTestBase; |
|
6
|
|
|
use Drupal\node\Entity\NodeType; |
|
7
|
|
|
use Drupal\node\Entity\Node; |
|
8
|
|
|
use Drupal\user\Entity\User; |
|
9
|
|
|
use Drupal\file\Entity\File; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Tests the driver's handling of image fields. |
|
13
|
|
|
* |
|
14
|
|
|
* @group driver |
|
15
|
|
|
*/ |
|
16
|
|
|
class ImageTest extends DriverFieldKernelTestBase |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* {@inheritdoc} |
|
21
|
|
|
*/ |
|
22
|
|
|
public static $modules = ['entity_test', 'field', 'image', 'file']; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Machine name of the field type being tested. |
|
26
|
|
|
* |
|
27
|
|
|
* @string |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $fieldType = 'image'; |
|
30
|
|
|
|
|
31
|
|
|
protected function setUp() |
|
32
|
|
|
{ |
|
33
|
|
|
parent::setUp(); |
|
34
|
|
|
$this->installEntitySchema('file'); |
|
35
|
|
|
$this->installSchema('file', ['file_usage']); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Test referencing an image by a uri. |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testImageFromUri() |
|
42
|
|
|
{ |
|
43
|
|
|
$fieldIntended = [ |
|
44
|
|
|
'http://www.google.com', |
|
45
|
|
|
]; |
|
46
|
|
|
$entity = $this->createTestEntity($fieldIntended); |
|
47
|
|
|
$this->assertValidField($entity); |
|
48
|
|
|
$field = $entity->get($this->fieldName); |
|
49
|
|
|
$fileId = $field->getValue()[0]['target_id']; |
|
50
|
|
|
$file = File::load($fileId); |
|
51
|
|
|
$this->assertFileExists($file->getFileUri()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Test referencing multiple images by uri. |
|
57
|
|
|
*/ |
|
58
|
|
|
public function testMultipleImagesFromUri() |
|
59
|
|
|
{ |
|
60
|
|
|
$fieldIntended = [ |
|
61
|
|
|
'http://www.google.com', |
|
62
|
|
|
'http://www.drupal.com', |
|
63
|
|
|
]; |
|
64
|
|
|
$entity = $this->createTestEntity($fieldIntended); |
|
65
|
|
|
$this->assertValidField($entity); |
|
66
|
|
|
$field = $entity->get($this->fieldName); |
|
67
|
|
|
$fileId1 = $field->getValue()[0]['target_id']; |
|
68
|
|
|
$fileId2 = $field->getValue()[1]['target_id']; |
|
69
|
|
|
$file1 = File::load($fileId1); |
|
70
|
|
|
$this->assertFileExists($file1->getFileUri()); |
|
71
|
|
|
$file2 = File::load($fileId2); |
|
72
|
|
|
$this->assertFileExists($file2->getFileUri()); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|