Projet

Général

Profil

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

root / htmltest / sites / all / modules / link / tests / link.crud.test @ a5572547

1
<?php
2

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

    
8
class LinkContentCrudTest extends DrupalWebTestCase {
9

    
10
  public static function getInfo() {
11
    return array(
12
      'name' => 'Link CRUD - Basic API tests',
13
      'description' => 'Tests the field CRUD (create, read, update, delete) API.',
14
      'group' => 'Link',
15
    );
16
  }
17

    
18
  function setUp() {
19
    parent::setUp('field_ui', 'link');
20
  }
21

    
22
  /**
23
   * All we're doing here is creating a content type, creating a simple link field
24
   * on that content type.
25
   */
26
  function testLinkCreateFieldAPI() {
27
    $content_type_friendly = $this->randomName(20);
28
    $content_type_machine = strtolower($this->randomName(10));
29
    $title = $this->randomName(20);
30

    
31
    // Create and login user.
32
    $this->web_user = $this->drupalCreateUser(array('administer content types'));
33
    $this->drupalLogin($this->web_user);
34

    
35
    $this->drupalGet('admin/structure/types');
36

    
37
    // Create the content type.
38
    $this->clickLink(t('Add content type'));
39

    
40
    $edit = array (
41
      'name' => $content_type_friendly,
42
      'type' => $content_type_machine,
43
    );
44
    $this->drupalPost(NULL, $edit, t('Save and add fields'));
45
    $this->assertText(t('The content type @name has been added.', array('@name' => $content_type_friendly)));
46

    
47
    //$field = $this->createField(array('type' => 'link', 'widget_type' => 'link'), 0);
48
    // Now add a singleton field.
49
    $single_field_name_friendly = $this->randomName(20);
50
    $single_field_name_machine = strtolower($this->randomName(10));
51
    $edit = array (
52
      'fields[_add_new_field][label]' => $single_field_name_friendly,
53
      'fields[_add_new_field][field_name]' => $single_field_name_machine,
54
      'fields[_add_new_field][type]' => 'link_field',
55
      'fields[_add_new_field][widget_type]' => 'link_field',
56
    );
57
    $this->drupalPost(NULL, $edit, t('Save'));
58

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

    
62
    // Using all the default settings, so press the button.
63
    $this->drupalPost(NULL, array(), t('Save settings'));
64
    $this->assertText(t('Saved @name configuration.', array('@name' => $single_field_name_friendly)));
65

    
66
    // Somehow clicking "save" isn't enough, and we have to do a
67
    // node_types_rebuild().
68
    node_types_rebuild();
69
    menu_rebuild();
70
    $type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $content_type_machine))->fetchField();
71
    $this->assertTrue($type_exists, 'The new content type has been created in the database.');
72

    
73
    /*$table_schema = drupal_get_schema();
74
    $this->assertEqual(1, 1, print_r(array_keys($table_schema), TRUE));
75
    // Check the schema - the values should be in the per-type table.
76
    $this->assertSchemaMatchesTables(array(
77
      'per_type' => array(
78
        $this->content_types[0]->type => array($field['field_name'] => array('url', 'title', 'attributes')),
79
      ),
80
    ));*/
81
  }
82
}