You are here

public function ProtectedNodePrivateFile::testUpload in Protected Node 7

Same name and namespace in other branches
  1. 1.0.x tests/protected_node.private_file.test \ProtectedNodePrivateFile::testUpload()

Test function.

Test that an image uploaded with AJAX can be viewed before being saved.

File

tests/protected_node.private_file.test, line 193
Test protected node behavior with private files.

Class

ProtectedNodePrivateFile
Configure protected_node to use per node password and use private file field.

Code

public function testUpload() {

  // Log in as Admin.
  $this
    ->drupalLogin($this->adminUser);

  // Go to the page creation form.
  $this
    ->drupalGet('node/add/page');
  $temp_image_file = current($this
    ->drupalGetTestFiles('image'));
  $this
    ->drupalPostAJAX(NULL, array(
    'files[private_image_und_0]' => drupal_realpath($temp_image_file->uri),
  ), array(
    (string) 'private_image_und_0_upload_button' => (string) t('Upload'),
  ));

  // Get the preview URL.
  $image_url = NULL;
  $image_preview = $this
    ->xpath('//div[@class="image-preview"]/img');

  /** @var SimpleXMLElement $html_node */
  foreach ($image_preview as $html_node) {
    $attributes = $html_node
      ->attributes();
    if (isset($attributes['src'])) {
      $image_url = $attributes['src'];
      break;
    }
  }

  // Go to the preview image URL to check the access.
  if (!is_null($image_url)) {
    $this
      ->drupalGet($image_url);
    $this
      ->assertResponse(200, 'Confirmed that the user has access to the image event if it is a private image as it is in temporary status.');
  }
  else {
    $this
      ->assertFalse($image_url, t('No image preview found.'), $this->group);
  }
}