You are here

public function ScaldAtomEntityTestCase::testScaldAtomManual in Scald: Media Management made easy 7

Manual atom CRUD test.

File

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

Class

ScaldAtomEntityTestCase
Test the Scald atom entities.

Code

public function testScaldAtomManual() {
  $image = $this
    ->getTestFile('image');
  $title = $this
    ->randomName(30);
  $author = $this
    ->randomName(10);
  $this
    ->drupalLogout();
  $web_user = $this
    ->drupalCreateUser(array(
    'view any atom',
    'fetch any atom',
    'edit own atom',
    'create atom of image type',
    'delete own atom',
  ));
  $this
    ->drupalLogin($web_user);

  // Create an image atom.
  $edit = array(
    'files[file]' => drupal_realpath($image->uri),
  );
  $this
    ->drupalPost('atom/add/image', $edit, t('Continue'));
  if ($this
    ->xpath('//input[@name="atom0[title]"]')) {
    $edit = array(
      'atom0[title]' => $title,
    );
    $this
      ->drupalPost(NULL, $edit, t('Finish'));
  }

  // Check that an image file has been created.
  $files = file_load_multiple(array(), array(
    'filename' => $image->filename,
  ));
  $file = reset($files);
  $this
    ->assertTrue($file, t('Image file found in database.'));
  $atom = scald_fetch(1, TRUE);
  $this
    ->addAtomAction($atom, 'edit');

  // Check that an image atom has been created.
  $this
    ->drupalGet('atom/' . $atom->sid);
  $this
    ->assertTitle($title . ' | Drupal', 'Image atom can be accessed.');
  $this
    ->assertLink(t('Edit'), 0, 'User can edit atom.');

  // Add an author.
  $langcode = LANGUAGE_NONE;
  $edit = array(
    'atom0[scald_authors][' . $langcode . ']' => $author,
  );
  $this
    ->drupalPost('atom/1/edit', $edit, t('Finish'));
  $this
    ->assertText($author, 'Atom author has been updated.');

  // Delete an atom.
  $this
    ->addAtomAction($atom, 'delete');
  $this
    ->drupalGet('atom/' . $atom->sid);
  $this
    ->assertLink(t('Delete'), 0, 'User can delete own atom.');
  $this
    ->clickLink(t('Delete'));
  $this
    ->drupalPost(NULL, array(), t('Delete'));
  $this
    ->drupalGet('atom/' . $atom->sid);
  $this
    ->assertResponse(404);

  // Check that the atom has really gone.
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'scald_atom');
  $query
    ->propertyCondition('sid', $atom->sid);
  $result = $query
    ->execute();
  $this
    ->assertIdentical(array(), $result, 'Atom has been deleted.');
}