MatcherAdminTest.php in Linkit 8.5
File
tests/src/Functional/MatcherAdminTest.php
View source
<?php
namespace Drupal\Tests\linkit\Functional;
use Drupal\linkit\Entity\Profile;
use Drupal\linkit\Tests\ProfileCreationTrait;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class MatcherAdminTest extends LinkitBrowserTestBase {
use ProfileCreationTrait;
use StringTranslationTrait;
protected $manager;
protected $linkitProfile;
protected function setUp() {
parent::setUp();
$this->manager = $this->container
->get('plugin.manager.linkit.matcher');
$this->linkitProfile = $this
->createProfile();
}
public function testOverview() {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('/admin/config/content/linkit/manage/' . $this->linkitProfile
->id() . '/matchers');
$this
->assertSession()
->pageTextContains('No matchers added.');
$this
->assertSession()
->linkByHrefExists('/admin/config/content/linkit/manage/' . $this->linkitProfile
->id() . '/matchers/add');
}
public function testAdd() {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('/admin/config/content/linkit/manage/' . $this->linkitProfile
->id() . '/matchers/add');
$edit = [];
$edit['plugin'] = 'dummy_matcher';
$this
->submitForm($edit, 'Save and continue');
$this
->assertSession()
->pageTextContains('Added Dummy Matcher matcher.');
$this
->assertSession()
->pageTextNotContains('No matchers added.');
}
public function testAddConfigurable() {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('/admin/config/content/linkit/manage/' . $this->linkitProfile
->id() . '/matchers/add');
$edit = [];
$edit['plugin'] = 'configurable_dummy_matcher';
$this
->submitForm($edit, 'Save and continue');
$this->linkitProfile = Profile::load($this->linkitProfile
->id());
$matcher_ids = $this->linkitProfile
->getMatchers()
->getInstanceIds();
$plugin = $this->linkitProfile
->getMatcher(current($matcher_ids));
$this
->assertSession()
->addressEquals('/admin/config/content/linkit/manage/' . $this->linkitProfile
->id() . '/matchers/' . $plugin
->getUuid());
$this
->drupalGet('/admin/config/content/linkit/manage/' . $this->linkitProfile
->id() . '/matchers');
$this
->assertSession()
->pageTextNotContains('No matchers added.');
}
public function testDelete() {
$this
->drupalLogin($this->adminUser);
$plugin = $this->manager
->createInstance('dummy_matcher');
$plugin_uuid = $this->linkitProfile
->addMatcher($plugin
->getConfiguration());
$this->linkitProfile
->save();
$this
->drupalGet('/admin/config/content/linkit/manage/' . $this->linkitProfile
->id() . '/matchers/doesntexists/delete');
$this
->assertSession()
->statusCodeEquals('404');
$this
->drupalGet('/admin/config/content/linkit/manage/' . $this->linkitProfile
->id() . '/matchers/' . $plugin_uuid . '/delete');
$this
->clickLink($this
->t('Cancel'));
$this
->assertSession()
->addressEquals('/admin/config/content/linkit/manage/' . $this->linkitProfile
->id() . '/matchers');
$this
->drupalGet('/admin/config/content/linkit/manage/' . $this->linkitProfile
->id() . '/matchers/' . $plugin_uuid . '/delete');
$this
->submitForm([], $this
->t('Confirm'));
$this
->assertSession()
->pageTextContains('The matcher Dummy Matcher has been deleted.');
$this
->assertSession()
->addressEquals('/admin/config/content/linkit/manage/' . $this->linkitProfile
->id() . '/matchers');
$this
->assertSession()
->pageTextContains('No matchers added.');
$updated_profile = Profile::load($this->linkitProfile
->id());
$this
->assertFalse($updated_profile
->getMatchers()
->has($plugin_uuid), 'The user matcher is deleted from the profile');
}
}
Classes
Name |
Description |
MatcherAdminTest |
Tests adding, listing, updating and deleting matchers on a profile. |