3 namespace Drupal\Tests\media_entity_instagram\Functional;
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\Tests\media\Functional\MediaFunctionalTestCreateMediaTypeTrait;
9 * Tests for Instagram embed formatter.
11 * @group media_entity_instagram
13 class InstagramEmbedFormatterTest extends BrowserTestBase {
15 use MediaFunctionalTestCreateMediaTypeTrait;
20 protected static $modules = [
21 'media_entity_instagram',
30 * The test media type.
32 * @var \Drupal\media\MediaTypeInterface
34 protected $testBundle;
39 protected function setUp() {
42 $this->testBundle = $this->createMediaType(['bundle' => 'instagram'], 'instagram');
43 $this->drupalPlaceBlock('local_actions_block');
44 $account = $this->drupalCreateUser([
46 'administer media types',
47 'administer media fields',
48 'administer media form display',
49 'administer media display',
50 // Media entity permissions.
60 $this->drupalLogin($account);
64 * Tests adding and editing an instagram embed formatter.
66 public function testFieldFormatter() {
67 // Test and create one media bundle.
68 $bundle = $this->testBundle;
70 $assert = $this->assertSession();
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.');
80 entity_get_display('media', $bundle->id(), 'default')
81 ->setComponent('field_media_instagram', [
83 'type' => 'instagram_embed',
85 'hidecaption' => FALSE,
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');
94 // Create and save the media with an instagram media code.
95 $this->drupalGet('media/add/' . $bundle->id());
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();
102 // Assert that the media has been successfully saved.
103 $assert->pageTextContains('My test instagram');
104 $assert->pageTextContains('Instagram');
106 // Assert that the formatter exists on this page and that it has absolute
108 $assert->elementExists('css', 'blockquote');
109 $assert->responseContains('platform.instagram.com/en_US/embeds.js');