5 * Contains \Drupal\linkit\Tests\ProfileCreationTest.
8 namespace Drupal\linkit\Tests;
9 use Drupal\Component\Utility\Unicode;
13 * Tests creating, loading and deleting profiles.
17 class ProfileCrudTest extends LinkitTestBase {
22 protected function setUp() {
25 $this->drupalLogin($this->adminUser);
29 * Test the overview page.
31 function testOverview() {
32 // Verify that the profile collection page is not accessible for regular
34 $this->drupalLogin($this->baseUser);
35 $this->drupalGet(Url::fromRoute('entity.linkit_profile.collection'));
36 $this->assertResponse(403);
37 $this->drupalLogout();
39 // Verify that the profile collection page is accessible for regular users.
40 $this->drupalLogin($this->adminUser);
43 $profiles[] = $this->createProfile();
44 $profiles[] = $this->createProfile();
46 $this->drupalGet(Url::fromRoute('entity.linkit_profile.collection'));
47 $this->assertResponse(200);
49 // Assert that the 'Add profile' action exists.
50 $this->assertLinkByHref(Url::fromRoute('entity.linkit_profile.add_form')->toString());
52 /** @var \Drupal\linkit\ProfileInterface $profile */
53 foreach ($profiles as $profile) {
54 $this->assertLinkByHref('admin/config/content/linkit/manage/' . $profile->id());
55 $this->assertLinkByHref('admin/config/content/linkit/manage/' . $profile->id() . '/delete');
62 function testProfileCreation() {
63 $this->drupalGet(Url::fromRoute('entity.linkit_profile.add_form'));
64 $this->drupalGet('admin/config/content/linkit/add');
65 $this->assertResponse(200);
69 $edit['label'] = Unicode::strtolower($this->randomMachineName());
70 $edit['id'] = Unicode::strtolower($this->randomMachineName());
71 $edit['description'] = $this->randomMachineName(16);
72 $this->drupalPostForm(NULL, $edit, t('Save and manage matchers'));
74 $this->assertRaw(t('Created new profile %label.', ['%label' => $edit['label']]));
76 $this->drupalGet(Url::fromRoute('entity.linkit_profile.collection'));
77 $this->assertText($edit['label'], 'Profile exists in the profile collection.');
83 function testProfileUpdate() {
84 $profile = $this->createProfile();
85 $this->drupalGet(Url::fromRoute('entity.linkit_profile.edit_form', [
86 'linkit_profile' => $profile->id(),
88 $this->assertResponse(200);
90 $id_field = $this->xpath('.//input[not(@disabled) and @name="id"]');
92 $this->assertTrue(empty($id_field), 'Machine name field is disabled.');
93 $this->assertLinkByHref(Url::fromRoute('entity.linkit_profile.edit_form', [
94 'linkit_profile' => $profile->id(),
96 $this->assertLinkByHref('admin/config/content/linkit/manage/' . $profile->id() . '/delete');
99 $edit['label'] = $this->randomMachineName();
100 $edit['description'] = $this->randomMachineName(16);
101 $this->drupalPostForm(NULL, $edit, t('Update profile'));
103 $this->assertRaw(t('Updated profile %label.', ['%label' => $edit['label']]));
105 $this->drupalGet(Url::fromRoute('entity.linkit_profile.collection'));
106 $this->assertText($edit['label'], 'Updated profile exists in the profile collection.');
112 function testProfileDelete() {
113 /** @var \Drupal\linkit\ProfileInterface $profile */
114 $profile = $this->createProfile();
115 $this->drupalGet(Url::fromRoute('entity.linkit_profile.delete_form', [
116 'linkit_profile' => $profile->id(),
118 $this->drupalPostForm(NULL, [], t('Delete'));
120 $this->assertRaw(t('The linkit profile %label has been deleted.', ['%label' => $profile->label()]));
121 $this->drupalGet(Url::fromRoute('entity.linkit_profile.collection'));
122 $this->assertNoText($profile->label(), 'Deleted profile does not exists in the profile collection.');