class ImageModuleTest in SimpleTest 5
Hierarchy
- class \DrupalTestCase extends \WebTestCase
- class \ImageModuleTest
Expanded class hierarchy of ImageModuleTest
File
- tests/
image_module.test, line 3
View source
class ImageModuleTest extends DrupalTestCase {
function get_info() {
return array(
'name' => t('Image Module'),
'desc' => t('Testing add/edit/delete image node. If GD tooklit is found, perform image crop test. Requires image.module'),
'group' => 'Image',
);
}
function setUp() {
parent::setUp();
$dir = file_directory_path() . '/' . variable_get('image_default_path', 'images');
$temp_dir = $dir . '/temp';
$dir_created = file_check_directory($dir, TRUE);
$temp_dir_created = file_check_directory($temp_dir, TRUE);
if (!$dir_created || !$temp_dir_created) {
print "Images dir could not be create";
exit;
}
}
function _rolesApi($op, $edit) {
if ($op == 'delete') {
$id = $edit['rid'];
db_query('DELETE FROM {role} WHERE rid = %d', $id);
db_query('DELETE FROM {permission} WHERE rid = %d', $id);
// Update the users who have this role set:
$result = db_query('SELECT DISTINCT(ur1.uid) FROM {users_roles} ur1 LEFT JOIN {users_roles} ur2 ON ur2.uid = ur1.uid WHERE ur1.rid = %d AND ur2.rid != ur1.rid', $id);
$uid = array();
while ($u = db_fetch_object($result)) {
$uid[] = $u->uid;
}
if ($uid) {
db_query('DELETE FROM {users_roles} WHERE rid = %d AND uid IN (%s)', $id, implode(', ', $uid));
}
// Users with only the deleted role are put back in the authenticated users pool.
db_query('UPDATE {users_roles} SET rid = %d WHERE rid = %d', _user_authenticated_id(), $id);
}
else {
if ($op == 'add') {
if (isset($edit['name'])) {
db_query("INSERT INTO {role} (name) VALUES ('%s')", $edit['name']);
$result = db_query("SELECT rid FROM {role} WHERE name = '%s'", $edit['name']);
$rid = db_result($result);
db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, $edit['perm']);
return $rid;
}
else {
return 0;
}
}
}
}
function testImageNode() {
global $base_url;
$this
->drupalModuleEnable('image');
//TODO: make sure image.module (and file api) is configured properly
// create and login a new user
$perm = array(
'access content',
'create images',
'administer nodes',
);
$account = $this
->drupalCreateUserRolePerm($perm);
$this
->drupalLoginUser($account);
$title = $this
->randomName(10);
$description = $this
->randomName(100);
$img_path = dirname(__FILE__) . '/ImageModuleTest.png';
$my_size = getimagesize($img_path);
if (image_get_toolkit()) {
// if we got gd we perform more precise test
$temppath = variable_get('image_default_path', 'images') . '/temp';
$path = realpath(file_create_path($temppath));
$new_image = $path . '/ImageTestGd.png';
$width = rand(20, $my_size[0]);
$height = rand(20, $my_size[1]);
image_crop($img_path, $new_image, 0, 0, $width, $height);
$my_size = getimagesize($new_image);
$img_path = $new_image;
}
// Add image
unset($edit);
$edit = array(
'title' => $title,
'body' => $description,
'files[image]' => $img_path,
);
$this
->drupalPostRequest('node/add/image', $edit, 'Submit');
$content = $this->_browser
->getContent();
// test message
$this
->assertWantedRaw(t('Your %post has been created.', array(
'%post' => 'Image',
)), "Checking message");
// get node nid
$node = node_load(array(
'title' => $title,
));
$this
->drupalGet(url("node/{$node->nid}", NULL, NULL, TRUE));
$content = $this->_browser
->getContent();
$this
->assertWantedText($title, "Checking title : {$title}");
$this
->assertWantedText($description, "Checking body: {$description}");
// sprawdz czy obrazek jest dobry
preg_match_all('~<img.*?src="?([^"]*png?)"?[^>]*>~i', $content, $matches);
$found = false;
// TODO Make is to that getimagesize goes green on HTTP-AUTH
// right now it will get denied.
foreach ($matches[1] as $file) {
if (strripos($file, "TestGD")) {
$size = getimagesize($file);
if ($size == $my_size) {
$found = true;
break;
}
}
}
$this
->assertTrue($found, 'Checking for presence and size of uploaded image');
// update image node
// TODO: upload a different file so we know that updating image files works
$title = $this
->randomName(10);
$description = $this
->randomName(100);
$img_path = dirname(__FILE__) . '/ImageModuleTest.png';
// powininem byc inny obrazek
unset($edit);
$edit = array(
'title' => $title,
'body' => $description,
'files[image]' => $img_path,
);
$this
->drupalPostRequest('node/' . $node->nid . '/edit', $edit, 'Submit');
$content = $this->_browser
->getContent();
$this
->drupalGet(url("node/{$node->nid}"));
$this
->assertWantedText($title, "Checking title : {$title}");
$this
->assertWantedText($description, "Checking body: {$description}");
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
function | Will trigger a pass if both parameters refer to different objects. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the same value only. Otherwise a fail. | ||
DrupalTestCase:: |
function | Confirms that an error has occurred and optionally that the error text matches exactly. | ||
DrupalTestCase:: |
function | Confirms that an error has occurred and that the error text matches a Perl regular expression. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the same value and same type. Otherwise a fail. | ||
DrupalTestCase:: |
function | Type and class test. Will pass if class matches the type name or is a subclass or if not an object, but the type is correct. | ||
DrupalTestCase:: |
function | Confirms that no errors have occurred so far in the test method. | ||
DrupalTestCase:: |
function | Type and class mismatch test. Will pass if class name or underling type does not match the one specified. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have a different value. Otherwise a fail. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the different value or different type. | ||
DrupalTestCase:: |
function | Will be true if the value is set. | ||
DrupalTestCase:: |
function | Will trigger a pass if the Perl regex pattern is not present in subject. Fail if found. | ||
DrupalTestCase:: |
function | Will trigger a pass if the raw text is NOT found on the loaded page Fail otherwise. | ||
DrupalTestCase:: |
function | Will be true if the value is null. | ||
DrupalTestCase:: |
function | Will trigger a pass if both parameters refer to the same object. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the Perl regex pattern is found in the subject. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the raw text is found on the loaded page Fail otherwise. | ||
DrupalTestCase:: |
function | Follows a link by name. Will click the first link found with this link text by default, or a later one if an index is given. Match is case insensitive with normalised space. Does make assertations if the click was sucessful or not and it does… | ||
DrupalTestCase:: |
function | @abstract Checks to see if we need to send a http-auth header to authenticate when browsing a site. | ||
DrupalTestCase:: |
function | Create a role / perm combination specified by permissions | ||
DrupalTestCase:: |
function | Creates a user / role / permissions combination specified by permissions | ||
DrupalTestCase:: |
function | @abstract Brokder for the get function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com> | ||
DrupalTestCase:: |
function | @TODO: needs documentation | ||
DrupalTestCase:: |
function | Logs in a user with the internal browser | ||
DrupalTestCase:: |
function | Disables a drupal module | ||
DrupalTestCase:: |
function | Enables a drupal module | ||
DrupalTestCase:: |
function | Do a post request on a drupal page. It will be done as usual post request with SimpleBrowser | ||
DrupalTestCase:: |
function | @abstract Broker for the post function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com> | ||
DrupalTestCase:: |
function | |||
DrupalTestCase:: |
function | Set a druapl variable and keep track of the changes for tearDown() | ||
DrupalTestCase:: |
function | Generates a random string, to be used as name or whatever | ||
DrupalTestCase:: |
function | Just some info for the reporter | ||
DrupalTestCase:: |
function | tearDown implementation, setting back switched modules etc | 1 | |
ImageModuleTest:: |
function | |||
ImageModuleTest:: |
function | |||
ImageModuleTest:: |
function | |||
ImageModuleTest:: |
function |