Projet

Général

Profil

Paste
Télécharger (2,96 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / webform_validation / tests / WebformValidationTestCase.test @ 65389548

1
<?php
2

    
3
/**
4
 * Test Webform Validation module.
5
 */
6
class WebformValidationTestCase extends WebformTestCase {
7

    
8
  /**
9
   * {@inheritdoc}
10
   */
11
  public static function getInfo() {
12
    return array(
13
      'name' => t('Webform Validation'),
14
      'description' => t('Test Webform Validation module.'),
15
      'group' => t('Webform'),
16
    );
17
  }
18

    
19
  /**
20
   * {@inheritdoc}
21
   */
22
  public function setUp($added_modules = array()) {
23
    $modules = array('webform_validation', 'webform_validation_testing');
24
    parent::setUp(array_merge($modules, $added_modules));
25
  }
26

    
27
  /**
28
   * The tests.
29
   */
30
  public function test() {
31
    // Create test Webform.
32
    $node = $this->webformForm();
33

    
34
    // Access to "Form validation" tab.
35
    $this->drupalLogin($this->webform_users['userAccess']);
36
    $this->drupalGet('node/' . $node->nid . '/webform/validation');
37
    $this->assertResponse(403, 'Authenticated user does not have access to "Form validation" tab');
38

    
39
    // Empty validation rules list.
40
    $this->drupalLogin($this->webform_users['admin']);
41
    $this->drupalGet('node/' . $node->nid . '/webform/validation');
42
    $this->assertResponse(200, 'Webform admin user has access to "Form validation" tab');
43
    $this->assertTitle('Test Webform | Drupal');
44
    $this->assertText('Add a validation rule');
45
    $this->assertText('No validation rules available.');
46

    
47
    // Rule creation page.
48
    $this->clickLink('Minimum length');
49
    $this->assertTitle('Add validation rule | Drupal');
50
    $this->assertText('Minimum length');
51
    $element = $this->xpath("//input[@id='edit-data'][@name='data'][@type='text']");
52
    $this->assertTrue($element, 'Page contains "edit-data" input.');
53

    
54
    // Rule created.
55
    $values = array(
56
      'rulename' => $this->randomString(),
57
      'rule_components[21]' => TRUE,
58
      'data' => 2,
59
    );
60
    $this->drupalPost(NULL, $values, t('Add rule'));
61
    $this->assertText(htmlspecialchars($values['rulename'], ENT_QUOTES), 'Rule name appears on page.');
62

    
63
    // Test rule creation validation.
64
    $this->clickLink('Compare two values');
65
    $this->assertTitle('Add validation rule | Drupal');
66
    $this->assertText('Compare two values');
67
    $values = array(
68
      'rulename' => $this->randomString(),
69
      'data' => 'invalid',
70
    );
71
    $this->drupalPost(NULL, $values, t('Add rule'));
72
    $this->assertText('Comparison operator is invalid.', 'Custom data validation fails.');
73
    $this->assertText('You need to select exactly 2 components.', 'Custom data validation fails.');
74
    $this->assertText('Custom error message field is required.', 'Custom data validation fails.');
75

    
76
    $values = array(
77
      'rule_components[20]' => TRUE,
78
      'rule_components[21]' => TRUE,
79
      'data' => '<',
80
      'error_message' => 'Error message.',
81
    );
82
    $this->drupalPost(NULL, $values, t('Add rule'));
83

    
84
    $this->clickLink('Webform Validation Testing 1');
85
    $element = $this->xpath("//textarea[@id='edit-data'][@name='data']");
86
    $this->assertTrue($element, 'Page contains "edit-data" textarea.');
87
  }
88

    
89
}