Projet

Général

Profil

Révision d50a36e0

Ajouté par Assos Assos il y a presque 4 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/fivestar/test/fivestar.field.test
1 1
<?php
2

  
2 3
/**
3 4
 * @file
4 5
 * Simpletests for the Fivestar module.
5 6
 */
6 7

  
8
/**
9
 * Makes sure fivestar widgets can be created and used.
10
 */
7 11
class FivestarTestCase extends FivestarBaseTestCase {
8 12

  
13
  /**
14
   * Provides test metadata.
15
   */
9 16
  public static function getInfo() {
10 17
    return array(
11 18
      'name' => 'Fivestar widgets',
......
18 25
   * Test that authors can rate their own content.
19 26
   */
20 27
  public function testAuthorRating() {
21
    $this->drupalLogin($this->admin_user);
28
    $this->drupalLogin($this->adminUser);
22 29
    // Add an author-rated fivestar field to the test_node_type content type.
23 30
    $this->createFivestarField(array('widget_type' => 'stars'));
24 31
    // Load the instance settings so we can set allow_ownvote.
25 32
    $instance = field_read_instance('node', 'fivestar_test', 'test_node_type');
26 33
    $instance['settings']['allow_ownvote'] = 1;
27 34
    field_update_instance($instance);
28
    // Save an test_node_typee node with a two-star rating.
35
    // Save a test_node_type node with a two-star rating.
29 36
    $edit = array(
30 37
      'title' => $this->randomString(),
31
      'fivestar_test[und][0][rating]' => '40' // Equals a rating of 2 stars.
38
      // Equals a rating of 2 stars.
39
      'fivestar_test[und][0][rating]' => '40',
32 40
    );
33
    $this->drupalPost('node/add/test_node_type', $edit, t('Save'));
41
    $this->drupalPost('node/add/test_node_type', $edit, 'Save');
34 42
    // Make sure the two-star rating shows on the node view.
35 43
    $result = $this->xpath("//div[contains(@class, 'field-name-fivestar-test')]//div[contains(@class,'star-first')]/span");
36 44
    $this->assertEqual($result[0][0], '2', 'Content authors can rate their own content using the stars widget.');
......
41 49
   */
42 50
  public function testViewerRating() {
43 51
    $this->createFivestarField(array('widget_type' => 'exposed'));
44
    // Add an test_node_type to rate.
52
    // Add a test_node_type to rate.
45 53
    $node = $this->drupalCreateNode(array('type' => 'test_node_type'));
46 54
    $this->drupalGet('node/' . $node->nid);
47
    $this->drupalLogin($this->voter_user);
55
    $this->drupalLogin($this->voterUser);
48 56

  
49 57
    // Rate the test_node_type.
50 58
    $edit = array(
51 59
      'vote' => '60',
52 60
    );
53
    $this->drupalPost('node/' . $node->nid, $edit, t('Rate'));
54
    $this->assertNoRaw(t('No votes yet'), 'Visitors can rate content using the exposed widget.');
61
    $this->drupalPost('node/' . $node->nid, $edit, 'Rate');
62
    $this->assertNoRaw('No votes yet', 'Visitors can rate content using the exposed widget.');
55 63

  
56 64
    // Load the instance settings so we can change certain settings.
57 65
    $instance = field_read_instance('node', 'fivestar_test', 'test_node_type');
58 66

  
59
    // Lets see if visitors is able to re-vote.
60
    // §see http://drupal.org/node/356605
67
    // Let's see if visitors is able to re-vote.
68
    // @see http://drupal.org/node/356605
61 69
    $instance['settings']['allow_revote'] = 1;
62 70
    field_update_instance($instance);
63 71
    $this->drupalGet('node/' . $node->nid);
64 72
    $result = $this->xpath("//div[contains(@class, 'field-name-fivestar-test')]//select[contains(@name,'vote')]");
65 73
    $this->assertEqual(count($result), TRUE, 'Visitors can re-vote');
66 74

  
67
    // Lets test to make sure the cancel option is not available if disabled.
75
    // Let's test to make sure the cancel option is not available if disabled.
68 76
    // @see http://drupal.org/node/1269276
69
    $this->assertNoRaw(t('Cancel rating'), 'User cannot cancel his vote.');
77
    $this->assertNoRaw('Cancel rating', 'User cannot cancel his vote.');
70 78
    $instance['settings']['allow_clear'] = 1;
71 79
    field_update_instance($instance);
72 80
    $this->drupalGet('node/' . $node->nid);
73
    $this->assertRaw(t('Cancel rating'), 'User can cancel his vote.');
81
    $this->assertRaw('Cancel rating', 'User can cancel his vote.');
74 82

  
75
    // Now lets change the field to have exposed off and make sure the value is still there.
83
    // Now let's change the field to have exposed off and make sure the value
84
    // is still there.
76 85
    // @see http://drupal.org/node/1242082
77 86
    $instance['display']['default']['settings']['expose'] = FALSE;
78 87
    field_update_instance($instance);
......
84 93
  }
85 94

  
86 95
  /**
87
   * Test that users can not rate content with exposed widgets that has the exposed
88
   * display setting set to FALSE.
96
   * Test exposed display setting.
97
   *
98
   * Tests that users can not rate content with exposed widgets that have their
99
   * exposed display setting set to FALSE.
89 100
   */
90 101
  public function testViewerNonRating() {
91 102
    // Add an exposed field, with the Exposed display settings set to FALSE.
......
102 113
        ),
103 114
      ),
104 115
    ));
105
    // Add an test_node_type to test static widget.
116
    // Add a test_node_type to test static widget.
106 117
    $node = $this->drupalCreateNode(array('type' => 'test_node_type'));
107 118
    // Rate the test_node_type.
108
    $this->drupalLogin($this->voter_user);
119
    $this->drupalLogin($this->voterUser);
109 120
    $this->drupalGet('node/' . $node->nid);
110
    $this->assertRaw(t('No votes yet'), 'Fivestar field has no votes.');
121
    $this->assertRaw('No votes yet', 'Fivestar field has no votes.');
111 122
    $this->assertFalse($this->xpath("//form[contains(@class, 'fivestar-widget')]"));
112 123
  }
113 124

  
......
117 128
  public function testViewerRatingAjax() {
118 129
    // Add a viewer-rated fivestar field to the test_node_type content type.
119 130
    $this->createFivestarField(array('widget_type' => 'exposed'));
120
    // Add an test_node_type to rate.
131
    // Add a test_node_type to rate.
121 132
    $node = $this->drupalCreateNode(array('type' => 'test_node_type'));
122 133
    // Rate the test_node_type.
123
    $this->drupalLogin($this->voter_user);
134
    $this->drupalLogin($this->voterUser);
124 135
    $edit = array(
125 136
      'vote' => '60',
126 137
    );
......
128 139
      NULL, array(), array(), "fivestar-custom-widget");
129 140
    $expected = array(
130 141
      'command' => 'fivestarUpdate',
131
      // TODO: we should text the data being returned.
142
      // @todo We should test the data being returned.
132 143
    );
133 144
    $this->assertCommand($commands, $expected, "The fivestarUpdate AJAX command was returned.");
134 145
  }
135 146

  
136 147
  /**
148
   * Tests changing the fivestar widget.
149
   *
137 150
   * Test that we can switch the fivestar widgets around for the exposed
138 151
   * widget type.
139 152
   */
140 153
  public function testExposedWidgetDisplay() {
141
    // Lets add an exposed widget but display the static widget.
154
    // Let's add an exposed widget but display the static widget.
142 155
    // It's simpler to compare the display type using the static widget.
143 156
    $this->createFivestarField(array(
144 157
      'widget_type' => 'exposed',
......
154 167
      ),
155 168
    ));
156 169
    $instance = field_read_instance('node', 'fivestar_test', 'test_node_type');
157
    // Add an test_node_type to test widget against.
170
    // Add a test_node_type to test widget against.
158 171
    $node = $this->drupalCreateNode(array('type' => 'test_node_type'));
159 172

  
160 173
    // Test the Default Widget.
......
168 181
      $widget_class = 'fivestar-' . drupal_strtolower($name);
169 182
      $this->drupalGet('node/' . $node->nid);
170 183
      $result = $this->xpath("//div[contains(@class, '" . $widget_class . "')]//div[contains(@class,'star-first')]/span");
171
      $this->assertEqual($result[0][0], '0', t('The @name fivestar widget is properly display.', array('@name' => $name)));
184
      $this->assertEqual($result[0][0], '0', "The $name fivestar widget is properly displayed.");
172 185
    }
173 186
  }
187

  
174 188
}

Formats disponibles : Unified diff