views_glossary.test

Definition of ViewsGlossaryTestCase.

File

tests/views_glossary.test
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of ViewsGlossaryTestCase.
  5. */
  6. /**
  7. * Tests glossary view ( summary of arguments ).
  8. */
  9. class ViewsGlossaryTestCase extends ViewsSqlTest {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Glossary Test',
  13. 'description' => 'Tests glossary functionality of views.',
  14. 'group' => 'Views',
  15. );
  16. }
  17. public function setUp() {
  18. parent::setUp('views');
  19. }
  20. /**
  21. * Tests the default glossary view.
  22. */
  23. public function testGlossaryView() {
  24. // create a contentype and add some nodes, with a non random title.
  25. $type = $this->drupalCreateContentType();
  26. $nodes_per_char = array(
  27. 'd' => 1,
  28. 'r' => 4,
  29. 'u' => 10,
  30. 'p' => 2,
  31. 'a' => 3,
  32. 'l' => 6,
  33. );
  34. foreach ($nodes_per_char as $char => $count) {
  35. $setting = array(
  36. 'type' => $type->type
  37. );
  38. for ($i = 0; $i < $count; $i++) {
  39. $node = $setting;
  40. $node['title'] = $char . $this->randomString(3);
  41. $this->drupalCreateNode($node);
  42. }
  43. }
  44. // Execute glossary view
  45. $view = views_get_view('glossary');
  46. $view->set_display('attachment');
  47. $view->execute_display('attachment');
  48. // Check that the amount of nodes per char.
  49. $result_nodes_per_char = array();
  50. foreach ($view->result as $item) {
  51. $this->assertEqual($nodes_per_char[$item->title_truncated], $item->num_records);
  52. }
  53. }
  54. }