public function PDFToImageFilefieldPathsTest::testAttachingPdf in PDF to ImageField 7.3
Save a document with an attached PDF, check that the image was generated.
File
- tests/
pdf_to_image.test, line 265 - Test the file attachment and process.
Class
- PDFToImageFilefieldPathsTest
- Test attaching a PDF using filefield_paths patterns.
Code
public function testAttachingPdf() {
$langcode = LANGUAGE_NONE;
$this->typeName = 'document';
$this->fieldName = 'field_document';
$this->imageFieldName = 'field_image';
// Use the settings to add tokens to the expected storage path.
$this
->changeFileFieldPath();
$test_file = PDFToImageTest::getTestFile('text');
// Create a new node with the uploaded file.
$nid = $this
->uploadNodeFile($test_file, $this->fieldName, $this->typeName);
$this
->assertTrue($nid !== FALSE, format_string('Created a new @type_name with @test_file as an uploaded @field_name', array(
'@test_file' => $test_file->uri,
'@field_name' => $this->fieldName,
'@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];
// After saving, there should also now be an attached image.
$message = format_string('Generated image preview %file exists in %image_field_name.', array(
'%file' => $node_image->uri,
'%image_field_name' => $this->imageFieldName,
));
// Check the filefield_path settings took effect.
$this
->assertTrue(is_file($node_image->uri), $message);
$message = format_string('Generated image file is stored in a custom folder using filefield_paths %image_file', array(
'%image_file' => $node_image->uri,
));
$this
->assertTrue(strstr($node_image->uri, 'custom'), $message);
$filename = pathinfo($node_file->uri, PATHINFO_FILENAME);
$message = format_string('Generated image file %image_file is named after the source document "%filename", using a filefield_paths pattern %customPattern', array(
'%image_file' => $node_image->uri,
'%filename' => $filename,
'%customPattern' => $this->customPattern,
));
$this
->assertTrue(strstr($node_image->uri, $filename), $message);
}