linkit.test 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * @file
  4. * Tests for Linkit module.
  5. */
  6. /**
  7. * Abstract class for Linkit testing.
  8. */
  9. //abstract class LinkitTestCase extends SimpleTestCloneTestCase {
  10. abstract class LinkitTestCase extends DrupalWebTestCase {
  11. /**
  12. * Permissions to apply to administers.
  13. *
  14. * @var array
  15. */
  16. public $admin_permissions = array(
  17. 'administer linkit',
  18. );
  19. /**
  20. * A user object.
  21. *
  22. * @var object
  23. */
  24. public $account;
  25. /**
  26. * A Linkit profile object.
  27. *
  28. * @var LinkitProfile object
  29. */
  30. public $_profile;
  31. function setUp($extra_modules = array()) {
  32. $modules = array('ctools', 'entity', 'linkit');
  33. $modules += $extra_modules;
  34. parent::setUp($modules);
  35. }
  36. /**
  37. * Helper function: Create a Linkit profile.
  38. */
  39. protected function createProfile($extra = array()) {
  40. ctools_include('export');
  41. $profile = ctools_export_crud_new('linkit_profiles');
  42. $profile->name = isset($extra['name']) ? $extra['name'] : 'test_profile';
  43. $profile->admin_title = isset($extra['admin_title']) ? $extra['admin_title'] : 'Test Profile';
  44. $profile->admin_description = isset($extra['admin_description']) ? $extra['admin_description'] : 'This is a description for the Test Profile.';
  45. $profile->data = array();
  46. if (isset($extra['data'])) {
  47. $profile->data += $extra['data'];
  48. }
  49. if (empty($profile->data['profile_type'])) {
  50. $profile->profile_type = LINKIT_PROFILE_TYPE_EDITOR;
  51. }
  52. if (!isset($profile->data['insert_plugin']) && $profile->profile_type == LINKIT_PROFILE_TYPE_FIELD) {
  53. $profile->data['insert_plugin'] = array(
  54. 'plugin' => 'raw_url',
  55. 'url_method' => LINKIT_URL_METHOD_RAW,
  56. );
  57. }
  58. // Save the profile.
  59. ctools_export_crud_save('linkit_profiles', $profile);
  60. // Load and return the saved profile.
  61. $this->_profile = linkit_profile_load($profile->name);
  62. }
  63. /**
  64. * Helper function: Update a Linkit profile.
  65. */
  66. protected function updateProfile() {
  67. ctools_include('export');
  68. // Save the changes to the profile.
  69. ctools_export_crud_save('linkit_profiles', $this->_profile);
  70. // Load the saved profile.
  71. $this->_profile = linkit_profile_load($this->_profile->name);
  72. }
  73. /**
  74. * Helper method to process the autocomplete call.
  75. */
  76. protected function autocompleteCall() {
  77. // Call the autocomplete.
  78. $path = 'linkit/autocomplete/' . $this->_profile->name;
  79. $response = $this->drupalGetAJAX($path, array('query' => array(LINKIT_BAC_QUERY_KEY => $this->search_string)));
  80. $this->assertResponse(200);
  81. $this->assertNotNull($response, 'The JSON respone is seems to be ok.');
  82. return $response;
  83. }
  84. }