| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: image.test,v 1.2 2009/01/17 00:20:44 sun Exp $ |
| 3 |
|
|
| 4 |
class ImageTest extends DrupalTestCase { |
/** |
| 5 |
|
* Test image functionality. |
| 6 |
|
*/ |
| 7 |
|
class ImageTestCase extends DrupalWebTestCase { |
| 8 |
protected $web_user; |
protected $web_user; |
| 9 |
protected $image; |
protected $image; |
| 10 |
protected $another_image; |
protected $another_image; |
| 11 |
|
|
| 12 |
|
function getInfo() { |
| 13 |
function get_info() { |
return array( |
| 14 |
return array('name' => t('Image tests'), 'desc' => t('Test Image module functionality.'), 'group' => 'Image'); |
'name' => t('Image functionality'), |
| 15 |
|
'description' => t('Test Image module functionality.'), |
| 16 |
|
'group' => t('Image'), |
| 17 |
|
); |
| 18 |
} |
} |
| 19 |
|
|
| 20 |
function setUp() { |
function setUp() { |
| 21 |
parent::setUp(); |
parent::setUp('image'); |
| 22 |
|
|
| 23 |
// User to create images. |
// User to create images. |
| 24 |
$this->web_user = $this->drupalCreateUserRolePerm(array('create images', 'view original images', 'edit own images', 'edit images')); |
$this->web_user = $this->drupalCreateUser(array('create images', 'view original images', 'edit own images', 'edit images')); |
| 25 |
$this->drupalGet('logout'); |
$this->drupalLogin($this->web_user); |
|
$this->drupalLoginUser($this->web_user); |
|
| 26 |
|
|
| 27 |
// Uploadable image |
// Uploadable image. |
| 28 |
$this->image = 'misc' . DIRECTORY_SEPARATOR . 'druplicon.png'; |
$this->image = 'misc' . DIRECTORY_SEPARATOR . 'druplicon.png'; |
| 29 |
$this->another_image = 'misc' . DIRECTORY_SEPARATOR . 'throbber.gif'; |
$this->another_image = 'misc' . DIRECTORY_SEPARATOR . 'throbber.gif'; |
| 30 |
|
|
| 37 |
$image_sizes['preview']['operation'] = 'scale'; |
$image_sizes['preview']['operation'] = 'scale'; |
| 38 |
$image_sizes['preview']['width'] = 10; |
$image_sizes['preview']['width'] = 10; |
| 39 |
$image_sizes['preview']['height'] = 10; |
$image_sizes['preview']['height'] = 10; |
| 40 |
$this->drupalVariableSet('image_sizes', $image_sizes); |
variable_set('image_sizes', $image_sizes); |
| 41 |
} |
} |
| 42 |
|
|
| 43 |
|
/** |
| 44 |
|
* Verify creating/displaying/editing/deleting image nodes. |
| 45 |
|
*/ |
| 46 |
function testNode() { |
function testNode() { |
| 47 |
// Create an image. |
// Create an image. |
| 48 |
$edit = array( |
$edit = array( |
| 52 |
); |
); |
| 53 |
$this->drupalPost('node/add/image', $edit, t('Save')); |
$this->drupalPost('node/add/image', $edit, t('Save')); |
| 54 |
|
|
| 55 |
$this->assertWantedRaw(t('@type %title has been created.', array('@type' => 'Image', '%title' => $edit['title'])), 'Image created. %s'); |
$this->assertRaw(t('@type %title has been created.', array('@type' => 'Image', '%title' => $edit['title'])), t('Image created.')); |
| 56 |
|
|
| 57 |
$node = node_load(array('title' => $edit['title'])); |
$node = node_load(array('title' => $edit['title'])); |
| 58 |
$this->assertNotNull($node, 'Image found in database. %s'); |
$this->assertTrue($node, t('Image found in database.')); |
| 59 |
|
|
| 60 |
// Display an image. |
// Display an image. |
| 61 |
$this->drupalGet('node/' . $node->nid); |
$this->drupalGet('node/' . $node->nid); |
| 62 |
$this->assertWantedPattern('|<img[^>]+?' . $node->images['preview'] . '[^>]+?>|', $this->drupalGetContent(), 'Image preview is on the page. %s'); |
$this->assertPattern('@<img[^>]+?' . $node->images['preview'] . '[^>]+?>@', t('Image preview displayed on the page.')); |
| 63 |
$this->assertTrue(file_exists($node->images['preview']), 'Image preview exists. %s'); |
$this->assertTrue(file_exists($node->images['preview']), t('Image preview exists.')); |
| 64 |
|
|
| 65 |
$this->drupalGet('node/' . $node->nid, array('query' => 'size=_original')); |
$this->drupalGet('node/' . $node->nid, array('query' => 'size=_original')); |
| 66 |
$this->assertWantedPattern('|<img[^>]+?' . $node->images['_original'] . '[^>]+?>|', $this->drupalGetContent(), 'Original image is on the page. %s'); |
$this->assertPattern('@<img[^>]+?' . $node->images['_original'] . '[^>]+?>@', t('Original image displayed on the page.')); |
| 67 |
$this->assertTrue(file_exists($node->images['_original']), 'Original image exists. %s'); |
$this->assertTrue(file_exists($node->images['_original']), t('Original image exists.')); |
| 68 |
|
|
| 69 |
$this->drupalGet('node/' . $node->nid, array('query' => 'size=thumbnail')); |
$this->drupalGet('node/' . $node->nid, array('query' => 'size=thumbnail')); |
| 70 |
$this->assertWantedPattern('|<img[^>]+?' . $node->images['thumbnail'] . '[^>]+?>|', $this->drupalGetContent(), 'Image thumbnail is on the page. %s'); |
$this->assertPattern('@<img[^>]+?' . $node->images['thumbnail'] . '[^>]+?>@', t('Image thumbnail displayed on the page.')); |
| 71 |
$this->assertTrue(file_exists($node->images['thumbnail']), 'Image thumbnail exists. %s'); |
$this->assertTrue(file_exists($node->images['thumbnail']), t('Image thumbnail exists.')); |
| 72 |
|
|
| 73 |
// Edit an image |
// Edit an image. |
| 74 |
$another_edit = array( |
$another_edit = array( |
| 75 |
'title' => $edit['title'], |
'title' => $edit['title'], |
| 76 |
'files[image]' => realpath($this->another_image), |
'files[image]' => realpath($this->another_image), |
| 77 |
); |
); |
| 78 |
$this->drupalPost('node/' . $node->nid .'/edit', $another_edit, t('Save')); |
$this->drupalPost('node/' . $node->nid .'/edit', $another_edit, t('Save')); |
| 79 |
$another_node = node_load(array('title' => $edit['title'])); |
$another_node = node_load(array('title' => $edit['title'])); |
| 80 |
$this->assertFalse(file_exists($node->images['preview']) || file_exists($node->images['_original']) || file_exists($node->images['thumbnail']), 'The previous image deleted. %s'); |
$this->assertFalse(file_exists($node->images['preview']) || file_exists($node->images['_original']) || file_exists($node->images['thumbnail']), t('The previous image deleted.')); |
| 81 |
|
|
| 82 |
// Delete an image |
// Delete an image. |
| 83 |
$this->drupalPost('node/' . $node->nid .'/delete', array(), 'Delete'); |
$this->drupalPost('node/' . $node->nid .'/delete', array(), t('Delete')); |
| 84 |
$this->assertWantedRaw(t('@type %title has been deleted.', array('@type' => 'Image', '%title' => $edit['title'])), 'Image created. %s'); |
$this->assertRaw(t('@type %title has been deleted.', array('@type' => 'Image', '%title' => $edit['title'])), t('Image created.')); |
| 85 |
$node = node_load(array('title' => $edit['title'])); |
$node = node_load(array('title' => $edit['title'])); |
| 86 |
$this->assertFalse($node, 'Image not found in database. %s'); |
$this->assertFalse($node, t('Image not found in database.')); |
| 87 |
$this->assertFalse(file_exists($another_node->images['preview']) || file_exists($another_node->images['_original']) || file_exists($another_node->images['thumbnail']), 'Image deleted. %s'); |
$this->assertFalse(file_exists($another_node->images['preview']) || file_exists($another_node->images['_original']) || file_exists($another_node->images['thumbnail']), t('Image deleted.')); |
| 88 |
} |
} |
| 89 |
|
|
| 90 |
|
/** |
| 91 |
|
* Test image node creation. |
| 92 |
|
*/ |
| 93 |
function testCreateNode() { |
function testCreateNode() { |
| 94 |
$edit = array( |
$edit = array( |
| 95 |
'title' => $this->randomName(), |
'title' => $this->randomName(), |
| 97 |
'files[image]' => realpath($this->image), |
'files[image]' => realpath($this->image), |
| 98 |
); |
); |
| 99 |
$this->drupalPost('node/add/image', $edit, t('Save')); |
$this->drupalPost('node/add/image', $edit, t('Save')); |
| 100 |
$this->assertWantedRaw(t('@type %title has been created.', array('@type' => 'Image', '%title' => $edit['title'])), 'Image created. %s'); |
$this->assertRaw(t('@type %title has been created.', array('@type' => 'Image', '%title' => $edit['title'])), t('Image created.')); |
| 101 |
|
|
| 102 |
$node_post = node_load(array('title' => $edit['title'])); |
$node_post = node_load(array('title' => $edit['title'])); |
| 103 |
$this->assertNotNull($node_post, 'Image found in database. %s'); |
$this->assertTrue($node_post, t('Image found in database.')); |
| 104 |
|
|
| 105 |
// Make a copy of the image so image_create_node_from() deletes original image. |
// Make a copy of the image so image_create_node_from() deletes original image. |
| 106 |
file_copy($edit['files[image]'], file_directory_temp()); |
file_copy($edit['files[image]'], file_directory_temp()); |
| 115 |
(filesize($node_post->images['_original']) == filesize($node_api->images['_original'])) && |
(filesize($node_post->images['_original']) == filesize($node_api->images['_original'])) && |
| 116 |
(filesize($node_post->images['preview']) == filesize($node_api->images['preview'])) && |
(filesize($node_post->images['preview']) == filesize($node_api->images['preview'])) && |
| 117 |
(filesize($node_post->images['thumbnail']) == filesize($node_api->images['thumbnail'])); |
(filesize($node_post->images['thumbnail']) == filesize($node_api->images['thumbnail'])); |
| 118 |
$this->assertTrue($equality, 'Images nodes are equal. %s'); |
$this->assertTrue($equality, t('Images nodes are equal.')); |
| 119 |
} |
} |
| 120 |
} |
} |