views_handler_field_file_size.test

Definition of ViewsHandlerTestFileSize.

File

tests/handlers/views_handler_field_file_size.test
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of ViewsHandlerTestFileSize.
  5. */
  6. /**
  7. * Tests the core views_handler_field_file_size handler.
  8. *
  9. * @see CommonXssUnitTest
  10. */
  11. class ViewsHandlerTestFileSize extends ViewsSqlTest {
  12. public static function getInfo() {
  13. return array(
  14. 'name' => 'Field: file_size',
  15. 'description' => 'Test the core views_handler_field_file_size handler.',
  16. 'group' => 'Views Handlers',
  17. );
  18. }
  19. function dataSet() {
  20. $data = parent::dataSet();
  21. $data[0]['age'] = 0;
  22. $data[1]['age'] = 10;
  23. $data[2]['age'] = 1000;
  24. $data[3]['age'] = 10000;
  25. return $data;
  26. }
  27. function viewsData() {
  28. $data = parent::viewsData();
  29. $data['views_test']['age']['field']['handler'] = 'views_handler_field_file_size';
  30. return $data;
  31. }
  32. public function testFieldFileSize() {
  33. $view = $this->getBasicView();
  34. $view->display['default']->handler->override_option('fields', array(
  35. 'age' => array(
  36. 'id' => 'age',
  37. 'table' => 'views_test',
  38. 'field' => 'age',
  39. ),
  40. ));
  41. $this->executeView($view);
  42. // Test with the formatted option.
  43. $this->assertEqual($view->field['age']->advanced_render($view->result[0]), '');
  44. $this->assertEqual($view->field['age']->advanced_render($view->result[1]), '10 bytes');
  45. $this->assertEqual($view->field['age']->advanced_render($view->result[2]), '1000 bytes');
  46. $this->assertEqual($view->field['age']->advanced_render($view->result[3]), '9.77 KB');
  47. // Test with the bytes option.
  48. $view->field['age']->options['file_size_display'] = 'bytes';
  49. $this->assertEqual($view->field['age']->advanced_render($view->result[0]), '');
  50. $this->assertEqual($view->field['age']->advanced_render($view->result[1]), 10);
  51. $this->assertEqual($view->field['age']->advanced_render($view->result[2]), 1000);
  52. $this->assertEqual($view->field['age']->advanced_render($view->result[3]), 10000);
  53. }
  54. }