X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fresponsive_image%2Ftests%2Fsrc%2FFunctional%2FViewsIntegrationTest.php;fp=web%2Fcore%2Fmodules%2Fresponsive_image%2Ftests%2Fsrc%2FFunctional%2FViewsIntegrationTest.php;h=33f19a5be56412f0b05fea22fbd9c9926f7bc296;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/modules/responsive_image/tests/src/Functional/ViewsIntegrationTest.php b/web/core/modules/responsive_image/tests/src/Functional/ViewsIntegrationTest.php new file mode 100644 index 000000000..33f19a5be --- /dev/null +++ b/web/core/modules/responsive_image/tests/src/Functional/ViewsIntegrationTest.php @@ -0,0 +1,106 @@ +enableViewsTestModule(); + + // Create a responsive image style. + $responsive_image_style = ResponsiveImageStyle::create([ + 'id' => self::RESPONSIVE_IMAGE_STYLE_ID, + 'label' => 'Foo', + 'breakpoint_group' => 'responsive_image_test_module', + ]); + // Create an image field to be used with a responsive image formatter. + FieldStorageConfig::create([ + 'type' => 'image', + 'entity_type' => 'entity_test', + 'field_name' => 'bar', + ])->save(); + FieldConfig::create([ + 'entity_type' => 'entity_test', + 'bundle' => 'entity_test', + 'field_name' => 'bar', + ])->save(); + + $responsive_image_style + ->addImageStyleMapping('responsive_image_test_module.mobile', '1x', [ + 'image_mapping_type' => 'image_style', + 'image_mapping' => 'thumbnail', + ]) + ->addImageStyleMapping('responsive_image_test_module.narrow', '1x', [ + 'image_mapping_type' => 'image_style', + 'image_mapping' => 'medium', + ]) + // Test the normal output of mapping to an image style. + ->addImageStyleMapping('responsive_image_test_module.wide', '1x', [ + 'image_mapping_type' => 'image_style', + 'image_mapping' => 'large', + ]) + ->save(); + + $admin_user = $this->drupalCreateUser(['administer views']); + $this->drupalLogin($admin_user); + } + + /** + * Tests integration with Views. + */ + public function testViewsAddResponsiveImageField() { + // Add the image field to the View. + $this->drupalGet('admin/structure/views/nojs/add-handler/entity_test_row/default/field'); + $this->drupalPostForm('admin/structure/views/nojs/add-handler/entity_test_row/default/field', ['name[entity_test__bar.bar]' => TRUE], 'Add and configure field'); + // Set the formatter to 'Responsive image'. + $this->drupalPostForm(NULL, ['options[type]' => 'responsive_image'], 'Apply'); + $this->assertSession() + ->responseContains('Responsive image style field is required.'); + $this->drupalPostForm(NULL, ['options[settings][responsive_image_style]' => self::RESPONSIVE_IMAGE_STYLE_ID], 'Apply'); + $this->drupalGet('admin/structure/views/nojs/handler/entity_test_row/default/field/bar'); + // Make sure the selected value is set. + $this->assertSession() + ->fieldValueEquals('options[settings][responsive_image_style]', self::RESPONSIVE_IMAGE_STYLE_ID); + } + +}