Projet

Général

Profil

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

root / drupal7 / sites / all / modules / link / tests / link.crud.test @ 39a181a4

1
<?php
2

    
3
/**
4
 * @file
5
 * File for Crud Tests.
6
 *
7
 * Basic CRUD simpletests for the link module, based off of content.crud.test in
8
 * CCK.
9
 */
10

    
11
/**
12
 * Content Crud.
13
 */
14
class LinkContentCrudTest extends DrupalWebTestCase {
15

    
16
  /**
17
   * Get Info.
18
   */
19
  public static function getInfo() {
20
    return array(
21
      'name' => 'Link CRUD - Basic API tests',
22
      'description' => 'Tests the field CRUD (create, read, update, delete) API.',
23
      'group' => 'Link',
24
    );
25
  }
26

    
27
  /**
28
   * Setup.
29
   */
30
  public function setUp() {
31
    parent::setUp('field_ui', 'link');
32
  }
33

    
34
  /**
35
   * Create Field API.
36
   *
37
   * All we're doing here is creating a content type, creating a simple link
38
   * field on that content type.
39
   *
40
   * @codingStandardsIgnoreStart
41
   */
42
  public function testLinkCreateFieldAPI() {
43
    // @codingStandardsIgnoreEnd
44
    $content_type_friendly = $this->randomName(20);
45
    $content_type_machine = strtolower($this->randomName(10));
46

    
47
    // Create and login user.
48
    $this->web_user = $this->drupalCreateUser(array(
49
      'administer content types',
50
      'administer fields',
51
    ));
52
    $this->drupalLogin($this->web_user);
53

    
54
    $this->drupalGet('admin/structure/types');
55

    
56
    // Create the content type.
57
    $this->clickLink(t('Add content type'));
58

    
59
    $edit = array(
60
      'name' => $content_type_friendly,
61
      'type' => $content_type_machine,
62
    );
63
    $this->drupalPost(NULL, $edit, t('Save and add fields'));
64
    $this->assertText(t('The content type @name has been added.', array('@name' => $content_type_friendly)));
65

    
66
    // Now add a singleton field.
67
    $single_field_name_friendly = $this->randomName(20);
68
    $single_field_name_machine = strtolower($this->randomName(10));
69
    $edit = array(
70
      'fields[_add_new_field][label]' => $single_field_name_friendly,
71
      'fields[_add_new_field][field_name]' => $single_field_name_machine,
72
      'fields[_add_new_field][type]' => 'link_field',
73
      'fields[_add_new_field][widget_type]' => 'link_field',
74
    );
75
    $this->drupalPost(NULL, $edit, t('Save'));
76

    
77
    // We'll go with the default settings for this run-through.
78
    $this->drupalPost(NULL, array(), t('Save field settings'));
79

    
80
    // Using all the default settings, so press the button.
81
    $this->drupalPost(NULL, array(), t('Save settings'));
82
    $this->assertText(t('Saved @name configuration.', array('@name' => $single_field_name_friendly)));
83

    
84
    // Somehow clicking "save" isn't enough, and we have to do a
85
    // node_types_rebuild().
86
    node_types_rebuild();
87
    menu_rebuild();
88
    $type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $content_type_machine))->fetchField();
89
    $this->assertTrue($type_exists, 'The new content type has been created in the database.');
90
  }
91

    
92
}