| 1 |
<?php |
<?php |
| 2 |
// $Id: user.test,v 1.14 2008/09/17 07:11:59 dries Exp $ |
// $Id: user.test,v 1.15 2008/09/20 20:22:25 webchick Exp $ |
| 3 |
|
|
| 4 |
class UserRegistrationTestCase extends DrupalWebTestCase { |
class UserRegistrationTestCase extends DrupalWebTestCase { |
| 5 |
/** |
/** |
| 257 |
$image = current($this->drupalGetTestFiles('image')); |
$image = current($this->drupalGetTestFiles('image')); |
| 258 |
$info = image_get_info($image->filename); |
$info = image_get_info($image->filename); |
| 259 |
|
|
| 260 |
// set new variables; |
// Set new variables: invalid dimensions, valid filesize (0 = no limit). |
|
$test_size = floor(filesize($image->filename) / 1000) + 1; |
|
| 261 |
$test_dim = ($info['width'] - 10) . 'x' . ($info['height'] - 10); |
$test_dim = ($info['width'] - 10) . 'x' . ($info['height'] - 10); |
| 262 |
variable_set('user_picture_dimensions', $test_dim); |
variable_set('user_picture_dimensions', $test_dim); |
| 263 |
variable_set('user_picture_file_size', $test_size); |
variable_set('user_picture_file_size', 0); |
| 264 |
|
|
| 265 |
$pic_path = $this->saveUserPicture($image); |
$pic_path = $this->saveUserPicture($image); |
| 266 |
|
// Check that the image was resized and is being displayed on the |
| 267 |
|
// user's profile page. |
| 268 |
|
$text = t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels.', array('%dimensions' => $test_dim)); |
| 269 |
|
$this->assertRaw($text, t('Image was resized.')); |
| 270 |
|
$this->assertRaw(file_create_url($pic_path), t("Image is displayed in user's profile page")); |
| 271 |
|
|
| 272 |
// check if image is displayed in user's profile page |
// Check if file is located in proper directory. |
| 273 |
$this->assertRaw(file_create_url($pic_path), "Image is displayed in user's profile page"); |
$this->assertTrue(is_file($pic_path), t("File is located in proper directory")); |
|
|
|
|
// check if file is located in proper directory |
|
|
$this->assertTrue(is_file($pic_path), "File is located in proper directory"); |
|
| 274 |
} |
} |
| 275 |
} |
} |
| 276 |
|
|
| 290 |
$image = current($this->drupalGetTestFiles('image')); |
$image = current($this->drupalGetTestFiles('image')); |
| 291 |
$info = image_get_info($image->filename); |
$info = image_get_info($image->filename); |
| 292 |
|
|
| 293 |
// Set new variables. |
// Set new variables: valid dimensions, invalid filesize. |
| 294 |
$test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10); |
$test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10); |
| 295 |
$test_size = filesize($image->filename); |
$test_size = 1; |
| 296 |
variable_set('user_picture_dimensions', $test_dim); |
variable_set('user_picture_dimensions', $test_dim); |
| 297 |
variable_set('user_picture_file_size', $test_size); |
variable_set('user_picture_file_size', $test_size); |
| 298 |
|
|
| 299 |
$picture_path = $this->saveUserPicture($image); |
$pic_path = $this->saveUserPicture($image); |
|
$this->assertText(t('The changes have been saved.')); |
|
| 300 |
|
|
| 301 |
// Check if image is displayed in user's profile page. |
// Test that the upload failed and that the correct reason was cited. |
| 302 |
$this->assertRaw(file_create_url($picture_path), t("Image is displayed in user's profile page")); |
$text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->basename)); |
| 303 |
|
$this->assertRaw($text, t('Upload failed.')); |
| 304 |
|
$text = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size(filesize($image->filename)), '%maxsize' => format_size($test_size * 1024))); |
| 305 |
|
$this->assertRaw($text, t('File size cited as reason for failure.')); |
| 306 |
|
|
| 307 |
// Check if file is located in proper directory. |
// Check if file is not uploaded. |
| 308 |
$this->assertTrue(is_file($picture_path), t('File is located in proper directory')); |
$this->assertFalse(is_file($pic_path), t('File was not uploaded.')); |
| 309 |
} |
} |
| 310 |
} |
} |
| 311 |
|
|
| 325 |
$image = current($this->drupalGetTestFiles('image')); |
$image = current($this->drupalGetTestFiles('image')); |
| 326 |
$info = image_get_info($image->filename); |
$info = image_get_info($image->filename); |
| 327 |
|
|
| 328 |
// Set new variables. |
// Set new variables: invalid dimensions, valid filesize (0 = no limit). |
|
$test_size = floor(filesize($image->filename) / 1000) + 1; |
|
| 329 |
$test_dim = ($info['width'] - 10) . 'x' . ($info['height'] - 10); |
$test_dim = ($info['width'] - 10) . 'x' . ($info['height'] - 10); |
| 330 |
variable_set('user_picture_dimensions', $test_dim); |
variable_set('user_picture_dimensions', $test_dim); |
| 331 |
variable_set('user_picture_file_size', $test_size); |
variable_set('user_picture_file_size', 0); |
| 332 |
|
|
| 333 |
$pic_path = $this->saveUserPicture($image); |
$pic_path = $this->saveUserPicture($image); |
|
$text = t('The uploaded image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'))); |
|
|
$this->assertText($text, t('Checking response on invalid image (dimensions).')); |
|
| 334 |
|
|
| 335 |
// check if file is not uploaded |
// Test that the upload failed and that the correct reason was cited. |
| 336 |
$this->assertFalse(is_file($pic_path), t('File is not uploaded')); |
$text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->basename)); |
| 337 |
|
$this->assertRaw($text, t('Upload failed.')); |
| 338 |
|
$text = t('The image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => $test_dim)); |
| 339 |
|
$this->assertRaw($text, t('Checking response on invalid image (dimensions).')); |
| 340 |
|
|
| 341 |
|
// Check if file is not uploaded. |
| 342 |
|
$this->assertFalse(is_file($pic_path), t('File was not uploaded.')); |
| 343 |
} |
} |
| 344 |
} |
} |
| 345 |
|
|
| 356 |
$this->drupalLogin($this->user); |
$this->drupalLogin($this->user); |
| 357 |
|
|
| 358 |
$image = current($this->drupalGetTestFiles('image')); |
$image = current($this->drupalGetTestFiles('image')); |
|
$image->filename = realpath("modules/tests/image-2.jpg"); |
|
| 359 |
$info = image_get_info($image->filename); |
$info = image_get_info($image->filename); |
| 360 |
// invalid size |
|
| 361 |
// restore one and set another |
// Set new variables: valid dimensions, invalid filesize. |
| 362 |
$test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10); |
$test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10); |
| 363 |
$test_size = floor(filesize($image->filename) / 1000) - 1; |
$test_size = 1; |
| 364 |
variable_set('user_picture_dimensions', $test_dim); |
variable_set('user_picture_dimensions', $test_dim); |
| 365 |
variable_set('user_picture_file_size', $test_size); |
variable_set('user_picture_file_size', $test_size); |
| 366 |
|
|
| 367 |
$pic_path = $this->saveUserPicture($image); |
$pic_path = $this->saveUserPicture($image); |
|
$text = t('The uploaded image is too large; the maximum file size is %size kB.', array('%size' => variable_get('user_picture_file_size', '30'))); |
|
|
$this->assertText($text, t('Checking response on invalid image size.')); |
|
| 368 |
|
|
| 369 |
// check if file is not uploaded |
// Test that the upload failed and that the correct reason was cited. |
| 370 |
$this->assertFalse(is_file($pic_path), t('File is not uploaded.')); |
$text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->basename)); |
| 371 |
|
$this->assertRaw($text, t('Upload failed.')); |
| 372 |
|
$text = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size(filesize($image->filename)), '%maxsize' => format_size($test_size * 1024))); |
| 373 |
|
$this->assertRaw($text, t('File size cited as reason for failure.')); |
| 374 |
|
|
| 375 |
|
// Check if file is not uploaded. |
| 376 |
|
$this->assertFalse(is_file($pic_path), t('File was not uploaded.')); |
| 377 |
} |
} |
| 378 |
} |
} |
| 379 |
|
|
| 390 |
$image = current($this->drupalGetTestFiles('image')); |
$image = current($this->drupalGetTestFiles('image')); |
| 391 |
$info = image_get_info($image->filename); |
$info = image_get_info($image->filename); |
| 392 |
|
|
| 393 |
// valid size & dimensions |
// Set new variables: valid dimensions, valid filesize (0 = no limit). |
|
// restore one and set another |
|
| 394 |
$test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10); |
$test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10); |
|
$test_size = floor(filesize($image->filename) / 1000) + 1; |
|
| 395 |
variable_set('user_picture_dimensions', $test_dim); |
variable_set('user_picture_dimensions', $test_dim); |
| 396 |
variable_set('user_picture_file_size', $test_size); |
variable_set('user_picture_file_size', 0); |
| 397 |
|
|
| 398 |
$pic_path = $this->saveUserPicture($image); |
$pic_path = $this->saveUserPicture($image); |
| 399 |
|
|