Mercurial > hg > isophonics-drupal-site
comparison core/modules/image/tests/src/Functional/ImageFieldValidateTest.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | 129ea1e6d783 |
children |
comparison
equal
deleted
inserted
replaced
17:129ea1e6d783 | 18:af1871eacc83 |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\Tests\image\Functional; | 3 namespace Drupal\Tests\image\Functional; |
4 | 4 |
5 use Drupal\Core\Field\FieldStorageDefinitionInterface; | |
5 use Drupal\Tests\TestFileCreationTrait; | 6 use Drupal\Tests\TestFileCreationTrait; |
6 | 7 |
7 /** | 8 /** |
8 * Tests validation functions such as min/max resolution. | 9 * Tests validation functions such as min/max resolution. |
9 * | 10 * |
204 $this->assertNoText(t('Alternative text field is required.')); | 205 $this->assertNoText(t('Alternative text field is required.')); |
205 $this->assertNoText(t('Title field is required.')); | 206 $this->assertNoText(t('Title field is required.')); |
206 } | 207 } |
207 | 208 |
208 /** | 209 /** |
210 * Tests creating an entity while leaving the image field empty. | |
211 * | |
212 * This is tested first with edit access to the image field allowed, and then | |
213 * with it forbidden. | |
214 * | |
215 * @dataProvider providerTestEmpty | |
216 */ | |
217 public function testEmpty($field_name, $required, $cardinality, $form_element_name, $expected_page_text_when_edit_access_allowed, $expected_page_text_when_edit_access_forbidden) { | |
218 $this->createImageField($field_name, 'article', ['cardinality' => $cardinality], ['required' => $required]); | |
219 | |
220 // Test with field edit access allowed. | |
221 $this->drupalGet('node/add/article'); | |
222 $this->assertSession()->fieldExists($form_element_name); | |
223 $edit = [ | |
224 'title[0][value]' => 'Article with edit-access-allowed image field', | |
225 ]; | |
226 $this->drupalPostForm(NULL, $edit, t('Save')); | |
227 $this->assertSession()->pageTextContains($expected_page_text_when_edit_access_allowed); | |
228 | |
229 // Test with field edit access forbidden. | |
230 \Drupal::service('module_installer')->install(['image_access_test_hidden']); | |
231 $this->drupalGet('node/add/article'); | |
232 $this->assertSession()->fieldNotExists($form_element_name); | |
233 $edit = [ | |
234 'title[0][value]' => 'Article with edit-access-forbidden image field', | |
235 ]; | |
236 $this->drupalPostForm(NULL, $edit, t('Save')); | |
237 $this->assertSession()->pageTextContains($expected_page_text_when_edit_access_forbidden); | |
238 } | |
239 | |
240 /** | |
241 * Data provider for ::testEmpty() | |
242 * | |
243 * @return array | |
244 * Test cases. | |
245 */ | |
246 public function providerTestEmpty() { | |
247 return [ | |
248 'optional-single' => ['field_image', FALSE, 1, 'files[field_image_0]', 'Article Article with edit-access-allowed image field has been created.', 'Article Article with edit-access-forbidden image field has been created.'], | |
249 'optional-unlimited' => ['field_image', FALSE, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'files[field_image_0][]', 'Article Article with edit-access-allowed image field has been created.', 'Article Article with edit-access-forbidden image field has been created.'], | |
250 'optional-multiple-limited' => ['field_image', FALSE, 2, 'files[field_image_0][]', 'Article Article with edit-access-allowed image field has been created.', 'Article Article with edit-access-forbidden image field has been created.'], | |
251 'required-single' => ['field_image', TRUE, 1, 'files[field_image_0]', 'field_image field is required.', 'field_image field is required.'], | |
252 'required-unlimited' => ['field_image', TRUE, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'files[field_image_0][]', 'field_image field is required.', 'field_image field is required.'], | |
253 | |
254 // @todo Fix this discrepancy in https://www.drupal.org/project/drupal/issues/3011744. | |
255 'required-multiple-limited' => ['field_image', TRUE, 2, 'files[field_image_0][]', 'This value should not be null.', 'Article Article with edit-access-forbidden image field has been created.'], | |
256 ]; | |
257 } | |
258 | |
259 /** | |
209 * Returns field settings. | 260 * Returns field settings. |
210 * | 261 * |
211 * @param int[] $min_resolution | 262 * @param int[] $min_resolution |
212 * The minimum width and height resolution setting. | 263 * The minimum width and height resolution setting. |
213 * @param int[] $max_resolution | 264 * @param int[] $max_resolution |