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