Version 1
[yaffs-website] / web / modules / contrib / crop / tests / src / Kernel / CropEntityProvidersTest.php
1 <?php
2
3 namespace Drupal\Tests\crop\Kernel;
4
5 use Drupal\crop\EntityProviderNotFoundException;
6
7 /**
8  * Tests entity provider plugins.
9  *
10  * @group crop
11  */
12 class CropEntityProvidersTest extends CropUnitTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var array
18    */
19   public static $modules = ['crop', 'file', 'image', 'user', 'system'];
20
21   /**
22    * {@inheritdoc}
23    */
24   protected function setUp() {
25     parent::setUp();
26
27     $this->container->get('entity.manager')
28       ->onEntityTypeCreate($this->container->get('entity.manager')->getDefinition('file'));
29   }
30
31   /**
32    * Tests file provider plugin.
33    */
34   public function testCropEffect() {
35     $file = $this->getTestFile();
36     $file->save();
37
38     // Create crop.
39     $values = [
40       'type' => $this->cropType->id(),
41       'entity_id' => $file->id(),
42       'entity_type' => 'file',
43       'uri' => $file->getFileUri(),
44       'x' => '190',
45       'y' => '120',
46       'width' => '50',
47       'height' => '50',
48     ];
49     /** @var \Drupal\crop\CropInterface $crop */
50     $crop = $this->container->get('entity.manager')->getStorage('crop')->create($values);
51     $crop->save();
52
53     try {
54       $provider = $crop->provider();
55       $this->assertTrue(TRUE, 'File entity provider plugin was found.');
56     }
57     catch (EntityProviderNotFoundException $e) {
58       $this->assertTrue(FALSE, 'File entity provider plugin was found.');
59     }
60
61     $this->assertEquals($provider->uri($file), $file->getFileUri(), 'File provider plugin returned correct URI.');
62   }
63
64 }