Created
September 12, 2015 15:41
-
-
Save aneek/0479a10e19b712f9e74d to your computer and use it in GitHub Desktop.
EditorImageDialogIntegrationTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Contains \Drupal\editor\Tests\EditorImageDialogIntegrationTest. | |
*/ | |
namespace Drupal\editor\Tests; | |
use Drupal\simpletest\WebTestBase; | |
use Drupal\editor\Entity\Editor; | |
use Drupal\filter\Entity\FilterFormat; | |
/** | |
* Tests Image Editor behaviour. | |
* | |
* @group editor | |
*/ | |
class EditorImageDialogIntegrationTest extends WebTestBase { | |
/** | |
* The modules to enable. | |
* | |
* @var array | |
*/ | |
public static $modules = ['filter', 'editor', 'editor_test', 'node']; | |
/** | |
* A privileged user with additional access to the 'full_html' format. | |
* | |
* @var \Drupal\user\UserInterface | |
*/ | |
protected $privilegedUser; | |
/** | |
* Defines the maximum dimension for a image while uploading. | |
* | |
* @var array | |
*/ | |
protected $maxDimension = ['width' => 50, 'height' => 50]; | |
/** | |
* Set up test case. | |
*/ | |
protected function setUp() { | |
parent::setUp(); | |
// Setup 'filtered_html' filter format. | |
$filteredHtml = FilterFormat::create([ | |
'format' => 'filtered_html', | |
'name' => 'Filtered HTML', | |
'weight' => 0, | |
'filters' => [], | |
]); | |
$filteredHtml->save(); | |
// Setup 'full_html' filter format. | |
$fullHtml = FilterFormat::create([ | |
'format' => 'full_html', | |
'name' => 'Full HTML', | |
'weight' => 1, | |
'filters' => [], | |
]); | |
$fullHtml->save(); | |
// Create user. | |
$this->privilegedUser = $this->drupalCreateUser([ | |
'use text format full_html' | |
]); | |
} | |
public function testMaxImageResolution() { | |
// Create the editor first. | |
$editor = Editor::create([ | |
'format' => 'full_html', | |
'editor' => 'unicorn', | |
'image_upload' => [ | |
'max_size' => '', | |
'scheme' => 'public', | |
'directory' => '', | |
'status' => TRUE, | |
], | |
]); | |
$editor->save(); | |
// Login the user. | |
$this->drupalLogin($this->privilegedUser); | |
$this->drupalGet('editor/dialog/image/full_html'); | |
// Get a suitable image and use it to upload. | |
$image_factory = $this->container->get('image.factory'); | |
$images = $this->drupalGetTestFiles('image'); | |
$suitable_image = NULL; | |
foreach ($images as $image) { | |
$file = $image_factory->get($image->uri); | |
if ($file->getWidth() > $this->maxDimension['width']) { | |
$suitable_image = $image; | |
break; | |
} | |
} | |
$image_path = \Drupal::service('file_system')->realpath($suitable_image->uri); | |
// Post the form. | |
$edit = [ | |
'files[fid]' => $image_path, | |
//'attributes[alt]' => 'foo', | |
]; | |
$this->drupalPostForm(NULL, $edit, t('Save')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment