|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\media\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\simpletest\WebTestBase; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Ensures that media bundle for twitter can be created. |
|
9
|
|
|
* |
|
10
|
|
|
* @group media |
|
11
|
|
|
*/ |
|
12
|
|
|
class TwitterBundleTest extends WebTestBase { |
|
13
|
|
|
/** |
|
14
|
|
|
* Exempt from strict schema checking. |
|
15
|
|
|
* |
|
16
|
|
|
* @see \Drupal\Core\Config\Testing\ConfigSchemaChecker |
|
17
|
|
|
* |
|
18
|
|
|
* @var bool |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $strictConfigSchema = FALSE; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Modules to enable. |
|
24
|
|
|
* |
|
25
|
|
|
* @var array |
|
26
|
|
|
*/ |
|
27
|
|
|
public static $modules = [ |
|
28
|
|
|
'media', |
|
29
|
|
|
'media_entity', |
|
30
|
|
|
'media_entity_twitter', |
|
31
|
|
|
'node', |
|
32
|
|
|
'link', |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* The test media bundle. |
|
37
|
|
|
* |
|
38
|
|
|
* @var \Drupal\media_entity\MediaBundleInterface |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $testBundle; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function setUp() { |
|
46
|
|
|
parent::setUp(); |
|
47
|
|
|
$this->testBundle = $this->container->get('entity.manager')->getStorage('media_bundle')->load('twitter'); |
|
48
|
|
|
|
|
49
|
|
|
$adminUser = $this->drupalCreateUser([ |
|
50
|
|
|
'view media', |
|
51
|
|
|
'create media', |
|
52
|
|
|
'update media', |
|
53
|
|
|
'update any media', |
|
54
|
|
|
'delete media', |
|
55
|
|
|
'delete any media', |
|
56
|
|
|
'access media overview', |
|
57
|
|
|
]); |
|
58
|
|
|
$this->drupalLogin($adminUser); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Tests twitter media bundle creation from config files. |
|
63
|
|
|
*/ |
|
64
|
|
|
public function testMediaBundleCreationFromModule() { |
|
65
|
|
|
$type_configuration = [ |
|
66
|
|
|
'use_twitter_api' => FALSE, |
|
67
|
|
|
'source_field' => 'field_tweet_url', |
|
68
|
|
|
'consumer_key' => '', |
|
69
|
|
|
'consumer_secret' => '', |
|
70
|
|
|
'oauth_access_token' => '', |
|
71
|
|
|
'oauth_access_token_secret' => '', |
|
72
|
|
|
]; |
|
73
|
|
|
$field_map = [ |
|
74
|
|
|
'id' => 'field_tweet_id', |
|
75
|
|
|
'user' => 'field_tweet_username', |
|
76
|
|
|
]; |
|
77
|
|
|
|
|
78
|
|
|
$this->assertTrue((bool) $this->testBundle, 'The media bundle from default configuration has been created in the database.'); |
|
79
|
|
|
$this->assertEqual($this->testBundle->get('label'), 'Twitter', 'Correct label detected.'); |
|
80
|
|
|
$this->assertEqual($this->testBundle->get('description'), 'Use this to attach tweets to your content.', 'Correct description detected.'); |
|
81
|
|
|
$this->assertEqual($this->testBundle->get('type'), 'twitter', 'Correct plugin ID detected.'); |
|
82
|
|
|
$this->assertEqual($this->testBundle->get('type_configuration'), $type_configuration, 'Type configuration correct.'); |
|
83
|
|
|
$this->assertEqual($this->testBundle->get('field_map'), $field_map, 'Correct field map detected.'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Tests item creation. |
|
88
|
|
|
*/ |
|
89
|
|
|
public function testMediaBundleItemCreation() { |
|
90
|
|
|
// Define the media item name. |
|
91
|
|
|
$name = $this->randomMachineName(); |
|
92
|
|
|
$tweet_url = 'https://twitter.com/jack/status/20'; |
|
93
|
|
|
$edit = [ |
|
94
|
|
|
'name[0][value]' => $name, |
|
95
|
|
|
'field_tweet_url[0][uri]' => $tweet_url, |
|
96
|
|
|
]; |
|
97
|
|
|
|
|
98
|
|
|
// Save the tweet. |
|
99
|
|
|
$this->drupalPostForm('media/add/' . $this->testBundle->id(), $edit, t('Save and publish')); |
|
100
|
|
|
// Let's retrieve the media id. |
|
101
|
|
|
$media_id = $this->container->get('entity.query')->get('media')->condition('bundle', 'twitter')->sort('created', 'DESC')->execute(); |
|
102
|
|
|
$media_id = reset($media_id); |
|
103
|
|
|
$media = $this->container->get('entity_type.manager') |
|
104
|
|
|
->getStorage('media') |
|
105
|
|
|
->loadUnchanged($media_id); |
|
106
|
|
|
$properties = $media->toArray(); |
|
|
|
|
|
|
107
|
|
|
$this->assertEqual($media->get('field_tweet_username')[0]->getValue()['value'], "jack", "Correct username stored."); |
|
108
|
|
|
$this->assertEqual($media->get('field_tweet_id')[0]->getValue()['value'], "20", "Correct tweet id stored."); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
} |
|
112
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.