public function TweetBundleTest::testMediaBundleItemCreation in D7 Media 8
Tests item creation.
File
- src/
Tests/ TweetBundleTest.php, line 90
Class
- TweetBundleTest
- Ensures that media bundle for tweets can be created.
Namespace
Drupal\media\TestsCode
public function testMediaBundleItemCreation() {
// Define the media item name.
$name = $this
->randomMachineName();
$tweet_url = 'https://twitter.com/jack/status/20';
$edit = [
'name[0][value]' => $name,
'field_tweet_url[0][uri]' => $tweet_url,
];
// Save the tweet.
$this
->drupalPostForm('media/add/' . $this->testBundle
->id(), $edit, t('Save and publish'));
// Let's retrieve the media id.
$media_id = $this->container
->get('entity.query')
->get('media')
->condition('bundle', 'tweet')
->sort('created', 'DESC')
->execute();
$media_id = reset($media_id);
$media = $this->container
->get('entity_type.manager')
->getStorage('media')
->loadUnchanged($media_id);
$properties = $media
->toArray();
$this
->assertEqual($media
->get('field_tweet_author')[0]
->getValue()['value'], "jack", "Correct tweet author stored.");
$this
->assertEqual($media
->get('field_tweet_id')[0]
->getValue()['value'], "20", "Correct tweet id stored.");
}