public function PDFToImageTest::testAttachingImage in PDF to ImageField 7.3
Save a document with an attached PDF and a custom image.
Ensure the custom image is retained.
File
- tests/
pdf_to_image.test, line 86 - Test the file attachment and process.
Class
- PDFToImageTest
- Test attaching a PDF.
Code
public function testAttachingImage() {
$langcode = LANGUAGE_NONE;
$test_file = $this
->getTestFile('text');
$test_image = current($this
->drupalGetTestFiles('image'));
// Create a new node with the uploaded file and image.
$edit = array(
"title" => $this
->randomName(),
);
$extras['type'] = $this->typeName;
$node = $this
->drupalCreateNode($extras);
$nid = $node->nid;
// Attach a file and image to the node simultaneously.
$edit['files[' . $this->fieldName . '_' . $langcode . '_0]'] = drupal_realpath($test_file->uri);
$edit['files[' . $this->imageFieldName . '_' . $langcode . '_0]'] = drupal_realpath($test_image->uri);
$this
->drupalPost("node/{$nid}/edit", $edit, t('Save'));
$this
->assertTrue($nid !== FALSE, format_string('New @type_name has @test_file as an uploaded @field_name', array(
'@test_file' => $test_file->uri,
'@field_name' => $this->fieldName,
'@type_name' => $this->typeName,
)));
$this
->assertTrue($nid !== FALSE, format_string('New @type_name has @test_image as an uploaded @image_field_name', array(
'@test_file' => $test_image->uri,
'@image_field_name' => $this->imageFieldName,
'@type_name' => $this->typeName,
)));
$node = node_load($nid, NULL, TRUE);
$node_file = (object) $node->{$this->fieldName}[$langcode][0];
$node_image = (object) $node->{$this->imageFieldName}[$langcode][0];
$message = format_string('File %file exists after uploading to %field_name.', array(
'%file' => $node_file->uri,
'%field_name' => $this->fieldName,
));
$this
->assertTrue(is_file($node_file->uri), $message);
// After saving, there should also now be an attached image.
// And it should be the one MANUALLY uploaded.
$message = format_string('Manual Image preview %node_image exists in %image_field_name.', array(
'%node_image' => $node_image->uri,
'%image_field_name' => $this->imageFieldName,
));
$this
->assertTrue(is_file($node_image->uri), $message);
$message = format_string('Manual Image preview %node_image is the manually uploaded one %test_image.', array(
'%node_image' => $node_image->filename,
'%test_image' => $test_image->filename,
));
$this
->assertTrue($node_image->filename == $test_image->filename, $message);
}