You are here

function ScaldBaseTestCase::testScaldContext in Scald: Media Management made easy 7

Test Scald context.

File

tests/scald.test, line 169
Tests for scald.module.

Class

ScaldBaseTestCase
Test the Scald base functionality.

Code

function testScaldContext() {
  module_enable(array(
    'scald_image',
  ));

  // Prefix to avoid invalid names.
  $title = 'context' . $this
    ->randomName(10);
  $name = strtolower($title);
  $description = $this
    ->randomName(20);
  $web_user = $this
    ->drupalCreateUser(array(
    'administer scald',
    'view any atom',
    'create atom of any type',
  ));
  $this
    ->drupalLogin($web_user);
  $this
    ->drupalGet('admin/structure/scald');
  $this
    ->clickLink('Add context');
  $edit = array(
    'title' => $title,
    // There is no JavaScript in the SimpleBrowser, thus machine name must be
    // filled manually.
    'name' => $name,
    'description' => $description,
  );
  $this
    ->drupalPost(NULL, $edit, t('Add context'));
  $this
    ->assertText($title, 'Context created.');
  $this
    ->assertText($description, 'Context description is correct.');
  $this
    ->assertLinkByHref('admin/structure/scald/context/edit/' . $name, 0, 'New context can be edited.');
  $this
    ->clickLink('contexts');
  $edit = array(
    'full_trans' => 'style-large',
    $name . '_trans' => 'style-thumbnail',
    $name . '_playe' => 'image_figure',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $this
    ->assertField('full_trans', 'style-large', 'Context transcoder updated.');
  $this
    ->assertField($name . '_playe', 'image_figure', 'Context player updated.');

  // Player settings.
  $this
    ->clickLink('settings');
  $class = 'class-' . $this
    ->randomName(5);
  $caption = '//[atom:title]//[atom:author]//';
  $edit = array(
    'classes' => $class,
    'caption' => $caption,
  );
  $this
    ->drupalPost(NULL, $edit, t('Update'));

  // We are in another request, static cache is no longer relevant and needs
  // to be cleared.
  drupal_static_reset('_scald_get_info');

  // Verify new context settings. There is no easy way to verify a context
  // other than "full".
  $atom = $this
    ->createAtom();
  $content = scald_render($atom, $name);
  $author = $atom->rendered->authors[0]->link;
  $this
    ->assertIdentical(1, preg_match('/class="[^"]*' . $class . '[^"]*"/', $content), 'Player class is correct.');
  $this
    ->assertNotIdentical(FALSE, strpos($content, '<figcaption>//' . $atom->title . '//' . $author . '//</figcaption>'), 'Player caption is correct.');
  $this
    ->drupalGet('atom/' . $atom->sid);
  $this
    ->assertRaw(check_plain(image_style_url('large', $atom->base_entity->uri)), 'Transcoder is correct.');
}