Skip to content

Commit 3e3ee87

Browse files
committed
Merge branch 'develop' of github.com:laravel/laravel into develop
2 parents d64d6c9 + 0950081 commit 3e3ee87

File tree

7 files changed

+329
-18
lines changed

7 files changed

+329
-18
lines changed

laravel/auth/drivers/driver.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ public function logout()
127127
$this->cookie($this->recaller(), null, -2000);
128128

129129
Session::forget($this->token());
130+
131+
$this->token = null;
130132
}
131133

132134
/**

laravel/database/eloquent/model.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ public function get_dirty()
528528

529529
foreach ($this->attributes as $key => $value)
530530
{
531-
if ( ! isset($this->original[$key]) or $value !== $this->original[$key])
531+
if ( ! array_key_exists($key, $this->original) or $value != $this->original[$key])
532532
{
533533
$dirty[$key] = $value;
534534
}
@@ -544,7 +544,7 @@ public function get_dirty()
544544
*/
545545
public function get_key()
546546
{
547-
return $this->get_attribute(static::$key);
547+
return array_get($this->original, static::$key);
548548
}
549549

550550
/**
@@ -721,7 +721,7 @@ public function __isset($key)
721721
{
722722
if (array_key_exists($key, $this->$source)) return true;
723723
}
724-
724+
725725
if (method_exists($this, $key)) return true;
726726
}
727727

laravel/laravel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137

138138
foreach ($languages as $language)
139139
{
140-
if (starts_with($uri, $language))
140+
if (preg_match("#^{$language}(?:$|/)#i", $uri))
141141
{
142142
Config::set('application.language', $language);
143143

laravel/str.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,22 @@ class Str {
99
*/
1010
public static $pluralizer;
1111

12-
/**
13-
* Get the default string encoding for the application.
14-
*
15-
* This method is simply a short-cut to Config::get('application.encoding').
16-
*
17-
* @return string
18-
*/
19-
public static function encoding()
20-
{
21-
return Config::get('application.encoding');
22-
}
12+
/**
13+
* Cache application encoding locally to save expensive calls to Config::get().
14+
*
15+
* @var string
16+
*/
17+
public static $encoding = null;
18+
19+
/**
20+
* Get the appliction.encoding without needing to request it from Config::get() each time.
21+
*
22+
* @return string
23+
*/
24+
protected static function encoding()
25+
{
26+
return static::$encoding ?: static::$encoding = Config::get('application.encoding');
27+
}
2328

2429
/**
2530
* Get the length of a string.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
class Model extends Laravel\Database\Eloquent\Model {
4+
5+
public function set_setter($setter)
6+
{
7+
$this->set_attribute('setter', 'setter: '.$setter);
8+
}
9+
10+
public function get_getter()
11+
{
12+
return 'getter: '.$this->get_attribute('getter');
13+
}
14+
15+
}

laravel/tests/cases/auth.test.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,6 @@ public function testLogoutMethodLogsOutUser()
294294

295295
Auth::logout();
296296

297-
// A workaround since Cookie will is only stored in memory, until Response class is called.
298-
Auth::driver()->token = null;
299-
300297
$this->assertNull(Auth::user());
301298

302299
$this->assertFalse(isset(Session::$instance->session['data']['laravel_auth_drivers_fluent_login']));

laravel/tests/cases/eloquent.test.php

Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
<?php
2+
3+
class EloquentTest extends PHPUnit_Framework_TestCase {
4+
5+
/**
6+
* Test the Model constructor.
7+
*
8+
* @group laravel
9+
*/
10+
public function testAttributesAreSetByConstructor()
11+
{
12+
$array = array('name' => 'Taylor', 'age' => 25, 'setter' => 'foo');
13+
14+
$model = new Model($array);
15+
16+
$this->assertEquals('Taylor', $model->name);
17+
$this->assertEquals(25, $model->age);
18+
$this->assertEquals('setter: foo', $model->setter);
19+
}
20+
21+
/**
22+
* Test the Model::fill method.
23+
*
24+
* @group laravel
25+
*/
26+
public function testAttributesAreSetByFillMethod()
27+
{
28+
$array = array('name' => 'Taylor', 'age' => 25, 'setter' => 'foo');
29+
30+
$model = new Model();
31+
$model->fill($array);
32+
33+
$this->assertEquals('Taylor', $model->name);
34+
$this->assertEquals(25, $model->age);
35+
$this->assertEquals('setter: foo', $model->setter);
36+
}
37+
38+
/**
39+
* Test the Model::fill_raw method.
40+
*
41+
* @group laravel
42+
*/
43+
public function testAttributesAreSetByFillRawMethod()
44+
{
45+
$array = array('name' => 'Taylor', 'age' => 25, 'setter' => 'foo');
46+
47+
$model = new Model();
48+
$model->fill_raw($array);
49+
50+
$this->assertEquals($array, $model->attributes);
51+
}
52+
53+
/**
54+
* Test the Model::fill method with accessible.
55+
*
56+
* @group laravel
57+
*/
58+
public function testAttributesAreSetByFillMethodWithAccessible()
59+
{
60+
Model::$accessible = array('name', 'age');
61+
62+
$array = array('name' => 'Taylor', 'age' => 25, 'foo' => 'bar');
63+
64+
$model = new Model();
65+
$model->fill($array);
66+
67+
$this->assertEquals('Taylor', $model->name);
68+
$this->assertEquals(25, $model->age);
69+
$this->assertNull($model->foo);
70+
71+
Model::$accessible = null;
72+
}
73+
74+
/**
75+
* Test the Model::fill method with empty accessible array.
76+
*
77+
* @group laravel
78+
*/
79+
public function testAttributesAreSetByFillMethodWithEmptyAccessible()
80+
{
81+
Model::$accessible = array();
82+
83+
$array = array('name' => 'Taylor', 'age' => 25, 'foo' => 'bar');
84+
85+
$model = new Model();
86+
$model->fill($array);
87+
88+
$this->assertEquals(array(), $model->attributes);
89+
$this->assertNull($model->name);
90+
$this->assertNull($model->age);
91+
$this->assertNull($model->foo);
92+
93+
Model::$accessible = null;
94+
}
95+
96+
/**
97+
* Test the Model::fill_raw method with accessible.
98+
*
99+
* @group laravel
100+
*/
101+
public function testAttributesAreSetByFillRawMethodWithAccessible()
102+
{
103+
Model::$accessible = array('name', 'age');
104+
105+
$array = array('name' => 'taylor', 'age' => 25, 'setter' => 'foo');
106+
107+
$model = new Model();
108+
$model->fill_raw($array);
109+
110+
$this->assertEquals($array, $model->attributes);
111+
112+
Model::$accessible = null;
113+
}
114+
115+
/**
116+
* Test the Model::__set method.
117+
*
118+
* @group laravel
119+
*/
120+
public function testAttributeMagicSetterMethodChangesAttribute()
121+
{
122+
Model::$accessible = array('setter');
123+
124+
$array = array('setter' => 'foo', 'getter' => 'bar');
125+
126+
$model = new Model($array);
127+
$model->setter = 'bar';
128+
$model->getter = 'foo';
129+
130+
$this->assertEquals('setter: bar', $model->get_attribute('setter'));
131+
$this->assertEquals('foo', $model->get_attribute('getter'));
132+
133+
Model::$accessible = null;
134+
}
135+
136+
/**
137+
* Test the Model::__get method.
138+
*
139+
* @group laravel
140+
*/
141+
public function testAttributeMagicGetterMethodReturnsAttribute()
142+
{
143+
$array = array('setter' => 'foo', 'getter' => 'bar');
144+
145+
$model = new Model($array);
146+
147+
$this->assertEquals('setter: foo', $model->setter);
148+
$this->assertEquals('getter: bar', $model->getter);
149+
}
150+
151+
/**
152+
* Test the Model::set_* method.
153+
*
154+
* @group laravel
155+
*/
156+
public function testAttributeSetterMethodChangesAttribute()
157+
{
158+
Model::$accessible = array('setter');
159+
160+
$array = array('setter' => 'foo', 'getter' => 'bar');
161+
162+
$model = new Model($array);
163+
$model->set_setter('bar');
164+
$model->set_getter('foo');
165+
166+
$this->assertEquals('setter: bar', $model->get_attribute('setter'));
167+
$this->assertEquals('foo', $model->get_attribute('getter'));
168+
169+
Model::$accessible = null;
170+
}
171+
172+
/**
173+
* Test the Model::get_* method.
174+
*
175+
* @group laravel
176+
*/
177+
public function testAttributeGetterMethodReturnsAttribute()
178+
{
179+
$array = array('setter' => 'foo', 'getter' => 'bar');
180+
181+
$model = new Model($array);
182+
183+
$this->assertEquals('setter: foo', $model->get_setter());
184+
$this->assertEquals('getter: bar', $model->get_getter());
185+
}
186+
187+
/**
188+
* Test determination of dirty/changed attributes.
189+
*
190+
* @group laravel
191+
*/
192+
public function testDeterminationOfChangedAttributes()
193+
{
194+
$array = array('name' => 'Taylor', 'age' => 25, 'foo' => null);
195+
196+
$model = new Model($array, true);
197+
$model->name = 'Otwell';
198+
$model->new = null;
199+
200+
$this->assertTrue($model->changed('name'));
201+
$this->assertFalse($model->changed('age'));
202+
$this->assertFalse($model->changed('foo'));
203+
$this->assertFalse($model->changed('new'));
204+
$this->assertTrue($model->dirty());
205+
$this->assertEquals(array('name' => 'Otwell', 'new' => null), $model->get_dirty());
206+
207+
$model->sync();
208+
209+
$this->assertFalse($model->changed('name'));
210+
$this->assertFalse($model->changed('age'));
211+
$this->assertFalse($model->changed('foo'));
212+
$this->assertFalse($model->changed('new'));
213+
$this->assertFalse($model->dirty());
214+
$this->assertEquals(array(), $model->get_dirty());
215+
}
216+
217+
/**
218+
* Test the Model::purge method.
219+
*
220+
* @group laravel
221+
*/
222+
public function testAttributePurge()
223+
{
224+
$array = array('name' => 'Taylor', 'age' => 25);
225+
226+
$model = new Model($array);
227+
$model->name = 'Otwell';
228+
$model->age = 26;
229+
230+
$model->purge('name');
231+
232+
$this->assertFalse($model->changed('name'));
233+
$this->assertNull($model->name);
234+
$this->assertTrue($model->changed('age'));
235+
$this->assertEquals(26, $model->age);
236+
$this->assertEquals(array('age' => 26), $model->get_dirty());
237+
}
238+
239+
/**
240+
* Test the Model::table method.
241+
*
242+
* @group laravel
243+
*/
244+
public function testTableMethodReturnsCorrectName()
245+
{
246+
$model = new Model();
247+
$this->assertEquals('models', $model->table());
248+
249+
Model::$table = 'table';
250+
$this->assertEquals('table', $model->table());
251+
252+
Model::$table = null;
253+
$this->assertEquals('models', $model->table());
254+
}
255+
256+
/**
257+
* Test the Model::to_array method.
258+
*
259+
* @group laravel
260+
*/
261+
public function testConvertingToArray()
262+
{
263+
Model::$hidden = array('password', 'hidden');
264+
265+
$array = array('name' => 'Taylor', 'age' => 25, 'password' => 'laravel', 'null' => null);
266+
267+
$model = new Model($array);
268+
269+
$first = new Model(array('first' => 'foo', 'password' => 'hidden'));
270+
$second = new Model(array('second' => 'bar', 'password' => 'hidden'));
271+
$third = new Model(array('third' => 'baz', 'password' => 'hidden'));
272+
273+
$model->relationships['one'] = new Model(array('foo' => 'bar', 'password' => 'hidden'));
274+
$model->relationships['many'] = array($first, $second, $third);
275+
$model->relationships['hidden'] = new Model(array('should' => 'visible'));
276+
$model->relationships['null'] = null;
277+
278+
$this->assertEquals(array(
279+
'name' => 'Taylor', 'age' => 25, 'null' => null,
280+
'one' => array('foo' => 'bar'),
281+
'many' => array(
282+
array('first' => 'foo'),
283+
array('second' => 'bar'),
284+
array('third' => 'baz'),
285+
),
286+
'hidden' => array('should' => 'visible'),
287+
'null' => null,
288+
), $model->to_array());
289+
290+
}
291+
292+
}

0 commit comments

Comments
 (0)