views_upgrade.test 13 KB

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