示例#1
0
  /**
   * Tests term matcher with bundle filer.
   */
  function testTermMatcherWidthBundleFiler() {
    /** @var \Drupal\linkit\MatcherInterface $plugin */
    $plugin = $this->manager->createInstance('entity:taxonomy_term', [
      'settings' => [
        'bundles' => [
          'testing_vocabulary_1' => 'testing_vocabulary_1'
        ],
      ],
    ]);

    $matches = $plugin->getMatches('foo');
    $this->assertEqual(3, count($matches), 'Correct number of matches');
  }
示例#2
0
  /**
   * Builds the table rows.
   *
   * @return array
   *   An array of table rows.
   */
  private function buildRows() {
    $rows = [];
    $all_plugins = $this->manager->getDefinitions();
    uasort($all_plugins, function ($a, $b) {
      return strnatcasecmp($a['label'], $b['label']);
    });
    foreach ($all_plugins as $definition) {
      /** @var \Drupal\linkit\MatcherInterface $plugin */
      $plugin = $this->manager->createInstance($definition['id']);
      $row = [
        'label' => $plugin->getLabel(),
      ];
      $rows[$plugin->getPluginId()] = $row;
    }

    return $rows;
  }
示例#3
0
  /**
   * Tests node matcher with include unpublished setting activated.
   */
  function testNodeMatcherWidthIncludeUnpublished() {
    /** @var \Drupal\linkit\MatcherInterface $plugin */
    $plugin = $this->manager->createInstance('entity:node', [
      'settings' => [
        'include_unpublished' => TRUE,
      ],
    ]);

    // Test without permissions to see unpublished nodes.
    $matches = $plugin->getMatches('Lorem');
    $this->assertEqual(3, count($matches), 'Correct number of matches');

    $account = $this->drupalCreateUser(['bypass node access']);
    $this->drupalLogin($account);

    // Test with permissions to see unpublished nodes.
    $matches = $plugin->getMatches('Lorem');
    $this->assertEqual(4, count($matches), 'Correct number of matches');
  }
示例#4
0
  /**
   * Tests user matcher with include blocked setting activated.
   */
  function testUserMatcherWidthIncludeBlocked() {
    /** @var \Drupal\linkit\MatcherInterface $plugin */
    $plugin = $this->manager->createInstance('entity:user', [
      'settings' => [
        'include_blocked' => TRUE,
      ],
    ]);

    // Test without permissions to see blocked users.
    $matches = $plugin->getMatches('blocked');
    $this->assertEqual(0, count($matches), 'Correct number of matches');

    $account = $this->drupalCreateUser(['administer users']);
    $this->drupalLogin($account);

    // Test with permissions to see blocked users.
    $matches = $plugin->getMatches('blocked');
    $this->assertEqual(1, count($matches), 'Correct number of matches');
  }
示例#5
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');
  }