views_module.test 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. /**
  3. * @file
  4. * Definition of ViewsModuleTest.
  5. */
  6. /**
  7. * Tests basic functions from the Views module.
  8. */
  9. class ViewsModuleTest extends ViewsSqlTest {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Tests views.module',
  13. 'description' => 'Tests some basic functions of views.module',
  14. 'group' => 'Views',
  15. );
  16. }
  17. public function setUp() {
  18. parent::setUp();
  19. drupal_theme_rebuild();
  20. }
  21. public function viewsData() {
  22. $data = parent::viewsData();
  23. $data['views_test_previous'] = array();
  24. $data['views_test_previous']['id']['field']['moved to'] = array('views_test', 'id');
  25. $data['views_test_previous']['id']['filter']['moved to'] = array('views_test', 'id');
  26. $data['views_test']['age_previous']['field']['moved to'] = array('views_test', 'age');
  27. $data['views_test']['age_previous']['sort']['moved to'] = array('views_test', 'age');
  28. $data['views_test_previous']['name_previous']['field']['moved to'] = array('views_test', 'name');
  29. $data['views_test_previous']['name_previous']['argument']['moved to'] = array('views_test', 'name');
  30. return $data;
  31. }
  32. public function test_views_trim_text() {
  33. // Test unicode, @see http://drupal.org/node/513396#comment-2839416
  34. $text = array(
  35. 'Tuy nhiên, những hi vọng',
  36. 'Giả sử chúng tôi có 3 Apple',
  37. 'siêu nhỏ này là bộ xử lý',
  38. 'Di động của nhà sản xuất Phần Lan',
  39. 'khoảng cách từ đại lí đến',
  40. 'của hãng bao gồm ba dòng',
  41. 'сд асд асд ас',
  42. 'асд асд асд ас'
  43. );
  44. // Just test maxlength without word boundry.
  45. $alter = array(
  46. 'max_length' => 10,
  47. );
  48. $expect = array(
  49. 'Tuy nhiên,',
  50. 'Giả sử chú',
  51. 'siêu nhỏ n',
  52. 'Di động củ',
  53. 'khoảng các',
  54. 'của hãng b',
  55. 'сд асд асд',
  56. 'асд асд ас',
  57. );
  58. foreach ($text as $key => $line) {
  59. $result_text = views_trim_text($alter, $line);
  60. $this->assertEqual($result_text, $expect[$key]);
  61. }
  62. // Test also word_boundary
  63. $alter['word_boundary'] = TRUE;
  64. $expect = array(
  65. 'Tuy nhiên',
  66. 'Giả sử',
  67. 'siêu nhỏ',
  68. 'Di động',
  69. 'khoảng',
  70. 'của hãng',
  71. 'сд асд',
  72. 'асд асд',
  73. );
  74. foreach ($text as $key => $line) {
  75. $result_text = views_trim_text($alter, $line);
  76. $this->assertEqual($result_text, $expect[$key]);
  77. }
  78. }
  79. /**
  80. * Tests the dynamic includes of templates via module feature.
  81. */
  82. function testModuleTemplates() {
  83. $views_status = variable_get('views_defaults', array());
  84. $views_status['frontpage'] = FALSE; // false is enabled
  85. variable_set('views_defaults', $views_status);
  86. $existing = array();
  87. $type = array();
  88. $theme = array();
  89. $path = array();
  90. $registry = views_theme($existing, $type, $theme, $path);
  91. $this->assertTrue(isset($registry['views_view__frontpage']));
  92. }
  93. /**
  94. * Tests the views_get_handler method.
  95. */
  96. function testviews_get_handler() {
  97. $types = array('field', 'area', 'filter');
  98. foreach ($types as $type) {
  99. $handler = views_get_handler($this->randomName(), $this->randomName(), $type);
  100. $this->assertEqual('views_handler_' . $type . '_broken', get_class($handler), t('Make sure that a broken handler of type: @type are created', array('@type' => $type)));
  101. }
  102. $views_data = $this->viewsData();
  103. $test_tables = array('views_test' => array('id', 'name'));
  104. foreach ($test_tables as $table => $fields) {
  105. foreach ($fields as $field) {
  106. $data = $views_data[$table][$field];
  107. foreach ($data as $id => $field_data) {
  108. if (!in_array($id, array('title', 'help'))) {
  109. $handler = views_get_handler($table, $field, $id);
  110. $this->assertInstanceHandler($handler, $table, $field, $id);
  111. }
  112. }
  113. }
  114. }
  115. // Test the automatic conversion feature.
  116. // Test the automatic table renaming.
  117. $handler = views_get_handler('views_test_previous', 'id', 'field');
  118. $this->assertInstanceHandler($handler, 'views_test', 'id', 'field');
  119. $handler = views_get_handler('views_test_previous', 'id', 'filter');
  120. $this->assertInstanceHandler($handler, 'views_test', 'id', 'filter');
  121. // Test the automatic field renaming.
  122. $handler = views_get_handler('views_test', 'age_previous', 'field');
  123. $this->assertInstanceHandler($handler, 'views_test', 'age', 'field');
  124. $handler = views_get_handler('views_test', 'age_previous', 'sort');
  125. $this->assertInstanceHandler($handler, 'views_test', 'age', 'sort');
  126. // Test the automatic table and field renaming.
  127. $handler = views_get_handler('views_test_previous', 'name_previous', 'field');
  128. $this->assertInstanceHandler($handler, 'views_test', 'name', 'field');
  129. $handler = views_get_handler('views_test_previous', 'name_previous', 'argument');
  130. $this->assertInstanceHandler($handler, 'views_test', 'name', 'argument');
  131. // Test the override handler feature.
  132. $handler = views_get_handler('views_test', 'job', 'filter', 'views_handler_filter');
  133. $this->assertEqual('views_handler_filter', get_class($handler));
  134. }
  135. /**
  136. * Ensure that a certain handler is a instance of a certain table/field.
  137. */
  138. function assertInstanceHandler($handler, $table, $field, $id) {
  139. $table_data = views_fetch_data($table);
  140. $field_data = $table_data[$field][$id];
  141. $this->assertEqual($field_data['handler'], get_class($handler));
  142. }
  143. }