Completed
Push — master ( 659231...788af6 )
by Wanderson
05:06
created

RouteTest::testRouteToPageNotFound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 14
loc 14
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
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 View Code Duplication
	public function testRouteToPageNotFound() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 View Code Duplication
	public function testRouteToActionNotFound() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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