ElggBreadcrumbsTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. class ElggBreadcrumbsTest extends \PHPUnit_Framework_TestCase {
  3. // public function setUp() {
  4. // // TODO run each test in better isolation
  5. // static $have_run;
  6. // if (!$have_run) {
  7. // _elgg_nav_init();
  8. // $have_run = true;
  9. // }
  10. // }
  11. public function testCrumbsCanBePushed() {
  12. elgg_push_breadcrumb('title 1');
  13. elgg_push_breadcrumb('title 2', 'path2');
  14. $this->assertEquals(array(
  15. array('title' => 'title 1', 'link' => null),
  16. array('title' => 'title 2', 'link' => 'path2')
  17. ), elgg_get_breadcrumbs());
  18. }
  19. public function testCrumbsCanBePopped() {
  20. elgg_push_breadcrumb('title 1');
  21. elgg_push_breadcrumb('title 2', 'path2');
  22. $this->assertEquals(array('title' => 'title 2', 'link' => 'path2'), elgg_pop_breadcrumb());
  23. $this->assertEquals(array(
  24. array('title' => 'title 1', 'link' => null),
  25. ), elgg_get_breadcrumbs());
  26. $this->assertEquals(array('title' => 'title 1', 'link' => null), elgg_pop_breadcrumb());
  27. $this->assertEquals(array(), elgg_get_breadcrumbs());
  28. }
  29. public function testCanAlterCrumbsViaHook() {
  30. elgg_push_breadcrumb(str_repeat('abcd ', 100));
  31. elgg_unregister_plugin_hook_handler('prepare', 'breadcrumbs', 'elgg_prepare_breadcrumbs');
  32. $this->assertEquals(array(
  33. array(
  34. 'title' => str_repeat('abcd ', 100),
  35. 'link' => null,
  36. ),
  37. ), elgg_get_breadcrumbs());
  38. }
  39. public function testCrumbsAreExcerpted() {
  40. $this->markTestIncomplete('Needs DB');
  41. elgg_push_breadcrumb(str_repeat('abcd ', 100));
  42. $this->assertEquals(array(
  43. array(
  44. 'title' => elgg_get_excerpt(str_repeat('abcd ', 100), 100),
  45. 'link' => null,
  46. ),
  47. ), elgg_get_breadcrumbs());
  48. }
  49. public function testCrumbTitlesAreEscaped() {
  50. $this->markTestIncomplete('Needs DB');
  51. // TODO make this unnecessary
  52. elgg_set_view_location('output/url', __DIR__ . '/../../../views/');
  53. elgg_set_view_location('navigation/breadcrumbs', __DIR__ . '/../../../views/');
  54. elgg_push_breadcrumb('Me < &amp; you');
  55. $escaped = 'Me &lt; &amp; you';
  56. $html = elgg_view('navigation/breadcrumbs');
  57. $this->assertNotFalse(strpos($html, $escaped));
  58. // links uses different view
  59. elgg_pop_breadcrumb();
  60. elgg_push_breadcrumb('Me < &amp; you', 'link');
  61. $html = elgg_view('navigation/breadcrumbs');
  62. $this->assertNotFalse(strpos($html, $escaped));
  63. }
  64. public function testCrumbLinksAreNormalized() {
  65. $this->markTestIncomplete('Needs DB');
  66. // TODO make this unnecessary
  67. elgg_set_view_location('output/url', __DIR__ . '/../../../views/');
  68. elgg_set_view_location('navigation/breadcrumbs', __DIR__ . '/../../../views/');
  69. elgg_push_breadcrumb('test', 'link');
  70. $html = elgg_view('navigation/breadcrumbs');
  71. $this->assertNotFalse(strpos($html, '"http://localhost/link"'));
  72. }
  73. }