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
|
* {@inheritdoc}
|
29
|
*/
|
30
|
public function setUp(array $modules = array()) {
|
31
|
$modules[] = 'field_ui';
|
32
|
$modules[] = 'link';
|
33
|
parent::setUp($modules);
|
34
|
}
|
35
|
|
36
|
/**
|
37
|
* Create Field API.
|
38
|
*
|
39
|
* All we're doing here is creating a content type, creating a simple link
|
40
|
* field on that content type.
|
41
|
*/
|
42
|
public function testLinkCreateFieldApi() {
|
43
|
$content_type_friendly = $this->randomName(20);
|
44
|
$content_type_machine = strtolower($this->randomName(10));
|
45
|
|
46
|
// Create and login user.
|
47
|
$this->web_user = $this->drupalCreateUser(array(
|
48
|
'administer content types',
|
49
|
'administer fields',
|
50
|
));
|
51
|
$this->drupalLogin($this->web_user);
|
52
|
|
53
|
$this->drupalGet('admin/structure/types');
|
54
|
|
55
|
// Create the content type.
|
56
|
$this->clickLink(t('Add content type'));
|
57
|
|
58
|
$edit = array(
|
59
|
'name' => $content_type_friendly,
|
60
|
'type' => $content_type_machine,
|
61
|
);
|
62
|
$this->drupalPost(NULL, $edit, t('Save and add fields'));
|
63
|
$this->assertText(t('The content type @name has been added.', array('@name' => $content_type_friendly)));
|
64
|
|
65
|
// Now add a singleton field.
|
66
|
$single_field_name_friendly = $this->randomName(20);
|
67
|
$single_field_name_machine = strtolower($this->randomName(10));
|
68
|
$edit = array(
|
69
|
'fields[_add_new_field][label]' => $single_field_name_friendly,
|
70
|
'fields[_add_new_field][field_name]' => $single_field_name_machine,
|
71
|
'fields[_add_new_field][type]' => 'link_field',
|
72
|
'fields[_add_new_field][widget_type]' => 'link_field',
|
73
|
);
|
74
|
$this->drupalPost(NULL, $edit, t('Save'));
|
75
|
|
76
|
// We'll go with the default settings for this run-through.
|
77
|
$this->drupalPost(NULL, array(), t('Save field settings'));
|
78
|
|
79
|
// Using all the default settings, so press the button.
|
80
|
$this->drupalPost(NULL, array(), t('Save settings'));
|
81
|
$this->assertText(t('Saved @name configuration.', array('@name' => $single_field_name_friendly)));
|
82
|
|
83
|
// Somehow clicking "save" isn't enough, and we have to do a
|
84
|
// node_types_rebuild().
|
85
|
node_types_rebuild();
|
86
|
menu_rebuild();
|
87
|
$type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $content_type_machine))->fetchField();
|
88
|
$this->assertTrue($type_exists, 'The new content type has been created in the database.');
|
89
|
}
|
90
|
|
91
|
}
|