123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. * Hoa
  4. *
  5. *
  6. * @license
  7. *
  8. * New BSD License
  9. *
  10. * Copyright © 2007-2017, Hoa community. All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. * * Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * * Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * * Neither the name of the Hoa nor the names of its contributors may be
  20. * used to endorse or promote products derived from this software without
  21. * specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. namespace Hoa\Protocol\Test\Unit;
  36. use Hoa\Protocol\Protocol as SUT;
  37. use Hoa\Test;
  38. /**
  39. * Class \Hoa\Protocol\Test\Unit\Protocol.
  40. *
  41. * Test suite of the protocol class.
  42. *
  43. * @copyright Copyright © 2007-2017 Hoa community
  44. * @license New BSD License
  45. */
  46. class Protocol extends Test\Unit\Suite
  47. {
  48. public function case_root_is_a_node()
  49. {
  50. $this
  51. ->when($result = SUT::getInstance())
  52. ->then
  53. ->object($result)
  54. ->isInstanceOf('Hoa\Protocol\Node');
  55. }
  56. public function case_default_tree()
  57. {
  58. $this
  59. ->when($result = SUT::getInstance())
  60. ->then
  61. ->object($result['Application'])->isInstanceOf('Hoa\Protocol\Node\Node')
  62. ->object($result['Application']['Public'])->isInstanceOf('Hoa\Protocol\Node\Node')
  63. ->object($result['Data'])->isInstanceOf('Hoa\Protocol\Node\Node')
  64. ->object($result['Data']['Etc'])->isInstanceOf('Hoa\Protocol\Node\Node')
  65. ->object($result['Data']['Etc']['Configuration'])->isInstanceOf('Hoa\Protocol\Node\Node')
  66. ->object($result['Data']['Etc']['Locale'])->isInstanceOf('Hoa\Protocol\Node\Node')
  67. ->object($result['Data']['Lost+found'])->isInstanceOf('Hoa\Protocol\Node\Node')
  68. ->object($result['Data']['Temporary'])->isInstanceOf('Hoa\Protocol\Node\Node')
  69. ->object($result['Data']['Variable'])->isInstanceOf('Hoa\Protocol\Node\Node')
  70. ->object($result['Data']['Variable']['Cache'])->isInstanceOf('Hoa\Protocol\Node\Node')
  71. ->object($result['Data']['Variable']['Database'])->isInstanceOf('Hoa\Protocol\Node\Node')
  72. ->object($result['Data']['Variable']['Log'])->isInstanceOf('Hoa\Protocol\Node\Node')
  73. ->object($result['Data']['Variable']['Private'])->isInstanceOf('Hoa\Protocol\Node\Node')
  74. ->object($result['Data']['Variable']['Run'])->isInstanceOf('Hoa\Protocol\Node\Node')
  75. ->object($result['Data']['Variable']['Test'])->isInstanceOf('Hoa\Protocol\Node\Node')
  76. ->object($result['Library'])->isInstanceOf('Hoa\Protocol\Node\Library')
  77. ->string($result['Library']->reach())
  78. ->isEqualTo(
  79. dirname(dirname(dirname(dirname(__DIR__)))) . DS . 'hoathis' . DS .
  80. RS .
  81. dirname(dirname(dirname(dirname(__DIR__)))) . DS . 'hoa' . DS
  82. );
  83. }
  84. public function case_resolve_not_a_hoa_path()
  85. {
  86. $this
  87. ->given($protocol = SUT::getInstance())
  88. ->when($result = $protocol->resolve('/foo/bar'))
  89. ->then
  90. ->string($result)
  91. ->isEqualTo('/foo/bar');
  92. }
  93. public function case_resolve_to_non_existing_resource()
  94. {
  95. $this
  96. ->given($protocol = SUT::getInstance())
  97. ->when($result = $protocol->resolve('hoa://Application/Foo/Bar'))
  98. ->then
  99. ->string($result)
  100. ->isEqualTo(SUT::NO_RESOLUTION);
  101. }
  102. public function case_resolve_does_not_test_if_exists()
  103. {
  104. $this
  105. ->given($protocol = SUT::getInstance())
  106. ->when($result = $protocol->resolve('hoa://Application/Foo/Bar', false))
  107. ->then
  108. ->string($result)
  109. ->isEqualTo('/Foo/Bar');
  110. }
  111. public function case_resolve_unfold_to_existing_resources()
  112. {
  113. $this
  114. ->given($protocol = SUT::getInstance())
  115. ->when($result = $protocol->resolve('hoa://Library', true, true))
  116. ->then
  117. ->array($result)
  118. ->contains(
  119. dirname(dirname(dirname(dirname(__DIR__)))) . DS . 'hoa'
  120. );
  121. }
  122. public function case_resolve_unfold_to_non_existing_resources()
  123. {
  124. $this
  125. ->given(
  126. $parentHoaDirectory = dirname(dirname(dirname(dirname(__DIR__)))),
  127. $protocol = SUT::getInstance()
  128. )
  129. ->when($result = $protocol->resolve('hoa://Library', false, true))
  130. ->then
  131. ->array($result)
  132. ->isEqualTo([
  133. $parentHoaDirectory . DS . 'hoathis',
  134. $parentHoaDirectory . DS . 'hoa'
  135. ]);
  136. }
  137. }