navigationmanagertest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Joas Schilling
  6. * @copyright 2015 Joas Schilling nickvergessen@owncloud.com
  7. *
  8. * This file is licensed under the Affero General Public License version 3 or
  9. * later.
  10. * See the COPYING-README file.
  11. */
  12. namespace Test;
  13. use OC\NavigationManager;
  14. class NavigationManagerTest extends TestCase {
  15. /** @var \OC\NavigationManager */
  16. protected $navigationManager;
  17. protected function setUp() {
  18. parent::setUp();
  19. $this->navigationManager = new NavigationManager();
  20. }
  21. public function addArrayData() {
  22. return [
  23. [
  24. [
  25. 'id' => 'entry id',
  26. 'name' => 'link text',
  27. 'order' => 1,
  28. 'icon' => 'optional',
  29. 'href' => 'url',
  30. ],
  31. [
  32. 'id' => 'entry id',
  33. 'name' => 'link text',
  34. 'order' => 1,
  35. 'icon' => 'optional',
  36. 'href' => 'url',
  37. 'active' => false,
  38. ],
  39. ],
  40. [
  41. [
  42. 'id' => 'entry id',
  43. 'name' => 'link text',
  44. 'order' => 1,
  45. //'icon' => 'optional',
  46. 'href' => 'url',
  47. 'active' => true,
  48. ],
  49. [
  50. 'id' => 'entry id',
  51. 'name' => 'link text',
  52. 'order' => 1,
  53. 'icon' => '',
  54. 'href' => 'url',
  55. 'active' => false,
  56. ],
  57. ],
  58. ];
  59. }
  60. /**
  61. * @dataProvider addArrayData
  62. *
  63. * @param array $entry
  64. * @param array $expectedEntry
  65. */
  66. public function testAddArray(array $entry, array $expectedEntry) {
  67. $this->assertEmpty($this->navigationManager->getAll(), 'Expected no navigation entry exists');
  68. $this->navigationManager->add($entry);
  69. $navigationEntries = $this->navigationManager->getAll();
  70. $this->assertEquals(1, sizeof($navigationEntries), 'Expected that 1 navigation entry exists');
  71. $this->assertEquals($expectedEntry, $navigationEntries[0]);
  72. $this->navigationManager->clear();
  73. $this->assertEmpty($this->navigationManager->getAll(), 'Expected no navigation entry exists after clear()');
  74. }
  75. /**
  76. * @dataProvider addArrayData
  77. *
  78. * @param array $entry
  79. * @param array $expectedEntry
  80. */
  81. public function testAddClosure(array $entry, array $expectedEntry) {
  82. global $testAddClosureNumberOfCalls;
  83. $testAddClosureNumberOfCalls = 0;
  84. $this->navigationManager->add(function () use ($entry) {
  85. global $testAddClosureNumberOfCalls;
  86. $testAddClosureNumberOfCalls++;
  87. return $entry;
  88. });
  89. $this->assertEquals(0, $testAddClosureNumberOfCalls, 'Expected that the closure is not called by add()');
  90. $navigationEntries = $this->navigationManager->getAll();
  91. $this->assertEquals(1, $testAddClosureNumberOfCalls, 'Expected that the closure is called by getAll()');
  92. $this->assertEquals(1, sizeof($navigationEntries), 'Expected that 1 navigation entry exists');
  93. $this->assertEquals($expectedEntry, $navigationEntries[0]);
  94. $navigationEntries = $this->navigationManager->getAll();
  95. $this->assertEquals(1, $testAddClosureNumberOfCalls, 'Expected that the closure is only called once for getAll()');
  96. $this->assertEquals(1, sizeof($navigationEntries), 'Expected that 1 navigation entry exists');
  97. $this->assertEquals($expectedEntry, $navigationEntries[0]);
  98. $this->navigationManager->clear();
  99. $this->assertEmpty($this->navigationManager->getAll(), 'Expected no navigation entry exists after clear()');
  100. }
  101. public function testAddArrayClearGetAll() {
  102. $entry = [
  103. 'id' => 'entry id',
  104. 'name' => 'link text',
  105. 'order' => 1,
  106. 'icon' => 'optional',
  107. 'href' => 'url',
  108. ];
  109. $this->assertEmpty($this->navigationManager->getAll(), 'Expected no navigation entry exists');
  110. $this->navigationManager->add($entry);
  111. $this->navigationManager->clear();
  112. $this->assertEmpty($this->navigationManager->getAll(), 'Expected no navigation entry exists after clear()');
  113. }
  114. public function testAddClosureClearGetAll() {
  115. $this->assertEmpty($this->navigationManager->getAll(), 'Expected no navigation entry exists');
  116. $entry = [
  117. 'id' => 'entry id',
  118. 'name' => 'link text',
  119. 'order' => 1,
  120. 'icon' => 'optional',
  121. 'href' => 'url',
  122. ];
  123. global $testAddClosureNumberOfCalls;
  124. $testAddClosureNumberOfCalls = 0;
  125. $this->navigationManager->add(function () use ($entry) {
  126. global $testAddClosureNumberOfCalls;
  127. $testAddClosureNumberOfCalls++;
  128. return $entry;
  129. });
  130. $this->assertEquals(0, $testAddClosureNumberOfCalls, 'Expected that the closure is not called by add()');
  131. $this->navigationManager->clear();
  132. $this->assertEquals(0, $testAddClosureNumberOfCalls, 'Expected that the closure is not called by clear()');
  133. $this->assertEmpty($this->navigationManager->getAll(), 'Expected no navigation entry exists after clear()');
  134. $this->assertEquals(0, $testAddClosureNumberOfCalls, 'Expected that the closure is not called by getAll()');
  135. }
  136. }