media_ckeditor.test in Media CKEditor 7.2
Tests for media_ckeditor.module.
File
tests/media_ckeditor.testView source
<?php
/**
* @file
* Tests for media_ckeditor.module.
*/
/**
* Defines base class for media test cases.
*/
abstract class MediaCkeditorTestHelper extends DrupalWebTestCase {
/**
* Enable media and file entity modules for testing.
*/
public function setUp() {
$modules = func_get_args();
if (isset($modules[0]) && is_array($modules[0])) {
$modules = $modules[0];
}
$modules[] = 'media_ckeditor';
$modules[] = 'media_wysiwyg';
$modules[] = 'media';
$modules[] = 'file_entity';
$modules[] = 'token';
$modules[] = 'views';
$modules[] = 'ctools';
parent::setUp($modules);
}
/**
* Generates markup to be inserted for a file.
*
* This is a PHP version of InsertMedia.insert() from js/wysiwyg-media.js.
*
* @param int $fid
* Drupal file id.
* @param int $count
* Quantity of markup to insert.
* @param array $attributes
* Extra attributes to insert.
* @param array $fields
* Extra field values to insert.
*
* @return string
* Filter markup.
*/
protected function generateJsonTokenMarkup($fid, $count = 1, array $attributes = array(), array $fields = array()) {
$markup = '';
// Merge default atttributes.
$attributes += array(
'height' => 100,
'width' => 100,
'classes' => 'media-element file_preview',
);
// Build the data that is used in a media tag.
$data = array(
'fid' => $fid,
'type' => 'media',
'view_mode' => 'preview',
'attributes' => $attributes,
'fields' => $fields,
);
// Create the file usage markup.
for ($i = 1; $i <= $count; $i++) {
$markup .= '<p>[[' . drupal_json_encode($data) . ']]</p>';
}
return $markup;
}
/**
* Utility function to create a test node.
*
* @param array $fields
* Extra field values to insert.
*
* @return int
* Returns the node id
*/
protected function createNode(array $fields = array()) {
$markup = 'test';
// If (! empty($fid)) {
// $markup = $this->generateJsonTokenMarkup($fid, 1, $attributes, $fields);
// }
// Create an article node with file markup in the body field.
$edit = array(
'title' => $this
->randomName(8),
'body[und][0][value]' => $markup,
);
// Save the article node. First argument is the URL, then the value array
// and the third is the label the button that should be "clicked".
$this
->drupalPost('node/add/article', $edit, t('Save'));
// Get the article node that was saved by the unique title.
$node = $this
->drupalGetNodeByTitle($edit['title']);
return $node->nid;
}
}
/**
* Defines base class for media_ckeditor_view_mode test cases.
*/
class MediaCkeditorViewModeTestHelper extends MediaCkeditorTestHelper {
/**
* Get information function.
*/
public static function getInfo() {
return array(
'name' => 'Media Ckeditor ViewMode test',
'description' => 'Tests the media ckeditor ViewMode.',
'group' => 'Media',
);
}
/**
* Set up function.
*/
public function setUp() {
parent::setUp();
/* Reset the permissions cache prior to calling drupalCreateUser
* see notes here: https://api.drupal.org/comment/28739#comment-28739
*/
$this
->checkPermissions(array(), TRUE);
$web_user = $this
->drupalCreateUser(array(
'access administration pages',
'administer file types',
'view files',
'use media wysiwyg',
'create article content',
'edit own article content',
'edit any article content',
'administer nodes',
));
$this
->drupalLogin($web_user);
}
/**
* Tests the behavior of node and file deletion.
*/
public function testCreateNodeAndDelete() {
// Create a new node with file markup.
$nid = $this
->createNode(array(
'test_field',
));
// Delete the node.
node_delete($nid);
$node = node_load($nid);
$this
->assertEqual(empty($node), TRUE, t('Node has been deleted.'));
}
}
Classes
Name | Description |
---|---|
MediaCkeditorTestHelper | Defines base class for media test cases. |
MediaCkeditorViewModeTestHelper | Defines base class for media_ckeditor_view_mode test cases. |