Completed
Push — master ( cf2f5b...2b18f3 )
by Wanderson
02:54
created

RouteTest::testThereIsNoRoutes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 8
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 11
rs 9.4285
1
<?php
2
namespace Win\Mvc;
3
4
use Win\Helper\Url;
5
use Win\Mvc\Route;
6
use Win\Mvc\Application;
7
8
9
class RouteTest extends \PHPUnit_Framework_TestCase {
10
11
	public function testThereIsNoRoutes() {
12
13
		Url::instance()->setUrl('my-page/my-action/my-param/');
14
		$config = [];
15
		$app = new Application($config);
16
		$app->controller->load();
17
18
		$this->assertEquals('404', $app->getPage());
19
		$this->assertFalse(Route::instance()->hasCustomUrl());
20
		$this->assertEquals([null, null], Route::instance()->getCustomUrl());
21
	}
22
23
	public function testThereIsOneRoute() {
24
		Url::instance()->setUrl('my-page/my-action/my-param/');
25
		$config = [
26
			'route' => [
27
				'my-page/(.*)' => 'index'
28
			]
29
		];
30
31
		$app = new Application($config);
32
		$app->controller->load();
33
34
		$this->assertEquals('index', $app->getPage());
35
		$this->assertTrue(Route::instance()->hasCustomUrl());
36
		$this->assertEquals(['index', null], Route::instance()->getCustomUrl());
37
	}
38
39
	public function testRouteToPageNotFound() {
40
		Url::instance()->setUrl('my-page/my-action/my-param/');
41
		$config = [
42
			'route' => [
43
				'other-page' => 'index'
44
			]
45
		];
46
47
		$app = new Application($config);
48
		$app->controller->load();
49
50
		$this->assertEquals('404', $app->getPage());
51
		$this->assertFalse(Route::instance()->hasCustomUrl());
52
	}
53
54
	public function testRouteToActionNotFound() {
55
		Url::instance()->setUrl('my-page/my-action/my-param/');
56
		$config = [
57
			'route' => [
58
				'my-page/(.*)' => 'index/this-action-doeent-exit'
59
			]
60
		];
61
62
		$app = new Application($config);
63
		$app->controller->load();
64
65
		$this->assertEquals('404', $app->getPage());
66
	}
67
68
	public function testRouteWithCustomParam() {
69
		Url::instance()->setUrl('my-product/list/id/100');
70
		$config = [
71
			'route' => [
72
				'my-product/(.*)/id/(.*)' => 'index/index/$1/teste/$2'
73
			]
74
		];
75
76
		$app = new Application($config);
77
		$app->controller->load();
78
79
		$this->assertEquals('index', $app->getPage());
80
		$this->assertEquals('list', $app->getParam(2));
81
		$this->assertEquals('teste', $app->getParam(3));
82
		$this->assertEquals('100', $app->getParam(4));
83
		$this->assertEquals(['index', 'index', 'list', 'teste', '100'], array_filter(Route::instance()->getCustomUrl()));
84
	}
85
86
}
87