Mercurial > hg > isophonics-drupal-site
comparison core/modules/link/tests/src/Functional/LinkFieldUITest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\link\Functional; | |
4 | |
5 use Drupal\Component\Utility\Unicode; | |
6 use Drupal\field_ui\Tests\FieldUiTestTrait; | |
7 use Drupal\link\LinkItemInterface; | |
8 use Drupal\Tests\BrowserTestBase; | |
9 | |
10 /** | |
11 * Tests link field UI functionality. | |
12 * | |
13 * @group link | |
14 */ | |
15 class LinkFieldUITest extends BrowserTestBase { | |
16 | |
17 use FieldUiTestTrait; | |
18 | |
19 /** | |
20 * Modules to enable. | |
21 * | |
22 * @var array | |
23 */ | |
24 public static $modules = ['node', 'link', 'field_ui', 'block']; | |
25 | |
26 /** | |
27 * A user that can edit content types. | |
28 * | |
29 * @var \Drupal\user\UserInterface | |
30 */ | |
31 protected $adminUser; | |
32 | |
33 /** | |
34 * {@inheritdoc} | |
35 */ | |
36 protected function setUp() { | |
37 parent::setUp(); | |
38 | |
39 $this->adminUser = $this->drupalCreateUser(['administer content types', 'administer node fields', 'administer node display']); | |
40 $this->drupalLogin($this->adminUser); | |
41 $this->drupalPlaceBlock('system_breadcrumb_block'); | |
42 } | |
43 | |
44 /** | |
45 * Tests the link field UI. | |
46 */ | |
47 public function testFieldUI() { | |
48 // Add a content type. | |
49 $type = $this->drupalCreateContentType(); | |
50 $type_path = 'admin/structure/types/manage/' . $type->id(); | |
51 $add_path = 'node/add/' . $type->id(); | |
52 | |
53 // Add a link field to the newly-created type. It defaults to allowing both | |
54 // internal and external links. | |
55 $label = $this->randomMachineName(); | |
56 $field_name = Unicode::strtolower($label); | |
57 $this->fieldUIAddNewField($type_path, $field_name, $label, 'link'); | |
58 | |
59 // Load the formatter page to check that the settings summary does not | |
60 // generate warnings. | |
61 // @todo Mess with the formatter settings a bit here. | |
62 $this->drupalGet("$type_path/display"); | |
63 $this->assertText(t('Link text trimmed to @limit characters', ['@limit' => 80])); | |
64 | |
65 // Test the help text displays when the link field allows both internal and | |
66 // external links. | |
67 $this->drupalLogin($this->drupalCreateUser(['create ' . $type->id() . ' content'])); | |
68 $this->drupalGet($add_path); | |
69 $this->assertRaw('You can also enter an internal path such as <em class="placeholder">/node/add</em> or an external URL such as <em class="placeholder">http://example.com</em>.'); | |
70 | |
71 // Log in an admin to set up the next content type. | |
72 $this->drupalLogin($this->adminUser); | |
73 | |
74 // Add a different content type. | |
75 $type = $this->drupalCreateContentType(); | |
76 $type_path = 'admin/structure/types/manage/' . $type->id(); | |
77 $add_path = 'node/add/' . $type->id(); | |
78 | |
79 // Add a link field to the newly-created type. Specify it must allow | |
80 // external only links. | |
81 $label = $this->randomMachineName(); | |
82 $field_name = Unicode::strtolower($label); | |
83 $field_edit = ['settings[link_type]' => LinkItemInterface::LINK_EXTERNAL]; | |
84 $this->fieldUIAddNewField($type_path, $field_name, $label, 'link', [], $field_edit); | |
85 | |
86 // Test the help text displays when link allows only external links. | |
87 $this->drupalLogin($this->drupalCreateUser(['create ' . $type->id() . ' content'])); | |
88 $this->drupalGet($add_path); | |
89 $this->assertRaw('This must be an external URL such as <em class="placeholder">http://example.com</em>.'); | |
90 } | |
91 | |
92 } |