123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- /**
- * @file
- * Tests for the Image CAPTCHA module.
- */
- class ImageCaptchaWebTestCase extends CaptchaBaseWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'General Image CAPTCHA functionality',
- 'description' => 'Testing of the basic Image CAPTCHA functions.',
- 'group' => 'CAPTCHA',
- );
- }
- public function setUp() {
- parent::setUp('image_captcha');
- }
- /**
- * Helper function to get the CAPTCHA image element from the current form.
- */
- protected function getCaptchaImageFromForm() {
- $elements = $this->xpath('//input[@name="captcha_sid"]/../img');
- return $elements[0];
- }
- /**
- * Helper function to get a CAPTCHA form.
- */
- protected function getImageCaptchaForm($form_id = 'user_login', $page = 'user') {
- // Set a CAPTCHA on supplied form.
- captcha_set_form_id_setting($form_id, 'image_captcha/Image');
- // Fetch the page and make sure that we got a CAPTCHA.
- $this->drupalGet($page);
- $this->assertCaptchaPresence(TRUE);
- }
- /**
- * Asserts that the image URL actually returns an image.
- */
- protected function assertNonEmptyImage() {
- $img = $this->getCaptchaImageFromForm();
- // Try to fetch the image.
- $this->drupalGet($this->getAbsoluteUrl($img['src']));
- $this->assertTrue($this->drupalGetHeader('Content-Length') > 0,
- 'Image CAPTCHA image is not empty.');
- }
- /**
- * Tests if the image URL actually returns an image with clean URLs enabled.
- */
- public function testNonEmptyImageCleanURLs() {
- variable_set('clean_url', 1);
- $this->getImageCaptchaForm();
- $this->assertNonEmptyImage();
- }
- /**
- * Tests if the image URL actually returns an image with clean URLs disabled.
- */
- public function testNonEmptyImageDirtyURLs() {
- variable_set('clean_url', 0);
- $this->getImageCaptchaForm();
- $this->assertNonEmptyImage();
- }
- }
|