initial commit of starter install drupal 7
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Tests for Linkit module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract class for Linkit testing.
|
||||
*/
|
||||
//abstract class LinkitTestCase extends SimpleTestCloneTestCase {
|
||||
abstract class LinkitTestCase extends DrupalWebTestCase {
|
||||
|
||||
/**
|
||||
* Permissions to apply to administers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $admin_permissions = array(
|
||||
'administer linkit',
|
||||
);
|
||||
|
||||
/**
|
||||
* A user object.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $account;
|
||||
|
||||
/**
|
||||
* A Linkit profile object.
|
||||
*
|
||||
* @var LinkitProfile object
|
||||
*/
|
||||
public $_profile;
|
||||
|
||||
function setUp($extra_modules = array()) {
|
||||
$modules = array('ctools', 'entity', 'linkit');
|
||||
$modules += $extra_modules;
|
||||
parent::setUp($modules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function: Create a Linkit profile.
|
||||
*/
|
||||
protected function createProfile($extra = array()) {
|
||||
ctools_include('export');
|
||||
$profile = ctools_export_crud_new('linkit_profiles');
|
||||
|
||||
$profile->name = isset($extra['name']) ? $extra['name'] : 'test_profile';
|
||||
$profile->admin_title = isset($extra['admin_title']) ? $extra['admin_title'] : 'Test Profile';
|
||||
$profile->admin_description = isset($extra['admin_description']) ? $extra['admin_description'] : 'This is a description for the Test Profile.';
|
||||
$profile->data = array();
|
||||
|
||||
if (isset($extra['data'])) {
|
||||
$profile->data += $extra['data'];
|
||||
}
|
||||
|
||||
if (empty($profile->data['profile_type'])) {
|
||||
$profile->profile_type = LINKIT_PROFILE_TYPE_EDITOR;
|
||||
}
|
||||
|
||||
if (!isset($profile->data['insert_plugin']) && $profile->profile_type == LINKIT_PROFILE_TYPE_FIELD) {
|
||||
$profile->data['insert_plugin'] = array(
|
||||
'plugin' => 'raw_url',
|
||||
'url_method' => LINKIT_URL_METHOD_RAW,
|
||||
);
|
||||
}
|
||||
|
||||
// Save the profile.
|
||||
ctools_export_crud_save('linkit_profiles', $profile);
|
||||
|
||||
// Load and return the saved profile.
|
||||
$this->_profile = linkit_profile_load($profile->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function: Update a Linkit profile.
|
||||
*/
|
||||
protected function updateProfile() {
|
||||
ctools_include('export');
|
||||
|
||||
// Save the changes to the profile.
|
||||
ctools_export_crud_save('linkit_profiles', $this->_profile);
|
||||
|
||||
// Load the saved profile.
|
||||
$this->_profile = linkit_profile_load($this->_profile->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to process the autocomplete call.
|
||||
*/
|
||||
protected function autocompleteCall() {
|
||||
// Call the autocomplete.
|
||||
$path = 'linkit/autocomplete/' . $this->_profile->name;
|
||||
$response = $this->drupalGetAJAX($path, array('query' => array(LINKIT_BAC_QUERY_KEY => $this->search_string)));
|
||||
$this->assertResponse(200);
|
||||
|
||||
$this->assertNotNull($response, 'The JSON respone is seems to be ok.');
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Tests for Linkit module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests Linkit profile UI CRUD.
|
||||
*/
|
||||
class LinkitProfileUICRUDTestCase extends LinkitTestCase {
|
||||
|
||||
/**
|
||||
* Default profile values.
|
||||
*/
|
||||
protected $profile_defaults = array(
|
||||
'name' => 'test_profile',
|
||||
'admin_title' => 'Test Profile',
|
||||
'admin_description' => 'This is a description for the Test Profile.',
|
||||
'profile_type' => LINKIT_PROFILE_TYPE_EDITOR,
|
||||
);
|
||||
|
||||
/**
|
||||
* Definition.
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Linkit Profile',
|
||||
'description' => 'Test that a Linkit profile can be created/read(load)/updated/deleted.',
|
||||
'group' => 'Linkit'
|
||||
);
|
||||
}
|
||||
|
||||
function setUp($extra_modules = array()) {
|
||||
parent::setUp($extra_modules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a profile.
|
||||
*/
|
||||
public function testCreateProfile() {
|
||||
// Create a user and login.
|
||||
$this->account = $this->drupalCreateUser($this->admin_permissions);
|
||||
$this->drupalLogin($this->account);
|
||||
|
||||
// Save the profile.
|
||||
$this->drupalPost('admin/config/content/linkit/add', $this->profile_defaults, t('Save'));
|
||||
|
||||
$this->assertRaw(t('!title has been created.', array('!title' => $this->profile_defaults['name'])), 'The new profile was created.');
|
||||
|
||||
// Go to the edit page.
|
||||
$this->drupalGet('admin/config/content/linkit/list/' . $this->profile_defaults['name'] . '/edit');
|
||||
$this->assertResponse(200);
|
||||
|
||||
// Test that the given values are saved.
|
||||
foreach ($this->profile_defaults as $form_key => $value) {
|
||||
$this->assertFieldByName($form_key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a profile.
|
||||
*/
|
||||
public function testUpdateProfile() {
|
||||
// Create a user and login.
|
||||
$this->account = $this->drupalCreateUser($this->admin_permissions);
|
||||
$this->drupalLogin($this->account);
|
||||
|
||||
// Create a profile.
|
||||
$this->createProfile(array(
|
||||
'data' => array(
|
||||
'autocomplete' => array(
|
||||
'charLimit' => LINKIT_CHAR_LIMIT,
|
||||
'wait' => LINKIT_WAIT,
|
||||
'remoteTimeout' => LINKIT_REMOTE_TIMEOUT,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
// Go to the edit page.
|
||||
$this->drupalGet('admin/config/content/linkit/list/' . $this->_profile->name . '/edit');
|
||||
$this->assertResponse(200);
|
||||
|
||||
$profile_update = array(
|
||||
'admin_title' => 'Test Profile updated',
|
||||
'admin_description' => 'This is a updated description for the Test Profile updated.',
|
||||
'data[autocomplete][charLimit]' => 4,
|
||||
'data[autocomplete][wait]' => 3500,
|
||||
'data[autocomplete][remoteTimeout]' => 1000,
|
||||
);
|
||||
// Set some new values for the profile.
|
||||
$this->drupalPost(NULL, $profile_update, t('Save'));
|
||||
|
||||
// Go to the edit page again.
|
||||
$this->drupalGet('admin/config/content/linkit/list/' . $this->_profile->name . '/edit');
|
||||
$this->assertResponse(200);
|
||||
|
||||
// Test that the given values are saved.
|
||||
foreach ($profile_update as $form_key => $value) {
|
||||
$this->assertFieldByName($form_key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a profile.
|
||||
*/
|
||||
public function testDeleteProfile() {
|
||||
// Create a user and login.
|
||||
$this->account = $this->drupalCreateUser($this->admin_permissions);
|
||||
$this->drupalLogin($this->account);
|
||||
|
||||
// Create a profile that we will delete.
|
||||
$this->createProfile();
|
||||
|
||||
// Delete the created profile.
|
||||
$this->drupalPost('/admin/config/content/linkit/list/' . $this->_profile->name . '/delete', array(), t('Delete'));
|
||||
|
||||
$this->assertRaw(t('The item has been deleted.'), 'The profile was deleted.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a profile that doesn't exists.
|
||||
*/
|
||||
public function testLoadNonExistingProfile() {
|
||||
// Load a profile that doesn't exists.
|
||||
$loaded_profile = linkit_profile_load('my_none_existing_profile');
|
||||
|
||||
$this->assertFalse($loaded_profile, 'FALSE is returned when loading a non existing profile.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a profile that exists.
|
||||
*/
|
||||
public function testLoadProfile() {
|
||||
// Create an user account so we can create a profile.
|
||||
$this->account = $this->drupalCreateUser($this->admin_permissions);
|
||||
$this->drupalLogin($this->account);
|
||||
|
||||
// Create a profile that we will load.
|
||||
$this->createProfile();
|
||||
|
||||
// Load the saved profile.
|
||||
$loaded_profile = linkit_profile_load($this->_profile->name);
|
||||
|
||||
$this->assertTrue($loaded_profile, 'Profile was successfully loaded.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all profiles when no profiles exists.
|
||||
*/
|
||||
public function testLoadProfilesNoProfilesExists() {
|
||||
// We have to clear the static variables here as we have in the
|
||||
// testLoadProfilesNoProfilesExists test function asked for profiles where
|
||||
// there were no profiles.
|
||||
drupal_static_reset('ctools_export_load_object');
|
||||
drupal_static_reset('ctools_export_load_object_all');
|
||||
|
||||
// Load all profiles.
|
||||
$loaded_profile = linkit_profile_load_all();
|
||||
$this->assertIdentical($loaded_profile, array(), 'Empty array is returned when loading all profiles and there are no profiles.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all profiles.
|
||||
*/
|
||||
public function testLoadAllProfiles() {
|
||||
// Create an user account so we can create profiles.
|
||||
$this->account = $this->drupalCreateUser($this->admin_permissions);
|
||||
$this->drupalLogin($this->account);
|
||||
|
||||
// Create profiles that we will load.
|
||||
$this->createProfile(array('name' => 'test_1'));
|
||||
$this->createProfile(array('name' => 'test_2'));
|
||||
$this->createProfile(array('name' => 'test_3'));
|
||||
|
||||
// We have to clear the static variables here as we have in the
|
||||
// testLoadProfilesNoProfilesExists test function asked for profiles where
|
||||
// there were no profiles.
|
||||
drupal_static_reset('ctools_export_load_object');
|
||||
drupal_static_reset('ctools_export_load_object_all');
|
||||
|
||||
// Load all profiles.
|
||||
$loaded_profiles = linkit_profile_load_all();
|
||||
$this->assertEqual(count($loaded_profiles), 3, 'All profile were successfully loaded.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Tests for Linkit module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Search plugin test helper class.
|
||||
*/
|
||||
abstract class LinkitsearchPluginTestCase extends LinkitTestCase {
|
||||
/**
|
||||
* The string to search for when doing autocomplete calls.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $search_string = 'lorem';
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Tests for Linkit search plugin node.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test the the node search plugin.
|
||||
*/
|
||||
class LinkitsearchPluginNodeTestCase extends LinkitsearchPluginTestCase {
|
||||
|
||||
/**
|
||||
* Definition.
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Linkit Search plugin (Node)',
|
||||
'description' => 'Test the the node search plugin.',
|
||||
'group' => 'Linkit'
|
||||
);
|
||||
}
|
||||
|
||||
function setUp($extra_modules = array()) {
|
||||
parent::setUp($extra_modules);
|
||||
|
||||
// Create a basic profile.
|
||||
$this->createProfile(array(
|
||||
'data' => array(
|
||||
'search_plugins' => array(
|
||||
'entity:node' => array(
|
||||
'enabled' => 1,
|
||||
'weight' => 0,
|
||||
),
|
||||
),
|
||||
'entity:node' => array(
|
||||
'result_description' => '',
|
||||
'bundles' => array(),
|
||||
'group_by_bundle' => 0,
|
||||
'include_unpublished' => 0,
|
||||
),
|
||||
'insert_plugin' => array(
|
||||
'url_method' => LINKIT_URL_METHOD_RAW,
|
||||
),
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that we get results back which is valid.
|
||||
*/
|
||||
public function testBasicResults() {
|
||||
// Create some nodes.
|
||||
$node_1 = $this->drupalCreateNode(array('type' => 'article', 'title' => $this->search_string . $this->randomName()));
|
||||
$node_2 = $this->drupalCreateNode(array('type' => 'article', 'title' => $this->search_string . $this->randomName()));
|
||||
$node_3 = $this->drupalCreateNode(array('type' => 'page', 'title' => $this->search_string . $this->randomName()));
|
||||
$node_4 = $this->drupalCreateNode(array('type' => 'page', 'title' => $this->search_string . $this->randomName()));
|
||||
|
||||
// Call the autocomplete helper method.
|
||||
$this->autocompleteCall();
|
||||
|
||||
// Assert that the node titles appears in the response.
|
||||
$this->assertRaw($node_1->title, 'Node was found in the result array.');
|
||||
$this->assertRaw($node_2->title, 'Node was found in the result array.');
|
||||
$this->assertRaw($node_3->title, 'Node was found in the result array.');
|
||||
$this->assertRaw($node_4->title, 'Node was found in the result array.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test how node states are handled.
|
||||
*/
|
||||
public function testUnpublishedItems() {
|
||||
// Create some nodes.
|
||||
$node_1 = $this->drupalCreateNode(array('type' => 'article', 'title' => $this->search_string . $this->randomName(), 'status' => NODE_NOT_PUBLISHED));
|
||||
$node_2 = $this->drupalCreateNode(array('type' => 'page', 'title' => $this->search_string . $this->randomName(), 'status' => NODE_NOT_PUBLISHED));
|
||||
|
||||
// Call the autocomplete helper method.
|
||||
$this->autocompleteCall();
|
||||
|
||||
// Assert that the unpublished node title doesn't appear in the response.
|
||||
$this->assertNoRaw($node_1->title, 'Unpublished node was not found in the result array.');
|
||||
$this->assertNoRaw($node_2->title, 'Unpublished node was not found in the result array.');
|
||||
|
||||
// Tell the profile to include unpublished nodes.
|
||||
$this->_profile->data['entity:node']['include_unpublished'] = 1;
|
||||
$this->updateProfile();
|
||||
|
||||
// In order to see unpublished nodes in the result, the user must also have
|
||||
// permission to see unpublished nodes.
|
||||
// We give the user 'bypass node access' permission as we don't crated the
|
||||
// nodes with this user.
|
||||
$this->account = $this->drupalCreateUser(array('bypass node access'));
|
||||
$this->drupalLogin($this->account);
|
||||
|
||||
// Call the autocomplete helper method.
|
||||
$this->autocompleteCall();
|
||||
|
||||
// Assert that the unpublished title appears in the response.
|
||||
$this->assertRaw($node_1->title, 'Unpublished node was found in the result array.');
|
||||
$this->assertRaw($node_2->title, 'Unpublished node was found in the result array.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test group by bundle.
|
||||
*
|
||||
* The actual grouping is made by the javascript later on.
|
||||
* We just test that the resons contains group info.
|
||||
*/
|
||||
public function testGroupbyBundle() {
|
||||
// Create some nodes.
|
||||
$node_1 = $this->drupalCreateNode(array('type' => 'article', 'title' => $this->search_string . $this->randomName()));
|
||||
$node_2 = $this->drupalCreateNode(array('type' => 'page', 'title' => $this->search_string . $this->randomName()));
|
||||
|
||||
// Get the bundle names.
|
||||
$node_type_name_1 = node_type_get_name($node_1);
|
||||
$node_type_name_2 = node_type_get_name($node_2);
|
||||
|
||||
// Update the profile to group by bundle.
|
||||
$this->_profile->data['entity:node']['group_by_bundle'] = 1;
|
||||
$this->updateProfile();
|
||||
|
||||
// Call the autocomplete helper method.
|
||||
$this->autocompleteCall();
|
||||
|
||||
// Assert that the bundle title appear in the response.
|
||||
$this->assertRaw('"group":"Node - ' . $node_type_name_1, 'Bundle name in group was found in the result array.');
|
||||
$this->assertRaw('"group":"Node - ' . $node_type_name_2, 'Bundle name in group was found in the result array.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test bundle filter.
|
||||
*/
|
||||
public function testBundleFilter() {
|
||||
// Create some nodes.
|
||||
$node_1 = $this->drupalCreateNode(array('type' => 'article', 'title' => $this->search_string . $this->randomName()));
|
||||
$node_2 = $this->drupalCreateNode(array('type' => 'page', 'title' => $this->search_string . $this->randomName()));
|
||||
|
||||
// Update the profile to filter by bundle.
|
||||
$this->_profile->data['entity:node']['bundles'] = array(
|
||||
'article' => 'article',
|
||||
);
|
||||
$this->updateProfile();
|
||||
|
||||
// Call the autocomplete helper method.
|
||||
$res = $this->autocompleteCall();
|
||||
|
||||
// Assert that the node title from the bundle included in the filter appear in the response.
|
||||
$this->assertRaw($node_1->title, 'Node that is included in the filter was found in the result array.');
|
||||
|
||||
// Assert that the node title from the bundle that is not included in the filter doesnät appear in the response.
|
||||
$this->assertNoRaw($node_2->title, 'Node that is not included in the filter was not found in the result array.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test result description.
|
||||
*
|
||||
* We just test one token.
|
||||
*/
|
||||
public function testDescription() {
|
||||
// Create some nodes.
|
||||
$node_1 = $this->drupalCreateNode(array('type' => 'article', 'title' => $this->search_string . $this->randomName()));
|
||||
$node_2 = $this->drupalCreateNode(array('type' => 'page', 'title' => $this->search_string . $this->randomName()));
|
||||
|
||||
// Update the profile with a user result description.
|
||||
$this->_profile->data['entity:node']['result_description'] = 'Created [node:created:raw]';
|
||||
$this->updateProfile();
|
||||
|
||||
// Call the autocomplete helper method.
|
||||
$this->autocompleteCall();
|
||||
|
||||
// Check that the result description appers in the result.
|
||||
$this->assertRaw('Created ' . $node_1->created, 'The result description was found in the result array.');
|
||||
$this->assertRaw('Created ' . $node_2->created, 'The result description was found in the result array.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Tests for Linkit search plugin taxonomy term.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test the the taxonomy term search plugin.
|
||||
*/
|
||||
class LinkitsearchPluginTaxonomyTermTestCase extends LinkitsearchPluginTestCase {
|
||||
|
||||
/**
|
||||
* Definition.
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Linkit Search plugin (Taxonomy term)',
|
||||
'description' => 'Test the the taxonomy term search plugin.',
|
||||
'group' => 'Linkit'
|
||||
);
|
||||
}
|
||||
|
||||
function setUp($extra_modules = array()) {
|
||||
parent::setUp(array('taxonomy'));
|
||||
|
||||
// Create a basic profile.
|
||||
$this->createProfile(array(
|
||||
'data' => array(
|
||||
'search_plugins' => array(
|
||||
'entity:taxonomy_term' => array(
|
||||
'enabled' => 1,
|
||||
'weight' => 0,
|
||||
),
|
||||
),
|
||||
'entity:taxonomy_term' => array(
|
||||
'result_description' => '',
|
||||
'bundles' => array(),
|
||||
'group_by_bundle' => 0,
|
||||
),
|
||||
'insert_plugin' => array(
|
||||
'url_method' => LINKIT_URL_METHOD_RAW,
|
||||
),
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and returns a new vocabulary.
|
||||
*/
|
||||
function createVocabulary() {
|
||||
// Create a vocabulary.
|
||||
$vocabulary = new stdClass();
|
||||
$vocabulary->name = $this->randomName();
|
||||
$vocabulary->description = $this->randomName();
|
||||
$vocabulary->machine_name = drupal_strtolower($this->randomName());
|
||||
$vocabulary->help = '';
|
||||
$vocabulary->nodes = array('article' => 'article');
|
||||
$vocabulary->weight = mt_rand(0, 10);
|
||||
taxonomy_vocabulary_save($vocabulary);
|
||||
return $vocabulary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and returns a new term in vocabulary $vid.
|
||||
*/
|
||||
function createTerm($vocabulary) {
|
||||
$term = new stdClass();
|
||||
$term->name = $this->search_string . $this->randomName();
|
||||
$term->description = $this->randomName();
|
||||
// Use the first available text format.
|
||||
$term->format = 'plain_text';
|
||||
$term->vid = $vocabulary->vid;
|
||||
taxonomy_term_save($term);
|
||||
return $term;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that we get results back which is valid.
|
||||
*/
|
||||
public function testBasicResults() {
|
||||
// Create demo vocabulary.
|
||||
$vocabulary = $this->createVocabulary();
|
||||
|
||||
// Create demo terms.
|
||||
$term_1 = $this->createTerm($vocabulary);
|
||||
$term_2 = $this->createTerm($vocabulary);
|
||||
$term_3 = $this->createTerm($vocabulary);
|
||||
|
||||
// Call the autocomplete helper method.
|
||||
$this->autocompleteCall();
|
||||
|
||||
// Check that the term names appears in the response.
|
||||
$this->assertRaw($term_1->name, 'Term was found in the result array.');
|
||||
$this->assertRaw($term_2->name, 'Term was found in the result array.');
|
||||
$this->assertRaw($term_3->name, 'Term was found in the result array.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test group by bundle.
|
||||
*
|
||||
* The actual grouping is made by the javascript later on.
|
||||
* We just test that the resons contains group info.
|
||||
*/
|
||||
public function testGroupbyBundle() {
|
||||
// Create demo vocabulary.
|
||||
$vocabulary_1 = $this->createVocabulary();
|
||||
$vocabulary_2 = $this->createVocabulary();
|
||||
|
||||
// Create demo terms.
|
||||
$term_1 = $this->createTerm($vocabulary_1);
|
||||
$term_2 = $this->createTerm($vocabulary_1);
|
||||
$term_3 = $this->createTerm($vocabulary_2);
|
||||
$term_4 = $this->createTerm($vocabulary_2);
|
||||
|
||||
// Update the profile to group by bundle.
|
||||
$this->_profile->data['entity:taxonomy_term']['group_by_bundle'] = 1;
|
||||
$this->updateProfile();
|
||||
|
||||
// Call the autocomplete helper method.
|
||||
$this->autocompleteCall();
|
||||
|
||||
// Assert that the bundle title appear in the response.
|
||||
$this->assertRaw('"group":"Taxonomy term - ' . $vocabulary_1->name, 'Bundle name in group was found in the result array.');
|
||||
$this->assertRaw('"group":"Taxonomy term - ' . $vocabulary_1->name, 'Bundle name in group was found in the result array.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test bundle filter.
|
||||
*/
|
||||
public function testBundleFilter() {
|
||||
// Create demo vocabulary.
|
||||
$vocabulary_1 = $this->createVocabulary();
|
||||
$vocabulary_2 = $this->createVocabulary();
|
||||
|
||||
// Create demo terms.
|
||||
$term_1 = $this->createTerm($vocabulary_1);
|
||||
$term_2 = $this->createTerm($vocabulary_2);
|
||||
|
||||
// Update the profile to filter by bundle.
|
||||
$this->_profile->data['entity:taxonomy_term']['bundles'] = array(
|
||||
$vocabulary_1->machine_name => $vocabulary_1->machine_name,
|
||||
);
|
||||
$this->updateProfile();
|
||||
|
||||
// Call the autocomplete helper method.
|
||||
$this->autocompleteCall();
|
||||
|
||||
// Assert that the term title from the bundle included in the filter appear in the response.
|
||||
$this->assertRaw($term_1->name, 'Term that is included in the filter was found in the result array.');
|
||||
|
||||
// Assert that the term title from the bundle that is not included in the filter doesnät appear in the response.
|
||||
$this->assertNoRaw($term_2->name, 'Term that is not included in the filter was not found in the result array.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test result description.
|
||||
*
|
||||
* We just test one token.
|
||||
*/
|
||||
public function testDescription() {
|
||||
// Create demo vocabulary.
|
||||
$vocabulary_1 = $this->createVocabulary();
|
||||
$vocabulary_2 = $this->createVocabulary();
|
||||
|
||||
// Create demo terms.
|
||||
$term_1 = $this->createTerm($vocabulary_1);
|
||||
$term_2 = $this->createTerm($vocabulary_2);
|
||||
|
||||
// Update the profile with a taxonomy_term result description.
|
||||
$this->_profile->data['entity:taxonomy_term']['result_description'] = 'Term [term:vocabulary]';
|
||||
$this->updateProfile();
|
||||
|
||||
// Call the autocomplete helper method.
|
||||
$this->autocompleteCall();
|
||||
|
||||
// Check that the result description appers in the result.
|
||||
$this->assertRaw('Term ' . $vocabulary_1->name, 'The result description was found in the result array.');
|
||||
$this->assertRaw('Term ' . $vocabulary_2->name, 'The result description was found in the result array.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Tests for Linkit search plugin user.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test the the user search plugin.
|
||||
*/
|
||||
class LinkitsearchPluginUserTestCase extends LinkitsearchPluginTestCase {
|
||||
|
||||
/**
|
||||
* Definition.
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Linkit Search plugin (User)',
|
||||
'description' => 'Test the the user search plugin.',
|
||||
'group' => 'Linkit'
|
||||
);
|
||||
}
|
||||
|
||||
function setUp($extra_modules = array()) {
|
||||
parent::setUp($extra_modules);
|
||||
|
||||
// Create a basic profile.
|
||||
$this->createProfile(array(
|
||||
'data' => array(
|
||||
'search_plugins' => array(
|
||||
'entity:user' => array(
|
||||
'enabled' => 1,
|
||||
'weight' => 0,
|
||||
),
|
||||
),
|
||||
'entity:user' => array(
|
||||
'result_description' => '',
|
||||
),
|
||||
'insert_plugin' => array(
|
||||
'url_method' => LINKIT_URL_METHOD_RAW,
|
||||
),
|
||||
)
|
||||
));
|
||||
|
||||
// Users need the 'access user profiles' permission to search for users.
|
||||
$this->account = $this->drupalCreateUser(array('access user profiles'));
|
||||
$this->drupalLogin($this->account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a user.
|
||||
*
|
||||
* We can't use drupalCreateUser() as we want to set specific usernames.
|
||||
*/
|
||||
protected function createUser($extra = array()) {
|
||||
// Create a user assigned to that role.
|
||||
$edit = array();
|
||||
$edit += $extra;
|
||||
if (!isset($edit['name'])) {
|
||||
$edit['name'] = $this->randomName();
|
||||
}
|
||||
|
||||
$edit['mail'] = $edit['name'] . '@example.com';
|
||||
$edit['pass'] = user_password();
|
||||
$edit['status'] = 1;
|
||||
|
||||
$account = user_save(drupal_anonymous_user(), $edit);
|
||||
|
||||
$this->assertTrue(!empty($account->uid), t('User created with name %name and pass %pass', array('%name' => $edit['name'], '%pass' => $edit['pass'])), t('User login'));
|
||||
if (empty($account->uid)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Add the raw password so that we can log in as this user.
|
||||
$account->pass_raw = $edit['pass'];
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that we get results back which is valid.
|
||||
*/
|
||||
public function testBasicResults() {
|
||||
// We don't use the drupalCreateUser() as we want to set specific usernames.
|
||||
$user_1 = $this->createUser(array('name' => $this->search_string . $this->randomName()));
|
||||
$user_2 = $this->createUser(array('name' => $this->search_string . $this->randomName()));
|
||||
$user_3 = $this->createUser(array('name' => $this->search_string . $this->randomName()));
|
||||
|
||||
// Call the autocomplete helper method.
|
||||
$this->autocompleteCall();
|
||||
|
||||
// Check that the usernames appears in the response.
|
||||
$this->assertRaw($user_1->name, 'Username was found in the result array.');
|
||||
$this->assertRaw($user_2->name, 'Username was found in the result array.');
|
||||
$this->assertRaw($user_3->name, 'Username was found in the result array.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test result description.
|
||||
*
|
||||
* We just test one token.
|
||||
*/
|
||||
public function testDescription() {
|
||||
// We don't use the drupalCreateUser() as we want to set specific usernames.
|
||||
$user_1 = $this->createUser(array('name' => $this->search_string . $this->randomName()));
|
||||
$user_2 = $this->createUser(array('name' => $this->search_string . $this->randomName()));
|
||||
|
||||
// Update the profile with a user result description.
|
||||
$this->_profile->data['entity:user']['result_description'] = 'Created [user:created:raw]';
|
||||
$this->updateProfile();
|
||||
|
||||
// Call the autocomplete helper method.
|
||||
$this->autocompleteCall();
|
||||
|
||||
// Check that the result description appers in the result.
|
||||
$this->assertRaw('Created ' . $user_1->created, 'The result description was found in the result array.');
|
||||
$this->assertRaw('Created ' . $user_2->created, 'The result description was found in the result array.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user