Skip to content

Commit e92496c

Browse files
committed
Adding additional check for User::getNextId method. photo#1230
1 parent 1399bbe commit e92496c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/libraries/models/User.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ public function getNextId($type)
139139
$nextIntId = base_convert($user[$key], 31, 10) + 1;
140140
$nextId = base_convert($nextIntId, 10, 31);
141141

142-
$this->update(array($key => $nextId));
142+
$status = $this->update(array($key => $nextId));
143+
if(!$status)
144+
return false;
143145
return $nextId;
144146
}
145147

src/tests/libraries/models/UserTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,26 @@ public function testGetNextIdFailure()
223223
$this->assertFalse($res);
224224
}
225225

226+
public function testGetNextIdUpdateFailure()
227+
{
228+
$db = $this->getMock('Db', array('getUser', 'postUser', 'putUser'));
229+
$db->expects($this->any())
230+
->method('getUser')
231+
->will($this->onConsecutiveCalls(
232+
array('id' => 'test@example.com', 'lastPhotoId' => 'abc'),
233+
array('id' => '', 'lastPhotoId' => '')
234+
));
235+
$db->expects($this->any())
236+
->method('postUser')
237+
->will($this->returnValue(false));
238+
$this->user->inject('db', $db);
239+
240+
// abc
241+
$res = $this->user->getNextId('photo');
242+
$this->assertEquals(false, $res);
243+
}
244+
245+
226246
public function testGetAttributeNameSuccess()
227247
{
228248
$res = $this->user->getAttributeName('foobar');

0 commit comments

Comments
 (0)