function ImageTestCase::testImageNode in Image 6
Same name and namespace in other branches
- 7 tests/image.test \ImageTestCase::testImageNode()
Verify creating/displaying/editing/deleting image nodes.
File
- tests/
image.test, line 68
Class
- ImageTestCase
- Test image functionality.
Code
function testImageNode() {
// Create an image.
$edit = array(
'title' => $this
->randomName(),
'body' => $this
->randomName(),
'files[image]' => realpath($this->image),
);
$this
->drupalPost('node/add/image', $edit, t('Save'));
$this
->assertRaw(t('@type %title has been created.', array(
'@type' => 'Image',
'%title' => $edit['title'],
)), t('Image node was created.'));
$node = node_load(array(
'title' => $edit['title'],
));
$this
->assertTrue($node, t('Image node is found in database.'));
// Display an image.
$this
->drupalGet('node/' . $node->nid, array(
'query' => 'size=_original',
));
$this
->assertPattern('@<img[^>]+?' . $node->images['_original'] . '[^>]+?>@', t('Original image displayed on the page.'));
$this
->assertTrue(file_exists($node->images['_original']), t('Original image exists.'));
$this
->drupalGet('node/' . $node->nid);
$this
->assertPattern('@<img[^>]+?' . $node->images['preview'] . '[^>]+?>@', t('Image preview displayed on the page.'));
$this
->assertTrue(file_exists($node->images['preview']), t('Image preview exists.'));
$this
->drupalGet('node/' . $node->nid, array(
'query' => 'size=thumbnail',
));
$this
->assertPattern('@<img[^>]+?' . $node->images['thumbnail'] . '[^>]+?>@', t('Image thumbnail displayed on the page.'));
$this
->assertTrue(file_exists($node->images['thumbnail']), t('Image thumbnail exists.'));
// Promote the node so we can test the thumbnail appears in the teaser.
$node->promote = TRUE;
node_save($node);
$this
->drupalGet('node');
$this
->assertPattern('@<img[^>]+?' . $node->images['thumbnail'] . '[^>]+?>@', t('Image thumbnail displayed on the front page teaser.'));
// Edit an image.
$another_edit = array(
'title' => $edit['title'],
'files[image]' => realpath($this->another_image),
);
$this
->drupalPost('node/' . $node->nid . '/edit', $another_edit, t('Save'));
$another_node = node_load(array(
'title' => $edit['title'],
));
$this
->assertFalse(file_exists($node->images['preview']) || file_exists($node->images['_original']) || file_exists($node->images['thumbnail']), t('Previous image derivative files were deleted.'));
// Delete an image.
$this
->drupalPost('node/' . $node->nid . '/delete', array(), t('Delete'));
$this
->assertRaw(t('@type %title has been deleted.', array(
'@type' => 'Image',
'%title' => $edit['title'],
)), t('Image node was deleted.'));
$node = node_load(array(
'title' => $edit['title'],
));
$this
->assertFalse($node, t('Image node is not found in database.'));
$this
->assertFalse(file_exists($another_node->images['preview']) || file_exists($another_node->images['_original']) || file_exists($another_node->images['thumbnail']), t('Image file was deleted.'));
}