comparison core/modules/media/tests/src/Functional/MediaRevisionTest.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
23 23
24 /** @var \Drupal\Core\Entity\Sql\SqlContentEntityStorage $media_storage */ 24 /** @var \Drupal\Core\Entity\Sql\SqlContentEntityStorage $media_storage */
25 $media_storage = $this->container->get('entity.manager')->getStorage('media'); 25 $media_storage = $this->container->get('entity.manager')->getStorage('media');
26 26
27 // Create a media type and media item. 27 // Create a media type and media item.
28 $media_type = $this->createMediaType(); 28 $media_type = $this->createMediaType('test');
29 $media = $media_storage->create([ 29 $media = $media_storage->create([
30 'bundle' => $media_type->id(), 30 'bundle' => $media_type->id(),
31 'name' => 'Unnamed', 31 'name' => 'Unnamed',
32 ]); 32 ]);
33 $media->save(); 33 $media->save();
78 $assert = $this->assertSession(); 78 $assert = $this->assertSession();
79 79
80 $uri = 'temporary://foo.txt'; 80 $uri = 'temporary://foo.txt';
81 file_put_contents($uri, $this->randomString(128)); 81 file_put_contents($uri, $this->randomString(128));
82 82
83 $this->createMediaType(['bundle' => 'file', 'new_revision' => TRUE], 'file'); 83 $this->createMediaType('file', ['id' => 'file', 'new_revision' => TRUE]);
84 84
85 // Create a media item. 85 // Create a media item.
86 $this->drupalGet('/media/add/file'); 86 $this->drupalGet('/media/add/file');
87 $page = $this->getSession()->getPage(); 87 $page = $this->getSession()->getPage();
88 $page->fillField('Name', 'Foobar'); 88 $page->fillField('Name', 'Foobar');
89 $page->attachFileToField('File', $this->container->get('file_system')->realpath($uri)); 89 $page->attachFileToField('File', $this->container->get('file_system')->realpath($uri));
90 $page->pressButton('Save'); 90 $page->pressButton('Save');
91 $assert->addressMatches('/^\/media\/[0-9]+$/'); 91 $assert->addressEquals('admin/content/media');
92 92
93 // The media item was just created, so it should only have one revision. 93 // The media item was just created, so it should only have one revision.
94 $media = $this->container 94 $media = $this->container
95 ->get('entity_type.manager') 95 ->get('entity_type.manager')
96 ->getStorage('media') 96 ->getStorage('media')
117 * Tests creating revisions of a Image media item. 117 * Tests creating revisions of a Image media item.
118 */ 118 */
119 public function testImageMediaRevision() { 119 public function testImageMediaRevision() {
120 $assert = $this->assertSession(); 120 $assert = $this->assertSession();
121 121
122 $this->createMediaType(['bundle' => 'image', 'new_revision' => TRUE], 'image'); 122 $this->createMediaType('image', ['id' => 'image', 'new_revision' => TRUE]);
123 123
124 /** @var \Drupal\field\FieldConfigInterface $field */ 124 /** @var \Drupal\field\FieldConfigInterface $field */
125 // Disable the alt text field, because this is not a JavaScript test and 125 // Disable the alt text field, because this is not a JavaScript test and
126 // the alt text field will therefore not appear without a full page refresh. 126 // the alt text field will therefore not appear without a full page refresh.
127 $field = FieldConfig::load('media.image.field_media_image'); 127 $field = FieldConfig::load('media.image.field_media_image');
133 133
134 // Create a media item. 134 // Create a media item.
135 $this->drupalGet('/media/add/image'); 135 $this->drupalGet('/media/add/image');
136 $page = $this->getSession()->getPage(); 136 $page = $this->getSession()->getPage();
137 $page->fillField('Name', 'Foobar'); 137 $page->fillField('Name', 'Foobar');
138 $page->attachFileToField('Image', \Drupal::root() . '/core/modules/media/tests/fixtures/example_1.jpeg'); 138 $page->attachFileToField('Image', $this->root . '/core/modules/media/tests/fixtures/example_1.jpeg');
139 $page->pressButton('Save'); 139 $page->pressButton('Save');
140 $assert->addressMatches('/^\/media\/[0-9]+$/'); 140 $assert->addressEquals('admin/content/media');
141 141
142 // The media item was just created, so it should only have one revision. 142 // The media item was just created, so it should only have one revision.
143 $media = $this->container 143 $media = $this->container
144 ->get('entity_type.manager') 144 ->get('entity_type.manager')
145 ->getStorage('media') 145 ->getStorage('media')
188 */ 188 */
189 protected function assertRevisionCount(EntityInterface $entity, $expected_revisions) { 189 protected function assertRevisionCount(EntityInterface $entity, $expected_revisions) {
190 $entity_type = $entity->getEntityType(); 190 $entity_type = $entity->getEntityType();
191 191
192 $count = $this->container 192 $count = $this->container
193 ->get('entity.query') 193 ->get('entity_type.manager')
194 ->get($entity_type->id()) 194 ->getStorage($entity_type->id())
195 ->getQuery()
195 ->count() 196 ->count()
196 ->allRevisions() 197 ->allRevisions()
197 ->condition($entity_type->getKey('id'), $entity->id()) 198 ->condition($entity_type->getKey('id'), $entity->id())
198 ->execute(); 199 ->execute();
199 200