Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / media_entity_instagram / tests / src / Functional / InstagramEmbedFormatterTest.php
1 <?php
2
3 namespace Drupal\Tests\media_entity_instagram\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\Tests\media\Functional\MediaFunctionalTestCreateMediaTypeTrait;
7
8 /**
9  * Tests for Instagram embed formatter.
10  *
11  * @group media_entity_instagram
12  */
13 class InstagramEmbedFormatterTest extends BrowserTestBase {
14
15   use MediaFunctionalTestCreateMediaTypeTrait;
16
17   /**
18    * {@inheritdoc}
19    */
20   protected static $modules = [
21     'media_entity_instagram',
22     'media',
23     'node',
24     'field_ui',
25     'views_ui',
26     'block',
27   ];
28
29   /**
30    * The test media type.
31    *
32    * @var \Drupal\media\MediaTypeInterface
33    */
34   protected $testBundle;
35
36   /**
37    * {@inheritdoc}
38    */
39   protected function setUp() {
40     parent::setUp();
41
42     $this->testBundle = $this->createMediaType(['bundle' => 'instagram'], 'instagram');
43     $this->drupalPlaceBlock('local_actions_block');
44     $account = $this->drupalCreateUser([
45       'administer media',
46       'administer media types',
47       'administer media fields',
48       'administer media form display',
49       'administer media display',
50       // Media entity permissions.
51       'view media',
52       'create media',
53       'update media',
54       'update any media',
55       'delete media',
56       'delete any media',
57       // Other permissions.
58       'administer views',
59     ]);
60     $this->drupalLogin($account);
61   }
62
63   /**
64    * Tests adding and editing an instagram embed formatter.
65    */
66   public function testFieldFormatter() {
67     // Test and create one media bundle.
68     $bundle = $this->testBundle;
69
70     $assert = $this->assertSession();
71
72     // Assert that the media bundle has the expected values before proceeding.
73     $this->drupalGet('admin/structure/media/manage/' . $bundle->id());
74     $assert->fieldValueEquals('label', $bundle->label());
75     $assert->fieldValueEquals('source', 'instagram');
76     $assert->pageTextContains('Instagram field is used to store the essential information about the media item.');
77     $assert->buttonExists('Save')->press();
78     $assert->pageTextContains('The media type ' . $bundle->label() . ' has been updated.');
79
80     entity_get_display('media', $bundle->id(), 'default')
81       ->setComponent('field_media_instagram', [
82         'label' => 'above',
83         'type' => 'instagram_embed',
84         'settings' => [
85           'hidecaption' => FALSE,
86         ],
87       ])
88       ->save();
89
90     // Set and save the settings of the new field.
91     $this->drupalGet('admin/structure/media/manage/' . $bundle->id() . '/display');
92     $assert->pageTextContains('Caption: Visible');
93
94     // Create and save the media with an instagram media code.
95     $this->drupalGet('media/add/' . $bundle->id());
96
97     $assert->fieldExists('Name')->setValue('My test instagram');
98     // Example instagram from https://www.instagram.com/developer/embedding
99     $assert->fieldExists('Instagram')->setValue('https://www.instagram.com/p/bNd86MSFv6/');
100     $assert->buttonExists('Save')->press();
101
102     // Assert that the media has been successfully saved.
103     $assert->pageTextContains('My test instagram');
104     $assert->pageTextContains('Instagram');
105
106     // Assert that the formatter exists on this page and that it has absolute
107     // size.
108     $assert->elementExists('css', 'blockquote');
109     $assert->responseContains('platform.instagram.com/en_US/embeds.js');
110   }
111
112 }