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
|
// Now add a singleton field.
|
48
|
$single_field_name_friendly = $this->randomName(20);
|
49
|
$single_field_name_machine = strtolower($this->randomName(10));
|
50
|
$edit = array(
|
51
|
'fields[_add_new_field][label]' => $single_field_name_friendly,
|
52
|
'fields[_add_new_field][field_name]' => $single_field_name_machine,
|
53
|
'fields[_add_new_field][type]' => 'link_field',
|
54
|
'fields[_add_new_field][widget_type]' => 'link_field',
|
55
|
);
|
56
|
$this->drupalPost(NULL, $edit, t('Save'));
|
57
|
|
58
|
// We'll go with the default settings for this run-through.
|
59
|
$this->drupalPost(NULL, array(), t('Save field settings'));
|
60
|
|
61
|
// Using all the default settings, so press the button.
|
62
|
$this->drupalPost(NULL, array(), t('Save settings'));
|
63
|
$this->assertText(t('Saved @name configuration.', array('@name' => $single_field_name_friendly)));
|
64
|
|
65
|
// Somehow clicking "save" isn't enough, and we have to do a
|
66
|
// node_types_rebuild().
|
67
|
node_types_rebuild();
|
68
|
menu_rebuild();
|
69
|
$type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $content_type_machine))->fetchField();
|
70
|
$this->assertTrue($type_exists, 'The new content type has been created in the database.');
|
71
|
}
|
72
|
}
|