3 namespace Drupal\media\Tests;
5 use Drupal\simpletest\WebTestBase;
8 * Ensures that media bundle for instagram can be created.
12 class InstagramBundleTest extends WebTestBase {
14 * Exempt from strict schema checking.
16 * @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
20 protected $strictConfigSchema = FALSE;
27 public static $modules = [
30 'media_entity_instagram',
37 * The test media bundle.
39 * @var \Drupal\media_entity\MediaBundleInterface
41 protected $testBundle;
46 protected function setUp() {
48 $this->testBundle = $this->container->get('entity.manager')->getStorage('media_bundle')->load('instagram');
50 $adminUser = $this->drupalCreateUser([
57 'access media overview',
59 $this->drupalLogin($adminUser);
63 * Tests instagram media bundle creation from config files.
65 public function testMediaBundleCreationFromModule() {
66 $type_configuration = [
67 'use_instagram_api' => FALSE,
68 'source_field' => 'field_instagram_url',
72 'shortcode' => 'field_instagram_shortcode',
75 $this->assertTrue((bool) $this->testBundle, 'The media bundle from default configuration has been created in the database.');
76 $this->assertEqual($this->testBundle->get('label'), 'Instagram Post', 'Correct label detected.');
77 $this->assertEqual($this->testBundle->get('description'), 'Use this to attach Instagram posts to your content.', 'Correct description detected.');
78 $this->assertEqual($this->testBundle->get('type'), 'instagram', 'Correct plugin ID detected.');
79 $this->assertEqual($this->testBundle->get('type_configuration'), $type_configuration, 'Type configuration correct.');
80 $this->assertEqual($this->testBundle->get('field_map'), $field_map, 'Correct field map detected.');
84 * Tests item creation and thumbnail.
86 public function testMediaBundleItemCreation() {
87 // Define the media item name.
88 $name = $this->randomMachineName();
89 $instagram_url = 'https://www.instagram.com/p/C/';
91 'name[0][value]' => $name,
92 'field_instagram_url[0][uri]' => $instagram_url,
95 // Save the Instagram post.
96 $this->drupalPostForm('media/add/' . $this->testBundle->id(), $edit, t('Save and publish'));
98 // Assert that the formatter exists on this page.
99 $this->assertFieldByXPath('//iframe');
101 // Let's retrieve the media id and corresponding media entity object.
102 $media_id = $this->container->get('entity.query')->get('media')->condition('bundle', 'instagram')->sort('created', 'DESC')->execute();
103 $media_id = reset($media_id);
104 /** @var \Drupal\media_entity\MediaInterface $media */
105 $media = $this->container->get('entity_type.manager')
106 ->getStorage('media')
107 ->loadUnchanged($media_id);
108 $properties = $media->toArray();
109 $this->assertEqual($media->get('field_instagram_shortcode')[0]->getValue()['value'], "C", "Correct shortcode stored.");