ProfileAdminTest.php in Linkit 8.5
File
tests/src/Functional/ProfileAdminTest.php
View source
<?php
namespace Drupal\Tests\linkit\Functional;
use Drupal\linkit\Tests\ProfileCreationTrait;
class ProfileAdminTest extends LinkitBrowserTestBase {
use ProfileCreationTrait;
public function testOverview() {
$this
->drupalLogin($this->webUser);
$this
->drupalGet('/admin/config/content/linkit');
$this
->assertSession()
->statusCodeEquals(403);
$this
->drupalLogout();
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('/admin/config/content/linkit');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->linkByHrefExists('/admin/config/content/linkit/add');
$profiles = [];
$profiles[] = $this
->createProfile();
$profiles[] = $this
->createProfile();
$this
->drupalGet('/admin/config/content/linkit');
$this
->assertSession()
->statusCodeEquals(200);
foreach ($profiles as $profile) {
$this
->assertSession()
->linkByHrefExists('/admin/config/content/linkit/manage/' . $profile
->id());
$this
->assertSession()
->linkByHrefExists('/admin/config/content/linkit/manage/' . $profile
->id() . '/delete');
}
}
public function testProfileCreation() {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('/admin/config/content/linkit/add');
$this
->assertSession()
->statusCodeEquals(200);
$edit = [];
$edit['label'] = mb_strtolower($this
->randomMachineName());
$edit['id'] = mb_strtolower($this
->randomMachineName());
$edit['description'] = $this
->randomMachineName(16);
$this
->submitForm($edit, 'Save and manage matchers');
$this
->assertSession()
->pageTextContains('Created new profile ' . $edit['label']);
$this
->drupalGet('/admin/config/content/linkit');
$this
->assertSession()
->pageTextContains($edit['label']);
}
public function testProfileUpdate() {
$this
->drupalLogin($this->adminUser);
$profile = $this
->createProfile();
$this
->drupalGet('/admin/config/content/linkit/manage/' . $profile
->id());
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->elementNotExists('xpath', '//input[not(@disabled) and @name="id"]');
$this
->assertSession()
->buttonExists('Update profile');
$this
->assertSession()
->linkByHrefExists('/admin/config/content/linkit/manage/' . $profile
->id() . '/delete');
$edit = [];
$edit['label'] = $this
->randomMachineName();
$edit['description'] = $this
->randomMachineName(16);
$this
->submitForm($edit, 'Update profile');
$this
->assertSession()
->pageTextContains('Updated profile ' . $edit['label']);
$this
->drupalGet('/admin/config/content/linkit');
$this
->assertSession()
->pageTextContains($edit['label']);
}
public function testProfileDelete() {
$this
->drupalLogin($this->adminUser);
$profile = $this
->createProfile();
$this
->drupalGet('/admin/config/content/linkit/manage/' . $profile
->id() . '/delete');
$this
->assertSession()
->statusCodeEquals(200);
$this
->submitForm([], 'Delete');
$this
->assertSession()
->pageTextContains('The linkit profile ' . $profile
->label() . ' has been deleted.');
$this
->drupalGet('/admin/config/content/linkit');
$this
->assertSession()
->pageTextNotContains($profile
->label());
}
}