function MatcherCrudTest::testDelete in Linkit 8.4
Test delete a matcher from a profile.
File
- src/
Tests/ MatcherCrudTest.php, line 115 - Contains \Drupal\linkit\Tests\MatcherCrudTest.
Class
- MatcherCrudTest
- Tests adding, listing, updating and deleting matchers on a profile.
Namespace
Drupal\linkit\TestsCode
function testDelete() {
/** @var \Drupal\linkit\AttributeInterface $plugin */
$plugin = $this->manager
->createInstance('dummy_matcher');
$profile = $this
->createProfile();
$plugin_uuid = $profile
->addMatcher($plugin
->getConfiguration());
$profile
->save();
// Try delete a matcher that is not attached to the profile.
$this
->drupalGet(Url::fromRoute('linkit.matcher.delete', [
'linkit_profile' => $profile
->id(),
'plugin_instance_id' => 'doesntexists',
]));
$this
->assertResponse('404');
// Go to the delete page, but press cancel.
$this
->drupalGet(Url::fromRoute('linkit.matcher.delete', [
'linkit_profile' => $profile
->id(),
'plugin_instance_id' => $plugin_uuid,
]));
$this
->clickLink(t('Cancel'));
$this
->assertUrl(Url::fromRoute('linkit.matchers', [
'linkit_profile' => $profile
->id(),
]));
// Delete the matcher from the profile.
$this
->drupalGet(Url::fromRoute('linkit.matcher.delete', [
'linkit_profile' => $profile
->id(),
'plugin_instance_id' => $plugin_uuid,
]));
$this
->drupalPostForm(NULL, [], t('Confirm'));
$this
->assertRaw(t('The matcher %plugin has been deleted.', [
'%plugin' => $plugin
->getLabel(),
]));
$this
->assertUrl(Url::fromRoute('linkit.matchers', [
'linkit_profile' => $profile
->id(),
]));
$this
->assertText(t('No matchers added.'));
/** @var \Drupal\linkit\Entity\Profile $updated_profile */
$updated_profile = Profile::load($profile
->id());
$this
->assertFalse($updated_profile
->getMatchers()
->has($plugin_uuid), 'The user matcher is deleted from the profile');
}