Completed
Push — master ( baf9c0...cf2f5b )
by Wanderson
02:20
created

ApplicationTest::testGetParamDefault()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 5
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 7
rs 9.4285
1
<?php
2
3
namespace Win\Mvc;
4
5
use Win\Mvc\Application;
6
use Win\Helper\Url;
7
8
class ApplicationTest extends \PHPUnit_Framework_TestCase {
9
10
	public function testGetInstanceApp() {
11
		Url::instance()->setUrl('index');
12
		$app = new Application();
13
		$this->assertTrue($app instanceof Application);
14
		$this->assertTrue(Application::app() instanceof Application);
15
	}
16
17
	public function testGetName() {
18
		$config = ['name' => 'My custom Application Name'];
19
		$app = new Application($config);
20
21
		$this->assertEquals('My custom Application Name', $app->getName());
22
		$this->assertEquals($app->getName(), $app->getConfig('name'));
23
	}
24
25
	public function testGetTitle() {
26
		Url::instance()->setUrl('');
27
		$app = new Application();
28
		$this->assertEquals('Index', $app->getTitle());
29
30
		Url::instance()->setUrl('my-custom-page');
31
		$app2 = new Application();
32
		$this->assertEquals('My Custom Page', $app2->getTitle());
33
34
		Url::instance()->setUrl('my-custom-page/my-action');
35
		$app3 = new Application();
36
		$app3->controller->load();
37
		$this->assertNotEquals('My Custom Page', $app3->getTitle());
38
39
		$app->setTitle('My Custom Test Title');
40
		$this->assertEquals('My Custom Test Title', $app->getTitle());
41
42
		$app->pageNotFound();
43
		$this->assertNotEquals('My Custom Test Title', $app->getTitle());
44
	}
45
46
	public function testGetPage() {
47
		Url::instance()->setUrl('my-page/my-action/first-param/2nd-param/3rd-param');
48
		$app = new Application();
49
50
		$this->assertEquals('my-page', $app->getPage());
51
	}
52
53
	public function testGetParamDefault() {
54
		Url::instance()->setUrl('my-page');
55
		$app = new Application();
56
57
		$this->assertEquals('index', $app->getParam(1));
58
		$this->assertNotEquals('', $app->getParam(1));
59
	}
60
61
	public function testGetAction() {
62
		Url::instance()->setUrl('my-page/my-action/first-param/2nd-param/3rd-param');
63
		$app = new Application();
64
65
		$this->assertEquals('myAction', $app->controller->getAction());
66
	}
67
68
	public function testGetParam() {
69
		Url::instance()->setUrl('my-page/my-action/second-param/3rd-param');
70
		$app = new Application();
71
72
		$this->assertEquals('my-page', $app->getParam(0));
73
		$this->assertEquals('my-action', $app->getParam(1));
74
		$this->assertEquals('second-param', $app->getParam(2));
75
		$this->assertEquals('3rd-param', $app->getParam(3));
76
		$this->assertEquals('', $app->getParam(4));
77
	}
78
79
	public function testIsErrorPage() {
80
		Url::instance()->setUrl('index');
81
		$app = new Application();
82
		$this->assertFalse($app->isErrorPage());
83
84
		$app->pageNotFound();
85
		$this->assertTrue($app->isErrorPage());
86
	}
87
88 View Code Duplication
	public function testIsHomePage() {
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...
89
		Url::instance()->setUrl('');
90
		$app = new Application();
91
		$this->assertTrue($app->isHomePage());
92
93
		Url::instance()->setUrl('index');
94
		$app2 = new Application();
95
		$this->assertTrue($app2->isHomePage());
96
	}
97
98 View Code Duplication
	public function testIsNotHomePage() {
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...
99
		Url::instance()->setUrl('index');
100
		$app = new Application();
101
		$app->pageNotFound();
102
		$this->assertFalse($app->isHomePage());
103
104
		Url::instance()->setUrl('other-page');
105
		$app2 = new Application();
106
		$this->assertFalse($app2->isHomePage());
107
	}
108
109
	public function testIsLocalHost() {
110
		$app = new Application();
111
		$this->assertEquals(true, $app->isLocalHost());
112
	}
113
114
	public function testGetConfig() {
115
		$config = ['year' => 2040];
116
		$app = new Application($config);
117
		$this->assertEquals(2040, $app->getConfig('year', 3000));
118
	}
119
120
	public function testGetConfigDefault() {
121
		$configEmpty = [];
122
		$app2 = new Application($configEmpty);
123
		$this->assertEquals(3000, $app2->getConfig('year', 3000));
124
	}
125
126
	public function testRun() {
127
		Url::instance()->setUrl('this-page-doesnt-exist');
128
		$app = new Application();
129
		$this->assertNotEquals('404', $app->getPage());
130
131
		Url::instance()->setUrl('this-page-doesnt-exist');
132
		$app2 = new Application();
133
134
		ob_start();
135
		$app2->run();
136
		ob_end_clean();
137
		$this->assertEquals('404', $app2->getPage());
138
	}
139
140
	public function testGetUrl() {
141
		$currentUrl = Url::instance()->format('my-page/my-action/param1/param2');
142
		Url::instance()->setUrl($currentUrl);
143
		$app = new Application();
144
		$this->assertEquals($currentUrl, $app->getUrl());
145
	}
146
147 View Code Duplication
	public function testValidatePage404() {
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...
148
		Url::instance()->setUrl('this-url-doent-exist');
149
		$app = new Application();
150
		$this->assertEquals('This Url Doent Exist', $app->getTitle());
151
152
		Url::instance()->setUrl('404');
153
		$app2 = new Application();
154
		$this->assertNotEquals('404', $app2->getTitle());
155
	}
156
157
}
158