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