views_upgrade.test

Definition of ViewsUpgradeTestCase.

File

tests/views_upgrade.test
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of ViewsUpgradeTestCase.
  5. */
  6. /**
  7. * Try to test the upgrade path of all conversions.
  8. *
  9. * You can find all conversions by searching for "moved to".
  10. */
  11. class ViewsUpgradeTestCase extends ViewsSqlTest {
  12. public static function getInfo() {
  13. return array(
  14. 'name' => 'Views Upgrade test',
  15. 'description' => 'Try to test the upgrade path of modules which were changed.',
  16. 'group' => 'Views',
  17. );
  18. }
  19. protected function setUp() {
  20. // // To import a view the user needs use PHP for settings rights, so enable php module.
  21. parent::setUp();
  22. module_enable(array('php'));
  23. $this->resetAll();
  24. }
  25. function viewsData() {
  26. $data = parent::viewsData();
  27. $data['views_test']['old_field_1']['moved to'] = array('views_test', 'id');
  28. $data['views_test']['old_field_2']['field']['moved to'] = array('views_test', 'name');
  29. $data['views_test']['old_field_3']['filter']['moved to'] = array('views_test', 'age');
  30. // @todo Test this scenario, too.
  31. $data['views_old_table_2']['old_field']['moved to'] = array('views_test', 'job');
  32. $data['views_old_table']['moved to'] = 'views_test';
  33. return $data;
  34. }
  35. function debugField($field) {
  36. $keys = array('id', 'table', 'field', 'actual_field', 'original_field', 'real_field');
  37. $info = array();
  38. foreach ($keys as $key) {
  39. $info[$key] = $field->{$key};
  40. }
  41. debug($info, NULL, TRUE);
  42. }
  43. /**
  44. * Tests the moved to parameter in general.
  45. */
  46. public function testMovedTo() {
  47. // Test moving on field lavel.
  48. $view = $this->viewsMovedToField();
  49. $view->update();
  50. $view->build();
  51. // $this->assertEqual('old_field_1', $view->field['old_field_1']->options['id'], "Id shouldn't change during conversion");
  52. // $this->assertEqual('id', $view->field['old_field_1']->field, 'The field should change during conversion');
  53. $this->assertEqual('id', $view->field['old_field_1']->real_field);
  54. $this->assertEqual('views_test', $view->field['old_field_1']->table);
  55. $this->assertEqual('old_field_1', $view->field['old_field_1']->original_field, 'The field should have stored the original_field');
  56. // Test moving on handler lavel.
  57. $view = $this->viewsMovedToHandler();
  58. $view->update();
  59. $view->build();
  60. // $this->assertEqual('old_field_2', $view->field['old_field_2']->options['id']);
  61. $this->assertEqual('name', $view->field['old_field_2']->real_field);
  62. $this->assertEqual('views_test', $view->field['old_field_2']->table);
  63. // $this->assertEqual('old_field_3', $view->filter['old_field_3']->options['id']);
  64. $this->assertEqual('age', $view->filter['old_field_3']->real_field);
  65. $this->assertEqual('views_test', $view->filter['old_field_3']->table);
  66. // Test moving on table level.
  67. $view = $this->viewsMovedToTable();
  68. $view->update();
  69. $view->build();
  70. $this->assertEqual('views_test', $view->base_table, 'Make sure that view->base_table gets automatically converted.');
  71. // $this->assertEqual('id', $view->field['id']->field, 'If we move a whole table fields of this table should work, too.');
  72. $this->assertEqual('id', $view->field['id']->real_field, 'To run the query right the real_field has to be set right.');
  73. $this->assertEqual('views_test', $view->field['id']->table);
  74. }
  75. /**
  76. * Tests a import via ui.
  77. *
  78. * To ensure the general functionality, the recent comments view from drupal6
  79. * is used.
  80. */
  81. public function testUpgradeImport() {
  82. $admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration', 'use PHP for settings'));
  83. $this->drupalLogin($admin_user);
  84. $edit = array(
  85. 'view' => $this->viewUpgradeImport(),
  86. );
  87. $this->drupalPost('admin/structure/views/import', $edit, t('Import'));
  88. $this->assertText('Recent comments');
  89. }
  90. public function viewsMovedToField() {
  91. $view = new view;
  92. $view->name = 'test_views_move_to_field';
  93. $view->description = '';
  94. $view->tag = '';
  95. $view->view_php = '';
  96. $view->base_table = 'views_test';
  97. $view->is_cacheable = FALSE;
  98. $view->api_version = 2;
  99. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  100. /* Display: Master */
  101. $handler = $view->new_display('default', 'Master', 'default');
  102. $handler->display->display_options['fields']['old_field_1']['id'] = 'old_field_1';
  103. $handler->display->display_options['fields']['old_field_1']['table'] = 'views_test';
  104. $handler->display->display_options['fields']['old_field_1']['field'] = 'old_field_1';
  105. return $view;
  106. }
  107. public function viewsMovedToHandler() {
  108. $view = new view;
  109. $view->name = 'test_views_move_to_handler';
  110. $view->description = '';
  111. $view->tag = '';
  112. $view->view_php = '';
  113. $view->base_table = 'views_test';
  114. $view->is_cacheable = FALSE;
  115. $view->api_version = 2;
  116. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  117. /* Display: Master */
  118. $handler = $view->new_display('default', 'Master', 'default');
  119. $handler->display->display_options['fields']['old_field_2']['id'] = 'old_field_2';
  120. $handler->display->display_options['fields']['old_field_2']['table'] = 'views_test';
  121. $handler->display->display_options['fields']['old_field_2']['field'] = 'old_field_2';
  122. $handler->display->display_options['filters']['old_field_3']['id'] = 'old_field_3';
  123. $handler->display->display_options['filters']['old_field_3']['table'] = 'views_test';
  124. $handler->display->display_options['filters']['old_field_3']['field'] = 'old_field_3';
  125. return $view;
  126. }
  127. public function viewsMovedToTable() {
  128. $view = new view;
  129. $view->name = 'test_views_move_to_table';
  130. $view->description = '';
  131. $view->tag = '';
  132. $view->view_php = '';
  133. $view->base_table = 'views_old_table';
  134. $view->is_cacheable = FALSE;
  135. $view->api_version = 2;
  136. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  137. /* Display: Master */
  138. $handler = $view->new_display('default', 'Master', 'default');
  139. $handler->display->display_options['fields']['id']['id'] = 'id';
  140. $handler->display->display_options['fields']['id']['table'] = 'views_old_table';
  141. $handler->display->display_options['fields']['id']['field'] = 'id';
  142. return $view;
  143. }
  144. protected function viewUpgradeImport() {
  145. $import = '
  146. $view = new view;
  147. $view->name = "comments_recent";
  148. $view->description = "Contains a block and a page to list recent comments; the block will automatically link to the page, which displays the comment body as well as a link to the node.";
  149. $view->tag = "default";
  150. $view->base_table = "comments";
  151. $view->human_name = "";
  152. $view->core = 0;
  153. $view->api_version = "3.0-alpha1";
  154. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  155. /* Display: Defaults */
  156. $handler = $view->new_display("default", "Defaults", "default");
  157. $handler->display->display_options["title"] = "Recent comments";
  158. $handler->display->display_options["use_more"] = TRUE;
  159. $handler->display->display_options["access"]["type"] = "none";
  160. $handler->display->display_options["cache"]["type"] = "none";
  161. $handler->display->display_options["query"]["type"] = "views_query";
  162. $handler->display->display_options["exposed_form"]["type"] = "basic";
  163. $handler->display->display_options["pager"]["type"] = "some";
  164. $handler->display->display_options["pager"]["options"]["items_per_page"] = 5;
  165. $handler->display->display_options["style_plugin"] = "list";
  166. $handler->display->display_options["row_plugin"] = "fields";
  167. /* Relationship: Comment: Node */
  168. $handler->display->display_options["relationships"]["nid"]["id"] = "nid";
  169. $handler->display->display_options["relationships"]["nid"]["table"] = "comments";
  170. $handler->display->display_options["relationships"]["nid"]["field"] = "nid";
  171. /* Field: Comment: Title */
  172. $handler->display->display_options["fields"]["subject"]["id"] = "subject";
  173. $handler->display->display_options["fields"]["subject"]["table"] = "comments";
  174. $handler->display->display_options["fields"]["subject"]["field"] = "subject";
  175. $handler->display->display_options["fields"]["subject"]["label"] = "";
  176. $handler->display->display_options["fields"]["subject"]["link_to_comment"] = 1;
  177. /* Field: Comment: Post date */
  178. $handler->display->display_options["fields"]["timestamp"]["id"] = "timestamp";
  179. $handler->display->display_options["fields"]["timestamp"]["table"] = "comments";
  180. $handler->display->display_options["fields"]["timestamp"]["field"] = "timestamp";
  181. $handler->display->display_options["fields"]["timestamp"]["label"] = "";
  182. $handler->display->display_options["fields"]["timestamp"]["date_format"] = "time ago";
  183. /* Sort criterion: Comment: Post date */
  184. $handler->display->display_options["sorts"]["timestamp"]["id"] = "timestamp";
  185. $handler->display->display_options["sorts"]["timestamp"]["table"] = "comments";
  186. $handler->display->display_options["sorts"]["timestamp"]["field"] = "timestamp";
  187. $handler->display->display_options["sorts"]["timestamp"]["order"] = "DESC";
  188. /* Filter: Node: Published or admin */
  189. $handler->display->display_options["filters"]["status_extra"]["id"] = "status_extra";
  190. $handler->display->display_options["filters"]["status_extra"]["table"] = "node";
  191. $handler->display->display_options["filters"]["status_extra"]["field"] = "status_extra";
  192. $handler->display->display_options["filters"]["status_extra"]["relationship"] = "nid";
  193. $handler->display->display_options["filters"]["status_extra"]["group"] = 0;
  194. $handler->display->display_options["filters"]["status_extra"]["expose"]["operator"] = FALSE;
  195. /* Display: Page */
  196. $handler = $view->new_display("page", "Page", "page");
  197. $handler->display->display_options["defaults"]["items_per_page"] = FALSE;
  198. $handler->display->display_options["defaults"]["style_plugin"] = FALSE;
  199. $handler->display->display_options["style_plugin"] = "list";
  200. $handler->display->display_options["defaults"]["style_options"] = FALSE;
  201. $handler->display->display_options["defaults"]["row_plugin"] = FALSE;
  202. $handler->display->display_options["row_plugin"] = "fields";
  203. $handler->display->display_options["row_options"]["inline"] = array(
  204. "title" => "title",
  205. "timestamp" => "timestamp",
  206. );
  207. $handler->display->display_options["row_options"]["separator"] = "&nbsp;";
  208. $handler->display->display_options["defaults"]["row_options"] = FALSE;
  209. $handler->display->display_options["defaults"]["fields"] = FALSE;
  210. /* Field: Node: Title */
  211. $handler->display->display_options["fields"]["title"]["id"] = "title";
  212. $handler->display->display_options["fields"]["title"]["table"] = "node";
  213. $handler->display->display_options["fields"]["title"]["field"] = "title";
  214. $handler->display->display_options["fields"]["title"]["relationship"] = "nid";
  215. $handler->display->display_options["fields"]["title"]["label"] = "Reply to";
  216. $handler->display->display_options["fields"]["title"]["link_to_node"] = 1;
  217. /* Field: Comment: Post date */
  218. $handler->display->display_options["fields"]["timestamp"]["id"] = "timestamp";
  219. $handler->display->display_options["fields"]["timestamp"]["table"] = "comments";
  220. $handler->display->display_options["fields"]["timestamp"]["field"] = "timestamp";
  221. $handler->display->display_options["fields"]["timestamp"]["label"] = "";
  222. $handler->display->display_options["fields"]["timestamp"]["date_format"] = "time ago";
  223. /* Field: Comment: Title */
  224. $handler->display->display_options["fields"]["subject"]["id"] = "subject";
  225. $handler->display->display_options["fields"]["subject"]["table"] = "comments";
  226. $handler->display->display_options["fields"]["subject"]["field"] = "subject";
  227. $handler->display->display_options["fields"]["subject"]["label"] = "";
  228. $handler->display->display_options["fields"]["subject"]["link_to_comment"] = 1;
  229. /* Field: Comment: Body */
  230. $handler->display->display_options["fields"]["comment"]["id"] = "comment";
  231. $handler->display->display_options["fields"]["comment"]["table"] = "comments";
  232. $handler->display->display_options["fields"]["comment"]["field"] = "comment";
  233. $handler->display->display_options["fields"]["comment"]["label"] = "";
  234. $handler->display->display_options["path"] = "comments/recent";
  235. /* Display: Block */
  236. $handler = $view->new_display("block", "Block", "block");
  237. $handler->display->display_options["block_description"] = "Recent comments view"
  238. ;';
  239. return $import;
  240. }
  241. }