Projet

Général

Profil

Révision c8740e19

Ajouté par Assos Assos il y a plus de 9 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/link/tests/link.crud_browser.test
76 76
    //$this->drupalGet('node/add');
77 77
    $this->drupalGet('node/add/page');
78 78
    $field_name = 'field_' . $name;
79
    $this->assertField('edit-field-'. $name .'-und-0-title', 'Title found');
80
    $this->assertField('edit-field-'. $name .'-und-0-url', 'URL found');
79
    $this->assertField('edit-field-' . $name . '-und-0-title', 'Title found');
80
    $this->assertField('edit-field-' . $name . '-und-0-url', 'URL found');
81 81

  
82 82
    $input_test_cases = array(
83 83
      array(
......
124 124
      ),
125 125
    );
126 126
    $test_case = array(
127
      'href' => 'www.example.com/'. $this->randomName(),
127
      'href' => 'www.example.com/' . $this->randomName(),
128 128
      'label' => $this->randomName(),
129 129
      'msg' => 'Link found',
130 130
      'type' => self::LINK_INPUT_TYPE_GOOD,
131 131
    );
132
    $test_case['expected_href'] = 'http://'. $test_case['href'];
132
    $test_case['expected_href'] = 'http://' . $test_case['href'];
133 133
    $input_test_cases[] = $test_case;
134 134

  
135 135
    foreach ($input_test_cases as $input) {
......
143 143
      );
144 144
      $this->drupalPost(NULL, $edit, t('Save'));
145 145
      if ($input['type'] == self::LINK_INPUT_TYPE_BAD_URL) {
146
        $this->assertRaw(t('The value provided for %field is not a valid URL.', array('%field' => $name)), 'Not a valid URL: ' . $input['href']);
146
        $this->assertRaw(t('The value %value provided for %field is not a valid URL.', array('%field' => $name, '%value' => trim($input['href']))), 'Not a valid URL: ' . $input['href']);
147 147
        continue;
148 148
      }
149 149
      else {
150
        $this->assertRaw(t(' has been created.',
150
        $this->assertRaw(' ' . t('has been created.',
151 151
                           array('@type' => 'Basic Page', '%title' => $edit['title'])),
152 152
                         'Page created: ' . $input['href']);
153 153
      }
154 154
      $url = $this->getUrl();
155 155

  
156
      // change to anonym user
156
      // change to Anonymous user.
157 157
      $this->drupalLogout();
158 158

  
159 159
      $this->drupalGet($url);
......
162 162
      // us and let us know it's broken.
163 163
      $this->assertFalse(libxml_use_internal_errors(TRUE));
164 164
      if (isset($input['expected_href'])) {
165
        $path = '//a[@href="'. $input['expected_href'] .'" and text()="'. $input['label'] .'"]';
165
        $path = '//a[@href="' . $input['expected_href'] . '" and text()="' . $input['label'] . '"]';
166 166
      }
167 167
      else {
168
        $path = '//a[@href="'. $input['href'] .'" and text()="'. $input['label'] .'"]';
168
        $path = '//a[@href="' . $input['href'] . '" and text()="' . $input['label'] . '"]';
169 169
      }
170
      //$this->pass(htmlentities($path));
171 170
      $elements = $this->xpath($path);
172 171
      libxml_use_internal_errors(FALSE);
173 172
      $this->assertIdentical(isset($elements[0]), $input['type'] == self::LINK_INPUT_TYPE_GOOD, $input['msg']);
......
185 184

  
186 185
    // create field
187 186
    $name = strtolower($this->randomName());
188
    $field_name = 'field_'. $name;
187
    $field_name = 'field_' . $name;
189 188
    $edit = array(
190 189
      'fields[_add_new_field][label]' => $name,
191 190
      'fields[_add_new_field][field_name]' => $name,
......
196 195
    $this->drupalPost(NULL, array(), t('Save field settings'));
197 196
    $this->drupalPost(NULL, array(
198 197
      'instance[settings][title]' => 'value',
199
      'instance[settings][title_value]' => '<strong>'. $name .'</strong>'), t('Save settings'));
198
      'instance[settings][title_value]' => '<strong>' . $name . '</strong>'), t('Save settings'));
200 199

  
201 200
    // Is field created?
202 201
    $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
......
221 220
    $this->drupalLogout();
222 221
    $this->drupalGet($url);
223 222

  
224
    $this->assertRaw(l('<strong>'. $name .'</strong>', $input['href'], array('html' => TRUE)));
223
    $this->assertRaw(l('<strong>' . $name . '</strong>', $input['href'], array('html' => TRUE)));
224
  }
225
  
226
  /**
227
   * Testing that if you have the title but no url, the title is not sanitized twice.
228
   */
229
  function testCRUDTitleOnlyTitleNoLink() {
230
    $this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
231
    $this->drupalLogin($this->web_user);
232

  
233
    // create field
234
    $name = strtolower($this->randomName());
235
    $field_name = 'field_' . $name;
236
    $edit = array(
237
      'fields[_add_new_field][label]' => $name,
238
      'fields[_add_new_field][field_name]' => $name,
239
      'fields[_add_new_field][type]' => 'link_field',
240
      'fields[_add_new_field][widget_type]' => 'link_field',
241
    );
242
    $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
243
    $this->drupalPost(NULL, array(), t('Save field settings'));
244
    $this->drupalPost(NULL, array(
245
      'instance[settings][url]' => 1,
246
    ), t('Save settings'));
247

  
248
    // Is field created?
249
    $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
250
    
251
    // create page form
252
    $this->drupalGet('node/add/page');
253
    $this->assertField($field_name . '[und][0][url]', 'URL found');
254

  
255
    $input = array(
256
      'title' => 'This & That',
257
      'href' => '',
258
    );
259

  
260
    $edit = array(
261
      'title' => $name,
262
      $field_name . '[und][0][title]' => $input['title'],
263
      $field_name . '[und][0][url]' => $input['href'],
264
    );
265
    $this->drupalPost(NULL, $edit, t('Save'));
266

  
267
    $url = $this->getUrl();
268
    
269
    // change to anonymous user
270
    $this->drupalLogout();
271
    $this->drupalGet($url);
272

  
273
    $this->assertRaw('This &amp; That');
225 274
  }
226 275

  
227 276
  /**
......
248 297
    $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
249 298
    node_types_rebuild();
250 299
    menu_rebuild();
251
    //_content_type_info(TRUE);
252
    //$fields = content_fields();
253
    //$field = $fields['field_'. $name];
254
    //$field = field_info_field('field_'. $name);
300

  
255 301
    _field_info_collate_fields(TRUE);
256 302
    $instances = field_info_instances('node', 'page');
257
    //$this->debug($instances);
258
    //$this->assert('debug', '<pre>'. print_r($instances, TRUE) .'</pre>', 'Debug');
259
    $instance = $instances['field_'. $name];
260
    //$this->assertTrue(1 === $instance['validate_url'], 'Make sure validation is on.');
303

  
304
    $instance = $instances['field_' . $name];
261 305
    $this->assertFalse($instance['required'], 'Make sure field is not required.');
262 306
    $this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.');
263
    $this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be off by default.');
307
    $this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.');
308
    $this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be on by default.');
264 309
    $this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.');
265 310
    $this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"');
266 311
    $this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.');
267 312
    $this->assertFalse($instance['settings']['attributes']['class'], 'By default, no class should be set.');
268 313
    $this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.');
269

  
270
    //$this->fail('<pre>'. print_r($fields['field_'. $name], TRUE) .'</pre>');
271 314
  }
272 315
}

Formats disponibles : Unified diff