Skip to content

Commit c9d8fb0

Browse files
committed
update last commit
2 parents c69b79a + 5c254cc commit c9d8fb0

File tree

6 files changed

+268
-4
lines changed

6 files changed

+268
-4
lines changed

app/controllers/InstallController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,8 @@ private function seed()
390390
'rule' => ''),
391391
array('varname' => 'copyright',
392392
'groupname' => 'general',
393-
'value' => 'yoursite.com © 2013',
394-
'defaultvalue' => 'A2Z CMS 2013',
393+
'value' => 'yoursite.com © '.date("Y"),
394+
'defaultvalue' => 'A2Z CMS 2013-2014',
395395
'type' =>'text',
396396
'rule' => ''),
397397
array('varname' => 'metadesc',

app/tests/blueprints/User.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
use Woodling\Woodling;
4+
use J20\Uuid;
5+
use Carbon\Carbon;
6+
7+
Woodling::seed('UserAdmin', array('class' => 'User', 'do' => function($blueprint)
8+
{
9+
$blueprint->username = 'admin';
10+
$blueprint->email = '[email protected]';
11+
$blueprint->confirmation_code = md5( uniqid(mt_rand(), true) );
12+
$blueprint->confirmed = 1;
13+
$blueprint->created = Carbon::now();
14+
$blueprint->updated = Carbon::now()->addMonths(2);
15+
$blueprint->role = function() { return Woodling::retrieve('RoleAdmin'); };
16+
}));
17+
18+
Woodling::seed('UserUser', array('class' => 'User', 'do' => function($blueprint)
19+
{
20+
$blueprint->username = 'user';
21+
$blueprint->email = '[email protected]';
22+
$blueprint->confirmation_code = md5( uniqid(mt_rand(), true) );
23+
$blueprint->confirmed = 1;
24+
$blueprint->created = Carbon::now();
25+
$blueprint->updated = Carbon::now()->addMonths(2);
26+
$blueprint->role = function() { return Woodling::retrieve('RoleComment'); };
27+
}));
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
class UserControllerTest extends BaseControllerTestCase {
4+
5+
public function testShouldLogin()
6+
{
7+
$this->requestAction('GET', 'UserController@getLogin');
8+
$this->assertRequestOk();
9+
}
10+
11+
public function testShouldDoLogin()
12+
{
13+
$credentials = array(
14+
'email'=>'[email protected]',
15+
'password'=>'admin',
16+
'csrf_token' => Session::getToken()
17+
);
18+
19+
$this->withInput( $credentials )
20+
->requestAction('POST', 'UserController@postLogin');
21+
22+
$this->assertRedirection( URL::action('BlogController@getIndex') );
23+
}
24+
25+
public function testShouldNotDoLoginWhenWrong()
26+
{
27+
$credentials = array(
28+
'email'=>'[email protected]',
29+
'password'=>'wrong',
30+
'csrf_token' => Session::getToken());
31+
32+
$this->withInput( $credentials )
33+
->requestAction('POST', 'UserController@postLogin');
34+
35+
$this->assertRedirection( URL::action('UserController@getLogin') );
36+
}
37+
38+
/**
39+
* @expectedException \Illuminate\Session\TokenMismatchException
40+
*/
41+
public function testShouldNotDoLoginWhenTokenWrong()
42+
{
43+
$credentials = array(
44+
'email'=>'[email protected]',
45+
'password'=>'admin',
46+
'csrf_token' => ''
47+
);
48+
49+
$this->withInput( $credentials )
50+
->requestAction('POST', 'UserController@postLogin');
51+
}
52+
53+
/**
54+
* Testing redirect with logged in user.
55+
*/
56+
public function testLoginShouldRedirectUser()
57+
{
58+
$credentials = array(
59+
'email'=>'[email protected]',
60+
'password'=>'admin',
61+
'csrf_token' => Session::getToken()
62+
);
63+
64+
$this->withInput( $credentials )
65+
->requestAction('POST', 'UserController@postLogin');
66+
67+
$this->requestAction('GET', 'UserController@getLogin');
68+
69+
$this->assertRedirection( URL::to('/') );
70+
}
71+
72+
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?php
2+
3+
use Symfony\Component\HttpKernel\Exception\HttpException;
4+
5+
class BaseControllerTestCase extends TestCase
6+
{
7+
8+
/**
9+
* Will contain the parameters of the next request
10+
*
11+
* @var array
12+
*/
13+
protected $requestInput = array();
14+
15+
/**
16+
* Will the last HttpException caught
17+
*
18+
* @var HttpException
19+
*/
20+
protected $lastException;
21+
22+
/**
23+
* Set session and enable Laravel filters
24+
*
25+
*/
26+
public function setUp()
27+
{
28+
parent::setUp();
29+
30+
// Enable session
31+
Session::start();
32+
33+
// Enable filters
34+
Route::enableFilters();
35+
}
36+
37+
/**
38+
* Request an URL by the action name
39+
*
40+
* @param string $method
41+
* @param string $action
42+
* @param array $params
43+
* @return BaseControllerTestCase this for method chaining.
44+
*/
45+
public function requestAction($method, $action, $params = array())
46+
{
47+
$action_url = URL::action($action, $params);
48+
49+
if ($action_url == '')
50+
trigger_error("Action '$action' does not exist");
51+
52+
try {
53+
// The following method returns Synfony's DomCrawler
54+
// but it will not be used when testing controllers
55+
$this->client->request($method, $action_url, array_merge($params, $this->requestInput));
56+
} catch (HttpException $e) {
57+
// Store the HttpException in order to check it later
58+
$this->lastException = $e;
59+
}
60+
61+
return $this; // for method chaining
62+
}
63+
64+
/**
65+
* Set the post parameters and return this for chainable
66+
* method call
67+
*
68+
* @param array $params Post paratemers array.
69+
* @return mixed this.
70+
*/
71+
public function withInput($params)
72+
{
73+
$this->requestInput = $params;
74+
75+
return $this;
76+
}
77+
78+
/**
79+
* Asserts if the status code is correct
80+
*
81+
* @param $code Correct status code
82+
* @return void
83+
*/
84+
public function assertStatusCode($code)
85+
{
86+
if ($this->lastException) {
87+
$realCode = $this->lastException->getStatusCode();
88+
} else {
89+
$realCode = $this->client->getResponse()->getStatusCode();
90+
}
91+
92+
$this->assertEquals($code, $realCode, "Response was not $code, status code was $realCode");
93+
}
94+
95+
/**
96+
* Asserts if the request was Ok (200)
97+
*
98+
* @return void
99+
*/
100+
public function assertRequestOk()
101+
{
102+
$this->assertStatusCode(200);
103+
}
104+
105+
/**
106+
* Asserts if page was redirected correctly
107+
*
108+
* @param $location Location where it should be redirected
109+
* @return void
110+
*/
111+
public function assertRedirection($location = null)
112+
{
113+
$response = $this->client->getResponse();
114+
115+
if ($this->lastException) {
116+
$statusCode = $this->lastException->getStatusCode();
117+
} else {
118+
$statusCode = $response->getStatusCode();
119+
}
120+
121+
$isRedirection = in_array($statusCode, array(201, 301, 302, 303, 307, 308));
122+
123+
$this->assertTrue($isRedirection, "Last request was not a redirection. Status code was " . $statusCode);
124+
125+
if ($location) {
126+
if (!strpos($location, '://'))
127+
$location = 'http://:' . $location;
128+
129+
$this->assertEquals($this->cleanTrailingSlash($location), $this->cleanTrailingSlash($response->headers->get('Location')), 'Page was not redirected to the correct place');
130+
}
131+
132+
}
133+
134+
/**
135+
* Asserts if the session variable is correct
136+
*
137+
* @param string $name Session variable name.
138+
* @param mixed $value Session variable value.
139+
* @return void.
140+
*/
141+
public function assertSessionHas($name, $value = null)
142+
{
143+
$this->assertTrue(Session::has($name), "Session doesn't contain '$name'");
144+
145+
if ($value) {
146+
$this->assertContains($value, Session::get($name), "Session '$name' are not equal to $value");
147+
}
148+
}
149+
150+
public function assertEqualsUrlPath($url, $value = null)
151+
{
152+
$path = parse_url($url, PHP_URL_PATH);
153+
$pathWithoutSlash = substr($path, 1);
154+
$this->assertEquals($pathWithoutSlash, $value);
155+
}
156+
157+
public function cleanTrailingSlash($string)
158+
{
159+
if (substr($string, -1) == '/') {
160+
$string = substr($string, 0, -1);
161+
}
162+
163+
return $string;
164+
}
165+
}

app/views/admin/layouts/default.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
<div class="clearfix"></div>
187187
<footer>
188188
<p>
189-
<span style="text-align:left;float:left">&copy; 2013 <a href="#">A2Z CMS</a></span>
189+
<span style="text-align:left;float:left">&copy; 2013-<?=date("Y")?> <a href="#">A2Z CMS</a></span>
190190
<span class="hidden-phone" style="text-align:right;float:right">Powered by: <a href="http://laravel.com/" alt="Laravel 4">Laravel 4</a></span>
191191
</p>
192192

app/views/site/layouts/default.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<div class="row">
5858
<div class="col-lg-12">
5959
<span style="text-align:left;float:left">
60-
&copy; 2013 <a class="a2zcms" href="#">A2Z CMS</a></span>
60+
&copy; 2013-<?=date("Y")?> <a class="a2zcms" href="#">A2Z CMS</a></span>
6161
<span style="text-align: center;padding-left: 30%">{{$copyright}}</span>
6262
<span style="text-align:right;float:right">
6363
Powered by: <a class="a2zcms" href="http://laravel.com/" alt="Laravel 4">Laravel 4</a></span>

0 commit comments

Comments
 (0)