adminUser = $this->drupalCreateUser(array('administer filters')); $this->drupalLogin($this->adminUser); //Initialize the max dimension value to empty $editor = entity_load('editor', 'basic_html'); $image_upload_settings = $editor->getImageUploadSettings(); $image_upload_settings['max_dimensions']['width'] = ''; $image_upload_settings['max_dimensions']['height'] = ''; $editor->setImageUploadSettings($image_upload_settings); $editor->save(); } function testEditorSettingsValidation() { //Case 1 - With have value, Height Empty // Expected Result: Validation error and message show $this->drupalGet('admin/config/content/formats/manage/basic_html'); $this->assertResponse(200); $this->assertUrl('admin/config/content/formats/manage/basic_html'); //Set the case value $width = '300'; $height = ''; $edit = array(); $edit['editor[settings][plugins][drupalimage][image_upload][max_dimensions][width]'] = $width; $edit['editor[settings][plugins][drupalimage][image_upload][max_dimensions][height]'] = $height; $this->drupalPostForm(NULL, $edit, t('Save configuration')); //Check for error message $this->assertRaw(t('Both a height and width value must be specified in the @name field.', array('@name' => 'Maximum dimensions'))); //Check for editor setting value $editor = entity_load('editor', 'basic_html'); $image_upload_settings = $editor->getImageUploadSettings(); if (($image_upload_settings['max_dimensions']['width'] == '') && ($image_upload_settings['max_dimensions']['height'] == '')) { $dimensions_no_change = true; } else { $dimensions_no_change = false; } $this->assertTrue($dimensions_no_change, 'Max dimensions settings had not been updated.'); //Case 2 - Test for width field valus is empty, height field had provided value // Expected Result: Validation error and message show $this->drupalGet('admin/config/content/formats/manage/basic_html'); $this->assertResponse(200); $this->assertUrl('admin/config/content/formats/manage/basic_html'); //Set the case value $width = ''; $height = '400'; $edit = array(); $edit['editor[settings][plugins][drupalimage][image_upload][max_dimensions][width]'] = $width; $edit['editor[settings][plugins][drupalimage][image_upload][max_dimensions][height]'] = $height; $this->drupalPostForm(NULL, $edit, t('Save configuration')); //Check for error message $this->assertRaw(t('Both a height and width value must be specified in the @name field.', array('@name' => 'Maximum dimensions'))); //Check for editor setting value $editor = entity_load('editor', 'basic_html'); $image_upload_settings = $editor->getImageUploadSettings(); if (($image_upload_settings['max_dimensions']['width'] == '') && ($image_upload_settings['max_dimensions']['height'] == '')) { $dimensions_no_change = true; } else { $dimensions_no_change = false; } $this->assertTrue($dimensions_no_change, 'Max dimensions settings had not been updated.'); //Case 3 - Test for both width field and height with value // Expected Result: Validation pass and setting updated $this->drupalGet('admin/config/content/formats/manage/basic_html'); $this->assertResponse(200); $this->assertUrl('admin/config/content/formats/manage/basic_html'); //Set the case value $width = '123'; $height = '456'; $edit = array(); $edit['editor[settings][plugins][drupalimage][image_upload][max_dimensions][width]'] = $width; $edit['editor[settings][plugins][drupalimage][image_upload][max_dimensions][height]'] = $height; $this->drupalPostForm(NULL, $edit, t('Save configuration')); $editor = entity_load('editor', 'basic_html'); $image_upload_settings = $editor->getImageUploadSettings(); if (($image_upload_settings['max_dimensions']['width'] == $width) && ($image_upload_settings['max_dimensions']['height'] == $height)) { $dimensions_updated = true; } else { $dimensions_updated = false; } $this->assertTrue($dimensions_updated, 'Max dimensions settings is updated properly.'); //Check for the successful message $this->assertRaw(t('The text format %format has been updated.', array('%format' => 'Basic HTML'))); //Check for the return page $this->assertUrl('admin/config/content/formats'); //Case 4 - Test for both width field and height are Empty // Expected Result: Validation pass and setting updated $this->drupalGet('admin/config/content/formats/manage/basic_html'); $this->assertResponse(200); $this->assertUrl('admin/config/content/formats/manage/basic_html'); //Set the case value $width = ''; $height = ''; $edit = array(); $edit['editor[settings][plugins][drupalimage][image_upload][max_dimensions][width]'] = $width; $edit['editor[settings][plugins][drupalimage][image_upload][max_dimensions][height]'] = $height; $this->drupalPostForm(NULL, $edit, t('Save configuration')); $editor = entity_load('editor', 'basic_html'); $image_upload_settings = $editor->getImageUploadSettings(); if (($image_upload_settings['max_dimensions']['width'] == $width) && ($image_upload_settings['max_dimensions']['height'] == $height)) { $dimensions_updated = true; } else { $dimensions_updated = false; } $this->assertTrue($dimensions_updated, 'Max dimensions settings is updated properly.'); //Check for the successful message $this->assertRaw(t('The text format %format has been updated.', array('%format' => 'Basic HTML'))); //Check for the return page $this->assertUrl('admin/config/content/formats'); } }