views_handler_field_counter.test

Definition of ViewsHandlerFilterCounterTest.

File

tests/handlers/views_handler_field_counter.test
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of ViewsHandlerFilterCounterTest.
  5. */
  6. /**
  7. * Tests the views_handler_field_counter handler.
  8. */
  9. class ViewsHandlerFilterCounterTest extends ViewsSqlTest {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Field: Counter',
  13. 'description' => 'Tests the views_handler_field_counter handler.',
  14. 'group' => 'Views Handlers',
  15. );
  16. }
  17. function testSimple() {
  18. $view = $this->getBasicView();
  19. $view->display['default']->handler->override_option('fields', array(
  20. 'counter' => array(
  21. 'id' => 'counter',
  22. 'table' => 'views',
  23. 'field' => 'counter',
  24. 'relationship' => 'none',
  25. ),
  26. 'name' => array(
  27. 'id' => 'name',
  28. 'table' => 'views_test',
  29. 'field' => 'name',
  30. 'relationship' => 'none',
  31. ),
  32. ));
  33. $view->preview();
  34. $this->assertEqual(1, $view->style_plugin->rendered_fields[0]['counter']);
  35. $this->assertEqual(2, $view->style_plugin->rendered_fields[1]['counter']);
  36. $this->assertEqual(3, $view->style_plugin->rendered_fields[2]['counter']);
  37. $view->destroy();
  38. $view = $this->getBasicView();
  39. $rand_start = rand(5, 10);
  40. $view->display['default']->handler->override_option('fields', array(
  41. 'counter' => array(
  42. 'id' => 'counter',
  43. 'table' => 'views',
  44. 'field' => 'counter',
  45. 'relationship' => 'none',
  46. 'counter_start' => $rand_start
  47. ),
  48. 'name' => array(
  49. 'id' => 'name',
  50. 'table' => 'views_test',
  51. 'field' => 'name',
  52. 'relationship' => 'none',
  53. ),
  54. ));
  55. $view->preview();
  56. $this->assertEqual(0 + $rand_start, $view->style_plugin->rendered_fields[0]['counter']);
  57. $this->assertEqual(1 + $rand_start, $view->style_plugin->rendered_fields[1]['counter']);
  58. $this->assertEqual(2 + $rand_start, $view->style_plugin->rendered_fields[2]['counter']);
  59. }
  60. // @TODO: Write tests for pager.
  61. function testPager() {
  62. }
  63. }