Created
June 30, 2014 05:19
-
-
Save santiblanko/9b72207ccafc0371b2eb to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| class StatesControllerTest extends \Illuminate\Foundation\Testing\TestCase | |
| { | |
| public function createApplication() | |
| { | |
| $unitTesting = true; | |
| $testEnvironment = 'testing'; | |
| return require __DIR__.'/../../../../../../bootstrap/start.php'; | |
| } | |
| public function setUp() | |
| { | |
| parent::setUp(); | |
| $this->app['config']->set('database.default', 'testing'); | |
| $this->app['config']->set('database.connections.testing', array( | |
| 'driver' => 'sqlite', | |
| 'database' => ':memory:', | |
| 'prefix' => '', | |
| )); | |
| Artisan::call('migrate', array( | |
| '--database' => 'testing', | |
| '--bench' => 'blanko/tematic' | |
| )); | |
| $this->seedTables(); | |
| } | |
| public function seedTables() | |
| { | |
| DB::table('mapStates')->insert(array ( | |
| 0 => | |
| array ( | |
| 'id' => 1, | |
| 'description' => 'EN PROGRAMA PAP-PDA', | |
| 'type_id' => 1, | |
| 'created_at' => '0000-00-00 00:00:00', | |
| 'updated_at' => '0000-00-00 00:00:00', | |
| ), | |
| 1 => | |
| array( | |
| 'id' => 2, | |
| 'description' => 'EN ESQUEMA FONDO DE ADAPTACIÓN', | |
| 'type_id' => 2, | |
| 'created_at' => '0000-00-00 00:00:00', | |
| 'updated_at' => '0000-00-00 00:00:00' | |
| ), | |
| 2 => | |
| array ( | |
| 'id' => 3, | |
| 'description' => 'EN ESQUEMA PLAN CARRASQUILLA', | |
| 'type_id' => 1, | |
| 'created_at' => '0000-00-00 00:00:00', | |
| 'updated_at' => '0000-00-00 00:00:00', | |
| ))); | |
| } | |
| public function testIndexAjaxResponseShouldReturnJSON() | |
| { | |
| $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest'); | |
| $response = $this->call('GET', '/genus/1/states'); | |
| $content = $response->getContent(); | |
| $data = json_decode($content); | |
| $this->assertJson($content); | |
| } | |
| public function testIndexAjaxResponseShouldGetStatesWithNullType() | |
| { | |
| $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest'); | |
| $response = $this->call('GET', '/genus/0/states'); | |
| $content = $response->getContent(); | |
| $data = json_decode($content); | |
| $this->assertCount(3, $data); | |
| } | |
| public function testIndexAjaxResponseShouldGetStatesWithNotNullTypeAndTypeIsTwo() | |
| { | |
| $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest'); | |
| $response = $this->call('GET', '/genus/2/states'); | |
| $content = $response->getContent(); | |
| $data = json_decode($content); | |
| $this->assertCount(1, $data); | |
| } | |
| public function testIndexNormalResponseShouldReturnIndex() | |
| { | |
| $this->client->request('GET', '/genus/1/states'); | |
| $this->assertTrue($this->client->getResponse()->isOk()); | |
| } | |
| public function testShowNormalResponseShouldRedirectToIndex() | |
| { | |
| $this->client->request('GET', '/genus/1/states/1'); | |
| $this->assertRedirectedTo('/genus/1/states#/1/municipalities'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment