linkit_search_plugin_user.test 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * @file
  4. * Tests for Linkit search plugin user.
  5. */
  6. /**
  7. * Test the the user search plugin.
  8. */
  9. class LinkitsearchPluginUserTestCase extends LinkitsearchPluginTestCase {
  10. /**
  11. * Definition.
  12. */
  13. public static function getInfo() {
  14. return array(
  15. 'name' => 'Linkit Search plugin (User)',
  16. 'description' => 'Test the the user search plugin.',
  17. 'group' => 'Linkit'
  18. );
  19. }
  20. function setUp($extra_modules = array()) {
  21. parent::setUp($extra_modules);
  22. // Create a basic profile.
  23. $this->createProfile(array(
  24. 'data' => array(
  25. 'search_plugins' => array(
  26. 'entity:user' => array(
  27. 'enabled' => 1,
  28. 'weight' => 0,
  29. ),
  30. ),
  31. 'entity:user' => array(
  32. 'result_description' => '',
  33. ),
  34. 'insert_plugin' => array(
  35. 'url_method' => LINKIT_URL_METHOD_RAW,
  36. ),
  37. )
  38. ));
  39. // Users need the 'access user profiles' permission to search for users.
  40. $this->account = $this->drupalCreateUser(array('access user profiles'));
  41. $this->drupalLogin($this->account);
  42. }
  43. /**
  44. * Create a user.
  45. *
  46. * We can't use drupalCreateUser() as we want to set specific usernames.
  47. */
  48. protected function createUser($extra = array()) {
  49. // Create a user assigned to that role.
  50. $edit = array();
  51. $edit += $extra;
  52. if (!isset($edit['name'])) {
  53. $edit['name'] = $this->randomName();
  54. }
  55. $edit['mail'] = $edit['name'] . '@example.com';
  56. $edit['pass'] = user_password();
  57. $edit['status'] = 1;
  58. $account = user_save(drupal_anonymous_user(), $edit);
  59. $this->assertTrue(!empty($account->uid), t('User created with name %name and pass %pass', array('%name' => $edit['name'], '%pass' => $edit['pass'])), t('User login'));
  60. if (empty($account->uid)) {
  61. return FALSE;
  62. }
  63. // Add the raw password so that we can log in as this user.
  64. $account->pass_raw = $edit['pass'];
  65. return $account;
  66. }
  67. /**
  68. * Test that we get results back which is valid.
  69. */
  70. public function testBasicResults() {
  71. // We don't use the drupalCreateUser() as we want to set specific usernames.
  72. $user_1 = $this->createUser(array('name' => $this->search_string . $this->randomName()));
  73. $user_2 = $this->createUser(array('name' => $this->search_string . $this->randomName()));
  74. $user_3 = $this->createUser(array('name' => $this->search_string . $this->randomName()));
  75. // Call the autocomplete helper method.
  76. $this->autocompleteCall();
  77. // Check that the usernames appears in the response.
  78. $this->assertRaw($user_1->name, 'Username was found in the result array.');
  79. $this->assertRaw($user_2->name, 'Username was found in the result array.');
  80. $this->assertRaw($user_3->name, 'Username was found in the result array.');
  81. }
  82. /**
  83. * Test result description.
  84. *
  85. * We just test one token.
  86. */
  87. public function testDescription() {
  88. // We don't use the drupalCreateUser() as we want to set specific usernames.
  89. $user_1 = $this->createUser(array('name' => $this->search_string . $this->randomName()));
  90. $user_2 = $this->createUser(array('name' => $this->search_string . $this->randomName()));
  91. // Update the profile with a user result description.
  92. $this->_profile->data['entity:user']['result_description'] = 'Created [user:created:raw]';
  93. $this->updateProfile();
  94. // Call the autocomplete helper method.
  95. $this->autocompleteCall();
  96. // Check that the result description appers in the result.
  97. $this->assertRaw('Created ' . $user_1->created, 'The result description was found in the result array.');
  98. $this->assertRaw('Created ' . $user_2->created, 'The result description was found in the result array.');
  99. }
  100. }