You are here

protected function MediaCkeditorTestHelper::generateJsonTokenMarkup in Media CKEditor 7.2

Generates markup to be inserted for a file.

This is a PHP version of InsertMedia.insert() from js/wysiwyg-media.js.

Parameters

int $fid: Drupal file id.

int $count: Quantity of markup to insert.

array $attributes: Extra attributes to insert.

array $fields: Extra field values to insert.

Return value

string Filter markup.

File

tests/media_ckeditor.test, line 49
Tests for media_ckeditor.module.

Class

MediaCkeditorTestHelper
Defines base class for media test cases.

Code

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;
}