- <?php
- * @file
- * Test case for testing the image example module.
- *
- * This file contains the tests cases to check if the module is performing as
- * expected.
- */
-
- * Functional tests for the Image Example module.
- *
- * @ingroup image_example
- */
- class ImageExampleTestCase extends BackdropWebTestCase {
- protected $webUser;
-
-
- * Enable modules and create user with specific permissions.
- */
- public function setUp() {
- parent::setUp('image_example');
-
- $this->webUser = $this->backdropCreateUser(array('administer image styles', 'administer blocks'));
- }
-
-
- * Test implementations of image API hooks.
- */
- public function testImageExample() {
-
- $this->backdropLogin($this->webUser);
-
-
-
- $image_styles = image_styles();
- $this->assertTrue(isset($image_styles['image_example_style']), 'The default style image_example_style is in the list of image styles.');
-
-
-
- $this->assertTrue((isset($image_styles['thumbnail']['effects'][1]['name']) && $image_styles['thumbnail']['effects'][1]['name'] == 'image_example_colorize'), 'Effect added to the thumbnail style via hook_image_styles_alter() is present.');
-
-
-
- $new_style = array('name' => backdrop_strtolower($this->randomName()), 'label' => backdrop_strtolower($this->randomName()));
- $new_style = image_style_save($new_style);
- $this->assertTrue(isset($new_style['name']), format_string('Image style @style_name created.', array('@style_name' => $new_style['name'])));
-
- $edit = array(
- 'new' => 'image_example_colorize',
- );
- $this->backdropPost('admin/config/media/image-styles/edit/' . $new_style['name'], $edit, t('Add'));
-
-
-
- $this->assertField('data[color]', 'Color field provided by image_example_effect_colorize_form is present on effect configuration page.');
- $edit = array(
- 'data[color]' => '#000000',
- );
- $this->backdropPost(NULL, $edit, t('Add effect'));
- $this->assertText(t('The image effect was successfully applied.'), format_string('Colorize effect added to @style_name.', array('@style_name' => $new_style['name'])));
-
-
-
- $style = image_style_load($new_style['name']);
- config_set('image_example.settings', 'image_example_style_name', $style['name']);
- $style['name'] = backdrop_strtolower($this->randomName());
- $style = image_style_save($style);
- $variable = config_get('image_example.settings', 'image_example_style_name');
- $this->assertTrue(($variable == $style['name']), 'Variable image_example_style_name successfully updated when renaming image style.');
- }
-
-
- * Tests for image block provided by module.
- */
- public function testImageExamplePage() {
-
- $this->backdropLogin($this->webUser);
- $this->backdropCreateNode(array('promote' => 1));
-
-
- $images = $this->backdropGetTestFiles('image');
- $edit = array(
- 'files[image_example_image_fid]' => backdrop_realpath($images[0]->uri),
- 'image_example_style_name' => 'image_example_style',
- );
- $this->backdropPost('image_example/styles', $edit, t('Save'));
- $this->assertText(t('The image @image_name was uploaded', array('@image_name' => $images[0]->filename)), 'Image uploaded to image block.');
-
-
- $this->backdropGet('image_example/styles');
- $fid = config_get('image_example.settings', 'image_example_image_fid');
- $image = isset($fid) ? file_load($fid) : NULL;
- $this->assertRaw(file_uri_target($image->uri), 'Image is displayed');
- }
- }