1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Tests for the Image CAPTCHA module.
|
6
|
*/
|
7
|
|
8
|
class ImageCaptchaWebTestCase extends CaptchaBaseWebTestCase {
|
9
|
|
10
|
public static function getInfo() {
|
11
|
return array(
|
12
|
'name' => 'General Image CAPTCHA functionality',
|
13
|
'description' => 'Testing of the basic Image CAPTCHA functions.',
|
14
|
'group' => 'CAPTCHA',
|
15
|
);
|
16
|
}
|
17
|
|
18
|
public function setUp() {
|
19
|
parent::setUp('image_captcha');
|
20
|
}
|
21
|
|
22
|
/**
|
23
|
* Helper function to get the CAPTCHA image element from the current form.
|
24
|
*/
|
25
|
protected function getCaptchaImageFromForm() {
|
26
|
$elements = $this->xpath('//input[@name="captcha_sid"]/../img');
|
27
|
return $elements[0];
|
28
|
}
|
29
|
|
30
|
/**
|
31
|
* Helper function to get a CAPTCHA form.
|
32
|
*/
|
33
|
protected function getImageCaptchaForm($form_id = 'user_login', $page = 'user') {
|
34
|
// Set a CAPTCHA on supplied form.
|
35
|
captcha_set_form_id_setting($form_id, 'image_captcha/Image');
|
36
|
|
37
|
// Fetch the page and make sure that we got a CAPTCHA.
|
38
|
$this->drupalGet($page);
|
39
|
$this->assertCaptchaPresence(TRUE);
|
40
|
}
|
41
|
|
42
|
/**
|
43
|
* Asserts that the image URL actually returns an image.
|
44
|
*/
|
45
|
protected function assertNonEmptyImage() {
|
46
|
$img = $this->getCaptchaImageFromForm();
|
47
|
|
48
|
// Try to fetch the image.
|
49
|
$this->drupalGet($this->getAbsoluteUrl($img['src']));
|
50
|
$this->assertTrue($this->drupalGetHeader('Content-Length') > 0,
|
51
|
'Image CAPTCHA image is not empty.');
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* Tests if the image URL actually returns an image with clean URLs enabled.
|
56
|
*/
|
57
|
public function testNonEmptyImageCleanURLs() {
|
58
|
variable_set('clean_url', 1);
|
59
|
$this->getImageCaptchaForm();
|
60
|
$this->assertNonEmptyImage();
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* Tests if the image URL actually returns an image with clean URLs disabled.
|
65
|
*/
|
66
|
public function testNonEmptyImageDirtyURLs() {
|
67
|
variable_set('clean_url', 0);
|
68
|
$this->getImageCaptchaForm();
|
69
|
$this->assertNonEmptyImage();
|
70
|
}
|
71
|
|
72
|
}
|