linkit_profile.test 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. /**
  3. * @file
  4. * Tests for Linkit module.
  5. */
  6. /**
  7. * Tests Linkit profile UI CRUD.
  8. */
  9. class LinkitProfileUICRUDTestCase extends LinkitTestCase {
  10. /**
  11. * Default profile values.
  12. */
  13. protected $profile_defaults = array(
  14. 'name' => 'test_profile',
  15. 'admin_title' => 'Test Profile',
  16. 'admin_description' => 'This is a description for the Test Profile.',
  17. );
  18. /**
  19. * Definition.
  20. */
  21. public static function getInfo() {
  22. return array(
  23. 'name' => 'Linkit Profile',
  24. 'description' => 'Test that a Linkit profile can be created/read(load)/updated/deleted.',
  25. 'group' => 'Linkit'
  26. );
  27. }
  28. function setUp($extra_modules = array()) {
  29. parent::setUp($extra_modules);
  30. $this->profile_defaults['profile_type'] = LINKIT_PROFILE_TYPE_EDITOR;
  31. }
  32. /**
  33. * Create a profile.
  34. */
  35. public function testCreateProfile() {
  36. // Create a user and login.
  37. $this->account = $this->drupalCreateUser($this->admin_permissions);
  38. $this->drupalLogin($this->account);
  39. // Save the profile.
  40. $this->drupalPost('admin/config/content/linkit/add', $this->profile_defaults, t('Save'));
  41. $this->assertRaw(t('!title has been created.', array('!title' => $this->profile_defaults['name'])), 'The new profile was created.');
  42. // Go to the edit page.
  43. $this->drupalGet('admin/config/content/linkit/list/' . $this->profile_defaults['name'] . '/edit');
  44. $this->assertResponse(200);
  45. // Test that the given values are saved.
  46. foreach ($this->profile_defaults as $form_key => $value) {
  47. $this->assertFieldByName($form_key, $value);
  48. }
  49. }
  50. /**
  51. * Update a profile.
  52. */
  53. public function testUpdateProfile() {
  54. // Create a user and login.
  55. $this->account = $this->drupalCreateUser($this->admin_permissions);
  56. $this->drupalLogin($this->account);
  57. // Create a profile.
  58. $this->createProfile(array(
  59. 'data' => array(
  60. 'autocomplete' => array(
  61. 'charLimit' => LINKIT_CHAR_LIMIT,
  62. 'wait' => LINKIT_WAIT,
  63. 'remoteTimeout' => LINKIT_REMOTE_TIMEOUT,
  64. ),
  65. ),
  66. ));
  67. // Go to the edit page.
  68. $this->drupalGet('admin/config/content/linkit/list/' . $this->_profile->name . '/edit');
  69. $this->assertResponse(200);
  70. $profile_update = array(
  71. 'admin_title' => 'Test Profile updated',
  72. 'admin_description' => 'This is a updated description for the Test Profile updated.',
  73. 'data[autocomplete][charLimit]' => 4,
  74. 'data[autocomplete][wait]' => 3500,
  75. 'data[autocomplete][remoteTimeout]' => 1000,
  76. );
  77. // Set some new values for the profile.
  78. $this->drupalPost(NULL, $profile_update, t('Save'));
  79. // Go to the edit page again.
  80. $this->drupalGet('admin/config/content/linkit/list/' . $this->_profile->name . '/edit');
  81. $this->assertResponse(200);
  82. // Test that the given values are saved.
  83. foreach ($profile_update as $form_key => $value) {
  84. $this->assertFieldByName($form_key, $value);
  85. }
  86. }
  87. /**
  88. * Delete a profile.
  89. */
  90. public function testDeleteProfile() {
  91. // Create a user and login.
  92. $this->account = $this->drupalCreateUser($this->admin_permissions);
  93. $this->drupalLogin($this->account);
  94. // Create a profile that we will delete.
  95. $this->createProfile();
  96. // Delete the created profile.
  97. $this->drupalPost('/admin/config/content/linkit/list/' . $this->_profile->name . '/delete', array(), t('Delete'));
  98. $this->assertRaw(t('The item has been deleted.'), 'The profile was deleted.');
  99. }
  100. /**
  101. * Load a profile that doesn't exists.
  102. */
  103. public function testLoadNonExistingProfile() {
  104. // Load a profile that doesn't exists.
  105. $loaded_profile = linkit_profile_load('my_none_existing_profile');
  106. $this->assertFalse($loaded_profile, 'FALSE is returned when loading a non existing profile.');
  107. }
  108. /**
  109. * Load a profile that exists.
  110. */
  111. public function testLoadProfile() {
  112. // Create an user account so we can create a profile.
  113. $this->account = $this->drupalCreateUser($this->admin_permissions);
  114. $this->drupalLogin($this->account);
  115. // Create a profile that we will load.
  116. $this->createProfile();
  117. // Load the saved profile.
  118. $loaded_profile = linkit_profile_load($this->_profile->name);
  119. $this->assertTrue($loaded_profile, 'Profile was successfully loaded.');
  120. }
  121. /**
  122. * Load all profiles when no profiles exists.
  123. */
  124. public function testLoadProfilesNoProfilesExists() {
  125. // We have to clear the static variables here as we have in the
  126. // testLoadProfilesNoProfilesExists test function asked for profiles where
  127. // there were no profiles.
  128. drupal_static_reset('ctools_export_load_object');
  129. drupal_static_reset('ctools_export_load_object_all');
  130. // Load all profiles.
  131. $loaded_profile = linkit_profile_load_all();
  132. $this->assertIdentical($loaded_profile, array(), 'Empty array is returned when loading all profiles and there are no profiles.');
  133. }
  134. /**
  135. * Load all profiles.
  136. */
  137. public function testLoadAllProfiles() {
  138. // Create an user account so we can create profiles.
  139. $this->account = $this->drupalCreateUser($this->admin_permissions);
  140. $this->drupalLogin($this->account);
  141. // Create profiles that we will load.
  142. $this->createProfile(array('name' => 'test_1'));
  143. $this->createProfile(array('name' => 'test_2'));
  144. $this->createProfile(array('name' => 'test_3'));
  145. // We have to clear the static variables here as we have in the
  146. // testLoadProfilesNoProfilesExists test function asked for profiles where
  147. // there were no profiles.
  148. drupal_static_reset('ctools_export_load_object');
  149. drupal_static_reset('ctools_export_load_object_all');
  150. // Load all profiles.
  151. $loaded_profiles = linkit_profile_load_all();
  152. $this->assertEqual(count($loaded_profiles), 3, 'All profile were successfully loaded.');
  153. }
  154. }