txt_export.test 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. class TXTExportViewsDataExportTests extends ViewsDataExportSimpleExportTest {
  3. protected $profile = 'testing';
  4. public static function getInfo() {
  5. return array(
  6. 'name' => 'TXT Export',
  7. 'description' => 'Various tests for exporting to TXT.',
  8. 'group' => 'Views Data Export',
  9. );
  10. }
  11. protected $vde_export_type = 'TXT';
  12. protected function getStylePluginName() {
  13. return 'views_data_export_txt';
  14. }
  15. protected function getExportView($path = 'vde_test') {
  16. // Create the basic view.
  17. $view = $this->getBasicExportView();
  18. $display = $view->new_display('views_data_export', 'Data export', 'vde_test');
  19. $display->override_option('style_plugin', $this->getStylePluginName());
  20. $display->override_option('path', $path);
  21. $expected = '[ID]
  22. 1
  23. [Name]
  24. John
  25. [Age]
  26. 25
  27. ----------------------------------------
  28. [ID]
  29. 2
  30. [Name]
  31. George
  32. [Age]
  33. 27
  34. ----------------------------------------
  35. [ID]
  36. 3
  37. [Name]
  38. Ringo
  39. [Age]
  40. 28
  41. ----------------------------------------
  42. [ID]
  43. 4
  44. [Name]
  45. Paul
  46. [Age]
  47. 26
  48. ----------------------------------------
  49. [ID]
  50. 5
  51. [Name]
  52. Meredith
  53. [Age]
  54. 30
  55. ----------------------------------------';
  56. return array(&$view, $expected);
  57. }
  58. /**
  59. * Test to check if empty fields are correctly hidden.
  60. */
  61. protected function testHideEmptySupport() {
  62. $view = $this->getHideIfEmptyExportView();
  63. // We need to ensure that the test fields are actually empty/0.
  64. db_update('views_test')
  65. ->fields(array('age' => 0,))
  66. ->condition('name', 'Paul')
  67. ->execute();
  68. db_update('views_test')
  69. ->fields(array('name' => '',))
  70. ->condition('name', 'George')
  71. ->execute();
  72. db_update('views_test')
  73. ->fields(array('name' => 0,))
  74. ->condition('name', 'John')
  75. ->execute();
  76. $expected = '[ID]
  77. 1
  78. [Name]
  79. 0
  80. [Age]
  81. 25
  82. ----------------------------------------
  83. [ID]
  84. 2
  85. [Age]
  86. 27
  87. ----------------------------------------
  88. [ID]
  89. 3
  90. [Name]
  91. Ringo
  92. [Age]
  93. 28
  94. ----------------------------------------
  95. [ID]
  96. 4
  97. [Name]
  98. Paul
  99. ----------------------------------------
  100. [ID]
  101. 5
  102. [Name]
  103. Meredith
  104. [Age]
  105. 30
  106. ----------------------------------------';
  107. $message = 'Hide if empty support for ' . $this->vde_export_type . ' export matched expected output.';
  108. $this->executeAndCompareGivenView($view, $expected, $message);
  109. }
  110. }