Esempio n. 1
0
  /**
   * Creates a profile based on default settings.
   *
   * @param array $settings
   *   (optional) An associative array of settings for the profile, as used in
   *   entity_create(). Override the defaults by specifying the key and value
   *   in the array
   *
   *   The following defaults are provided:
   *   - label: Random string.
   *
   * @return \Drupal\linkit\ProfileInterface
   *   The created profile entity.
   */
  protected function createProfile(array $settings = []) {
    // Populate defaults array.
    $settings += [
      'id' => Unicode::strtolower($this->randomMachineName()),
      'label' => $this->randomMachineName(),
    ];

    $profile = Profile::create($settings);
    $profile->save();

    return $profile;
  }
Esempio n. 2
0
  /**
   * Test delete a matcher from a profile.
   */
  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');
  }