|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nip\Router\Tests\Parsers; |
|
4
|
|
|
|
|
5
|
|
|
use Nip\Router\Parsers\Dynamic; |
|
6
|
|
|
use Nip\Router\Tests\AbstractTest; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Test class for Nip_Route_Abstract. |
|
10
|
|
|
* Generated by PHPUnit on 2010-11-17 at 15:16:44. |
|
11
|
|
|
*/ |
|
12
|
|
|
class DynamicTest extends AbstractTest |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var Dynamic |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $object; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Sets up the fixture, for example, opens a network connection. |
|
22
|
|
|
* This method is called before a test is executed. |
|
23
|
|
|
*/ |
|
24
|
|
|
protected function setUp() : void |
|
25
|
|
|
{ |
|
26
|
|
|
$this->object = new Dynamic(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testSetMap() |
|
30
|
|
|
{ |
|
31
|
|
|
$map = 'shop/category_:url/:name'; |
|
32
|
|
|
$this->object->setMap($map); |
|
|
|
|
|
|
33
|
|
|
static::assertEquals($map, $this->object->getMap()); |
|
34
|
|
|
static::assertEquals(3, count($this->object->getParts())); |
|
35
|
|
|
static::assertEquals(['url', 'name'], $this->object->getVariables()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testGetVariableFromPart() |
|
39
|
|
|
{ |
|
40
|
|
|
static::assertEquals(['url'], $this->object->getVariableFromPart(':url')); |
|
41
|
|
|
static::assertEquals(['url'], $this->object->getVariableFromPart('category_:url')); |
|
42
|
|
|
static::assertEquals(['category', 'url_shop'], $this->object->getVariableFromPart(':category:url_shop')); |
|
43
|
|
|
static::assertEquals(['category_main', 'url_shop'], $this->object->getVariableFromPart(':category_main:url_shop')); |
|
44
|
|
|
static::assertEquals(['category', 'url_product'], $this->object->getVariableFromPart(':category-:url_product')); |
|
45
|
|
|
static::assertEquals(['category', 'url_product'], $this->object->getVariableFromPart(':category-:url_product-test')); |
|
46
|
|
|
static::assertEquals(['category', 'url_product'], $this->object->getVariableFromPart('shop-:category-:url_product-test')); |
|
47
|
|
|
static::assertEquals(['category_main', 'url_product'], $this->object->getVariableFromPart('shop-:category_main-:url_product-test')); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
public function testAssemble() |
|
52
|
|
|
{ |
|
53
|
|
|
$params = [ |
|
54
|
|
|
'url' => 'lorem', |
|
55
|
|
|
'name' => 'ipsum', |
|
56
|
|
|
'company' => 'dolo&rem', |
|
57
|
|
|
]; |
|
58
|
|
|
static::assertEquals('?url=lorem&name=ipsum&company=dolo%26rem', $this->object->assemble($params)); |
|
59
|
|
|
|
|
60
|
|
|
$this->object->setMap('shop/category_:url/:name'); |
|
|
|
|
|
|
61
|
|
|
static::assertEquals('shop/category_lorem/ipsum?company=dolo%26rem', $this->object->assemble($params)); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testMatch() |
|
65
|
|
|
{ |
|
66
|
|
|
$map = 'shop/category_:url/:name'; |
|
67
|
|
|
$this->object->setMap($map); |
|
|
|
|
|
|
68
|
|
|
static::assertFalse($this->object->match('shop/category_cast/')); |
|
69
|
|
|
static::assertTrue($this->object->match('shop/category_cars/honda')); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|