-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c239328
commit e91331c
Showing
5 changed files
with
52 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,22 +5,22 @@ | |
* @link https://github.com/paysio/yii-rest-api | ||
* @copyright Copyright (c) 2012 Pays I/O Ltd. (http://pays.io) | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT license | ||
* @package REST_Service_DEMO | ||
* @package REST_Service_Demo | ||
*/ | ||
|
||
/** | ||
* @method array getRenderAttributes(bool $recursive = true) | ||
* @method string getObjectId() | ||
*/ | ||
class RestMockModel extends CModel | ||
class RestUser extends CModel | ||
{ | ||
public $id = 'TEST_ID'; | ||
|
||
public $version = 0.1; | ||
public $email = '[email protected]'; | ||
|
||
public $name = 'Yii REST API'; | ||
public $name = 'Test REST User'; | ||
|
||
public $hidden; | ||
public $password = 'hidden_password'; | ||
|
||
public function __construct() | ||
{ | ||
|
@@ -32,7 +32,7 @@ public function __construct() | |
*/ | ||
public function attributeNames() | ||
{ | ||
return array('id', 'version', 'name', 'hidden'); | ||
return array('id', 'email', 'name', 'password'); | ||
} | ||
|
||
/** | ||
|
@@ -41,10 +41,10 @@ public function attributeNames() | |
public function rules() | ||
{ | ||
return array( | ||
array('version', 'numerical'), | ||
array('name', 'length', 'max' => 244), | ||
array('email', 'email'), | ||
array('name, password', 'length', 'max' => 244), | ||
|
||
array('id,version,name', 'safe', 'on' => 'render'), | ||
array('id, email, name', 'safe', 'on' => 'render'), | ||
); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,36 +10,36 @@ | |
|
||
namespace restTest; | ||
|
||
class RestControllerTest extends AbstractTest | ||
class RestUserTest extends AbstractTest | ||
{ | ||
public function testCreate() | ||
{ | ||
$result = $this->post('/api/rest', array('version' => 0.2)); | ||
$result = $this->post('/api/users', array('email' => '[email protected]')); | ||
$model = json_decode($result['body']); | ||
|
||
$this->assertEquals($model->id, 'TEST_ID'); | ||
$this->assertEquals($model->version, 0.2); | ||
$this->assertEquals($model->email, '[email protected]'); | ||
|
||
$this->assertEquals($result['code'], 201); | ||
|
||
$this->assertContains('api/rest/TEST_ID', $result['location']); | ||
$this->assertNotEmpty($result['location']); | ||
} | ||
|
||
public function testView() | ||
{ | ||
$result = $this->get('/api/rest/TEST_ID'); | ||
$result = $this->get('/api/users/TEST_ID'); | ||
$model = json_decode($result['body']); | ||
$model = $model->model; | ||
|
||
$this->assertEquals($model->id, 'TEST_ID'); | ||
$this->assertEquals($model->version, 0.1); | ||
$this->assertEquals($model->email, '[email protected]'); | ||
$this->assertEquals($model->name, 'Test REST User'); | ||
|
||
$this->assertEquals($result['code'], 200); | ||
} | ||
|
||
public function testIndex() | ||
{ | ||
$result = $this->get('/api/rest'); | ||
$result = $this->get('/api/users'); | ||
$data = json_decode($result['body']); | ||
|
||
$this->assertEquals($data->count, 100); | ||
|
@@ -51,30 +51,34 @@ public function testIndex() | |
|
||
public function testUpdate() | ||
{ | ||
$result = $this->put('/api/rest/TEST_ID', array('version' => '0.3')); | ||
$result = $this->put('/api/users/TEST_ID', array( | ||
'email' => '[email protected]', | ||
'name' => 'Updated Name' | ||
)); | ||
$model = json_decode($result['body']); | ||
|
||
$this->assertEquals($model->id, 'TEST_ID'); | ||
$this->assertEquals($model->version, 0.3); | ||
$this->assertEquals($model->email, '[email protected]'); | ||
$this->assertEquals($model->name, 'Updated Name'); | ||
|
||
$this->assertEquals($result['code'], 200); | ||
} | ||
|
||
public function testError() | ||
{ | ||
$result = $this->put('/api/rest/TEST_ID', array('version' => 'wrong_version')); | ||
$result = $this->put('/api/users/TEST_ID', array('email' => 'wrong_email')); | ||
$model = json_decode($result['body']); | ||
|
||
$this->assertEquals($model->error->type, 'invalid_param_error'); | ||
$this->assertCount(1, $model->error->params); | ||
$this->assertEquals($model->error->params[0]->name, 'version'); | ||
$this->assertEquals($model->error->params[0]->name, 'email'); | ||
|
||
$this->assertEquals($result['code'], 400); | ||
} | ||
|
||
public function testDelete() | ||
{ | ||
$result = $this->delete('/api/rest/TEST_ID'); | ||
$result = $this->delete('/api/users/TEST_ID'); | ||
$model = json_decode($result['body']); | ||
|
||
$this->assertEquals($model->id, 'TEST_ID'); | ||
|