3
3
namespace Drupal \content_entity_example \Tests ;
4
4
5
5
use Drupal \content_entity_example \Entity \Contact ;
6
- use Drupal \examples \Tests \ ExamplesTestBase ;
6
+ use Drupal \Tests \ examples \Functional \ ExamplesBrowserTestBase ;
7
7
8
8
/**
9
9
* Tests the basic functions of the Content Entity Example module.
15
15
* @group content_entity_example
16
16
* @group examples
17
17
*/
18
- class ContentEntityExampleTest extends ExamplesTestBase {
18
+ class ContentEntityExampleTest extends ExamplesBrowserTestBase {
19
19
20
20
public static $ modules = array ('content_entity_example ' , 'block ' , 'field_ui ' );
21
21
22
22
/**
23
23
* Basic tests for Content Entity Example.
24
24
*/
25
25
public function testContentEntityExample () {
26
+ $ assert = $ this ->assertSession ();
27
+
26
28
$ web_user = $ this ->drupalCreateUser (array (
27
29
'add contact entity ' ,
28
30
'edit contact entity ' ,
@@ -35,26 +37,26 @@ public function testContentEntityExample() {
35
37
));
36
38
37
39
// Anonymous User should not see the link to the listing.
38
- $ this -> assertNoText ( t ( 'Content Entity Example: Contacts Listing ' ) );
40
+ $ assert -> pageTextNotContains ( 'Content Entity Example: Contacts Listing ' );
39
41
40
42
$ this ->drupalLogin ($ web_user );
41
43
42
44
// Web_user user has the right to view listing.
43
- $ this -> assertLink ( t ( 'Content Entity Example: Contacts Listing ' ) );
45
+ $ assert -> linkExists ( 'Content Entity Example: Contacts Listing ' );
44
46
45
- $ this ->clickLink (t ( 'Content Entity Example: Contacts Listing ' ) );
47
+ $ this ->clickLink ('Content Entity Example: Contacts Listing ' );
46
48
47
49
// WebUser can add entity content.
48
- $ this -> assertLink ( t ( 'Add Contact ' ) );
50
+ $ assert -> linkExists ( 'Add Contact ' );
49
51
50
52
$ this ->clickLink (t ('Add Contact ' ));
51
53
52
- $ this -> assertFieldByName ('name[0][value] ' , '' , ' Name Field, empty ' );
53
- $ this -> assertFieldByName ('name[0][value] ' , '' , ' First Name Field, empty ' );
54
- $ this -> assertFieldByName ('name[0][value] ' , '' , ' Gender Field, empty ' );
54
+ $ assert -> fieldValueEquals ('name[0][value] ' , '' );
55
+ $ assert -> fieldValueEquals ('name[0][value] ' , '' );
56
+ $ assert -> fieldValueEquals ('name[0][value] ' , '' );
55
57
56
58
$ user_ref = $ web_user ->name ->value . ' ( ' . $ web_user ->id () . ') ' ;
57
- $ this -> assertFieldByName ('user_id[0][target_id] ' , $ user_ref, ' User ID reference field points to web_user ' );
59
+ $ assert -> fieldValueEquals ('user_id[0][target_id] ' , $ user_ref );
58
60
59
61
// Post content, save an instance. Go back to list after saving.
60
62
$ edit = array (
@@ -65,44 +67,46 @@ public function testContentEntityExample() {
65
67
$ this ->drupalPostForm (NULL , $ edit , t ('Save ' ));
66
68
67
69
// Entity listed.
68
- $ this -> assertLink ( t ( 'Edit ' ) );
69
- $ this -> assertLink ( t ( 'Delete ' ) );
70
+ $ assert -> linkExists ( 'Edit ' );
71
+ $ assert -> linkExists ( 'Delete ' );
70
72
71
73
$ this ->clickLink ('test name ' );
72
74
73
75
// Entity shown.
74
- $ this -> assertText ( t ( 'test name ' ) );
75
- $ this -> assertText ( t ( 'test first name ' ) );
76
- $ this -> assertText ( t ( 'male ' ) );
77
- $ this -> assertLink ( t ( 'Add Contact ' ) );
78
- $ this -> assertLink ( t ( 'Edit ' ) );
79
- $ this -> assertLink ( t ( 'Delete ' ) );
76
+ $ assert -> pageTextContains ( 'test name ' );
77
+ $ assert -> pageTextContains ( 'test first name ' );
78
+ $ assert -> pageTextContains ( 'male ' );
79
+ $ assert -> linkExists ( 'Add Contact ' );
80
+ $ assert -> linkExists ( 'Edit ' );
81
+ $ assert -> linkExists ( 'Delete ' );
80
82
81
83
// Delete the entity.
82
84
$ this ->clickLink ('Delete ' );
83
85
84
86
// Confirm deletion.
85
- $ this -> assertLink ( t ( 'Cancel ' ) );
87
+ $ assert -> linkExists ( 'Cancel ' );
86
88
$ this ->drupalPostForm (NULL , array (), 'Delete ' );
87
89
88
90
// Back to list, must be empty.
89
- $ this -> assertNoText ('test name ' );
91
+ $ assert -> pageTextNotContains ('test name ' );
90
92
91
93
// Settings page.
92
94
$ this ->drupalGet ('admin/structure/content_entity_example_contact_settings ' );
93
- $ this -> assertText ( t ( 'Contact Settings ' ) );
95
+ $ assert -> pageTextContains ( 'Contact Settings ' );
94
96
95
97
// Make sure the field manipulation links are available.
96
- $ this -> assertLink ( t ( 'Settings ' ) );
97
- $ this -> assertLink ( t ( 'Manage fields ' ) );
98
- $ this -> assertLink ( t ( 'Manage form display ' ) );
99
- $ this -> assertLink ( t ( 'Manage display ' ) );
98
+ $ assert -> linkExists ( 'Settings ' );
99
+ $ assert -> linkExists ( 'Manage fields ' );
100
+ $ assert -> linkExists ( 'Manage form display ' );
101
+ $ assert -> linkExists ( 'Manage display ' );
100
102
}
101
103
102
104
/**
103
105
* Test all paths exposed by the module, by permission.
104
106
*/
105
107
public function testPaths () {
108
+ $ assert = $ this ->assertSession ();
109
+
106
110
// Generate a contact so that we can test the paths against it.
107
111
$ contact = Contact::create (
108
112
array (
@@ -129,7 +133,7 @@ public function testPaths() {
129
133
$ this ->drupalLogin ($ user );
130
134
}
131
135
$ this ->drupalGet ($ datum [1 ]);
132
- $ this -> assertResponse ($ datum [0 ]);
136
+ $ assert -> statusCodeEquals ($ datum [0 ]);
133
137
}
134
138
}
135
139
@@ -237,8 +241,7 @@ public function testAddFields() {
237
241
238
242
// Fetch url without query parameters.
239
243
$ current_path = strtok ($ this ->getUrl (), '? ' );
240
- $ this ->assertEqual ($ expected_path , $ current_path , 'It should redirect to field storage settings page. ' );
241
-
244
+ $ this ->assertEquals ($ expected_path , $ current_path );
242
245
}
243
246
244
247
}
0 commit comments