Projet

Général

Profil

Révision 7fe061e8

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

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/link/tests/link.crud_browser.test
312 312
    $this->assertFalse($instance['settings']['attributes']['class'], 'By default, no class should be set.');
313 313
    $this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.');
314 314
  }
315
  
316
  /**
317
   * If we're creating a new field and just hit 'save' on the default options, we want to make
318
   * sure they are set to the expected results.
319
   */
320
  function testCRUDCreateFieldWithClass() {
321
    $this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
322
    $this->drupalLogin($this->web_user);
323

  
324
    // create field
325
    $name = strtolower($this->randomName());
326
    $edit = array(
327
      'fields[_add_new_field][label]' => $name,
328
      'fields[_add_new_field][field_name]' => $name,
329
      'fields[_add_new_field][type]' => 'link_field',
330
      'fields[_add_new_field][widget_type]' => 'link_field',
331
    );
332
    $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
333

  
334
    $this->drupalPost(NULL, array(), t('Save field settings'));
335
    $link_class_name = 'basic-link-' . strtolower($this->randomName());
336
    $edit = array(
337
      'instance[settings][attributes][class]' => $link_class_name,
338
    );
339
    $this->drupalPost(NULL, $edit, t('Save settings'));
340

  
341
    // Is field created?
342
    $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
343
    node_types_rebuild();
344
    menu_rebuild();
345

  
346
    _field_info_collate_fields(TRUE);
347
    $instances = field_info_instances('node', 'page');
348

  
349
    $instance = $instances['field_' . $name];
350
    $this->assertFalse($instance['required'], 'Make sure field is not required.');
351
    $this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.');
352
    $this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.');
353
    $this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be on by default.');
354
    $this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.');
355
    $this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"');
356
    $this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.');
357
    $this->assertEqual($instance['settings']['attributes']['class'], $link_class_name, 'One class should be set.');
358
    $this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.');
359
    
360
    // Now, let's create a node with this field and make sure the link shows up:
361
    // create page form
362
    $field_name = 'field_' . $name;
363
    $this->drupalGet('node/add/page');
364
    $this->assertField($field_name . '[und][0][url]', 'URL found');
365

  
366
    $input = array(
367
      'title' => 'This & That',
368
      'href' => 'http://www.example.com/',
369
    );
370

  
371
    $edit = array(
372
      'title' => $field_name,
373
      $field_name . '[und][0][title]' => $input['title'],
374
      $field_name . '[und][0][url]' => $input['href'],
375
    );
376
    $this->drupalPost(NULL, $edit, t('Save'));
377

  
378
    $url = $this->getUrl();
379
    
380
    // change to anonymous user
381
    $this->drupalLogout();
382
    $this->drupalGet($url);
383

  
384
    $this->assertRaw('This & That');
385
    $this->assertPattern('|class\s?=\s?"' . $link_class_name . '"|', "Class $link_class_name exists on page.");
386
  }
387

  
388
/**
389
   * If we're creating a new field and just hit 'save' on the default options, we want to make
390
   * sure they are set to the expected results.
391
   */
392
  function testCRUDCreateFieldWithTwoClasses() {
393
    $this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
394
    $this->drupalLogin($this->web_user);
395

  
396
    // create field
397
    $name = strtolower($this->randomName());
398
    $edit = array(
399
      'fields[_add_new_field][label]' => $name,
400
      'fields[_add_new_field][field_name]' => $name,
401
      'fields[_add_new_field][type]' => 'link_field',
402
      'fields[_add_new_field][widget_type]' => 'link_field',
403
    );
404
    $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
405

  
406
    $this->drupalPost(NULL, array(), t('Save field settings'));
407
    $link_class_name = 'basic-link ' . strtoupper($this->randomName());
408
    $edit = array(
409
      'instance[settings][attributes][class]' => $link_class_name,
410
    );
411
    $this->drupalPost(NULL, $edit, t('Save settings'));
412

  
413
    // Is field created?
414
    $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
415
    node_types_rebuild();
416
    menu_rebuild();
417

  
418
    _field_info_collate_fields(TRUE);
419
    $instances = field_info_instances('node', 'page');
420

  
421
    $instance = $instances['field_' . $name];
422
    $this->assertFalse($instance['required'], 'Make sure field is not required.');
423
    $this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.');
424
    $this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.');
425
    $this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be on by default.');
426
    $this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.');
427
    $this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"');
428
    $this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.');
429
    $this->assertEqual($instance['settings']['attributes']['class'], $link_class_name, 'Two classes should be set.');
430
    $this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.');
431
    
432
    // Now, let's create a node with this field and make sure the link shows up:
433
    // create page form
434
    $field_name = 'field_' . $name;
435
    $this->drupalGet('node/add/page');
436
    $this->assertField($field_name . '[und][0][url]', 'URL found');
437

  
438
    $input = array(
439
      'title' => 'This & That',
440
      'href' => 'http://www.example.com/',
441
    );
442

  
443
    $edit = array(
444
      'title' => $field_name,
445
      $field_name . '[und][0][title]' => $input['title'],
446
      $field_name . '[und][0][url]' => $input['href'],
447
    );
448
    $this->drupalPost(NULL, $edit, t('Save'));
449

  
450
    $url = $this->getUrl();
451
    
452
    // change to anonymous user
453
    $this->drupalLogout();
454
    $this->drupalGet($url);
455

  
456
    $this->assertRaw('This & That');
457
    $this->assertPattern('|class\s?=\s?"' . $link_class_name . '"|', "Classes $link_class_name exist on page.");
458
  }
315 459
}

Formats disponibles : Unified diff