Last active
December 17, 2015 08:38
-
-
Save gwoo/5580947 to your computer and use it in GitHub Desktop.
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
<?php | |
namespace app\tests\cases\controllers; | |
use app\controllers\UsersController; | |
use app\models\Users; | |
use lithium\action\Request; | |
use lithium\data\Connections; | |
class UsersControllerTest extends \lithium\test\Integration { | |
private $_data = array( | |
array( | |
"name" => "Bob the Builder" | |
), | |
array( | |
"name" => "Frank the Tank" | |
), | |
array( | |
"name" => "Mack the Truck" | |
) | |
); | |
public function skip() { | |
$isAvailable = ( | |
Connections::get('test', array('config' => true)) && | |
Connections::get('test')->isConnected(array('autoConnect' => true)) | |
); | |
$this->skipIf(!$isAvailable, "No test connection available."); | |
} | |
public function setUp() { | |
Users::config(array('connection' => 'test')); | |
Users::all()->delete(); | |
} | |
public function testAdd() { | |
$request = new Request(array('data' => $this->_data[0])); | |
$Users = new UsersController(compact('request')); | |
$response = $Users($request, array('action' => 'add')); | |
$expected = 201; | |
$result = $response->status('code'); | |
$this->assertEqual($expected, $result); | |
$user = Users::first(); | |
$expected = 'Bob the Builder'; | |
$result = $user->name; | |
$this->assertEqual($expected, $result); | |
} | |
public function testIndex() { | |
$request = new Request(); | |
$Users = new UsersController(compact('request')); | |
$response = $Users($request, array('action' => 'index')); | |
$expected = 400; | |
$result = $response->status('code'); | |
$this->assertEqual($expected, $result); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment