OSDN Git Service

a8e7b2b76322b3f99262481e068df843843ff118
[php-libraries/Router.git] / tests / src / PHPRouterTest / RouteTest.php
1 <?php
2 /**
3  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14  *
15  * This software consists of voluntary contributions made by many individuals
16  * and is licensed under the MIT license.
17  */
18 namespace PHPRouterTest\Test;
19
20 use PHPRouter\Route;
21 use PHPUnit_Framework_TestCase;
22
23 class RouteTest extends PHPUnit_Framework_TestCase
24 {
25     private $routeWithParameters;
26
27     protected function setUp()
28     {
29         $this->routeWithParameters = new Route(
30             '/page/:page_id',
31             array(
32                 '_controller' => 'PHPRouter\Test\SomeController::page',
33                 'methods' => array(
34                     'GET'
35                 ),
36                 'target' => 'thisIsAString',
37                 'name' => 'page'
38             )
39         );
40     }
41
42     public function testGetUrl()
43     {
44         $this->assertEquals('/page/:page_id', $this->routeWithParameters->getUrl());
45     }
46
47     public function testSetUrl()
48     {
49         $this->routeWithParameters->setUrl('/pages/:page_name/');
50         $this->assertEquals('/pages/:page_name/', $this->routeWithParameters->getUrl());
51
52         $this->routeWithParameters->setUrl('/pages/:page_name');
53         $this->assertEquals('/pages/:page_name/', $this->routeWithParameters->getUrl());
54     }
55
56     public function testGetMethods()
57     {
58         $this->assertEquals(array('GET'), $this->routeWithParameters->getMethods());
59     }
60
61     public function testSetMethods()
62     {
63         $this->routeWithParameters->setMethods(array('POST'));
64         $this->assertEquals(array('POST'), $this->routeWithParameters->getMethods());
65
66         $this->routeWithParameters->setMethods(array('GET', 'POST', 'PUT', 'DELETE'));
67         $this->assertEquals(array('GET', 'POST', 'PUT', 'DELETE'), $this->routeWithParameters->getMethods());
68     }
69
70     public function testGetTarget()
71     {
72         $this->assertEquals('thisIsAString', $this->routeWithParameters->getTarget());
73     }
74
75     public function testSetTarget()
76     {
77         $this->routeWithParameters->setTarget('ThisIsAnotherString');
78         $this->assertEquals('ThisIsAnotherString', $this->routeWithParameters->getTarget());
79     }
80
81     public function testGetName()
82     {
83         $this->assertEquals('page', $this->routeWithParameters->getName());
84     }
85
86     public function testSetName()
87     {
88         $this->routeWithParameters->setName('pageroute');
89         $this->assertEquals('pageroute', $this->routeWithParameters->getName());
90     }
91
92     public function testGetAction()
93     {
94         $this->assertEquals('page', $this->routeWithParameters->getAction());
95     }
96 }