/** * Tests Category deletion * @test * @depends editCategory */ public function deleteCategory($category_id) { $_POST = array('action' => 'delete', 'category_id' => $category_id, 'task' => 'category'); ob_start(); $this->api_controller->index(); $contents = json_decode(ob_get_clean()); $this->assertEquals(0, $contents->error->code, $contents->error->message); }
/** * Tests fetching of locations by location id */ public function testGetLocationsByLocationId() { // Get a random location $location_id = testutils::get_random_id('location'); // Parameters to submit $_GET = array('task' => 'locations', 'by' => 'locid', 'id' => $location_id); ob_start(); $this->api_controller->index(); $contents = json_decode(ob_get_clean()); $this->assertEquals("0", $contents->error->code); $this->assertEquals($location_id, (int) $contents->payload->locations[0]->location->id); }
/** * Test report deletion. * @test * @depends editReport */ public function deleteReport($report_id) { $_POST = array('action' => 'delete', 'incident_id' => $report_id, 'task' => 'reports'); ob_start(); $this->api_controller->index(); $contents = json_decode(ob_get_clean()); $this->assertEquals(0, $contents->error->code, $contents->error->message); }
public function testGetIncidentsByMaxId() { // Get random incident id - it must be active and should not be first record in the table $incident_id = testutils::get_random_id('incident', 'WHERE incident_active = 1 AND id NOT IN(SELECT * FROM (SELECT id from incident where incident_active = 1 ORDER BY id ASC LIMIT 1) as first_id)'); // HTTP GET data $_GET = array('task' => 'incidents', 'by' => 'maxid', 'id' => $incident_id); ob_start(); $this->api_controller->index(); $contents = json_decode(ob_get_clean()); // Test for successful execution $this->assertEquals("0", $contents->error->code); // Get random index for the payload data $index = rand(0, count($contents->payload->incidents) - 1); // Fetched incidents should have an id less than or equal to the search parameter $this->assertLessThanOrEqual($incident_id, (int) $contents->payload->incidents[$index]->incident->incidentid); }
/** * Tests fetching countries by country ID * @test */ public function testGetCountryById() { // Test fetching by ISO code $country = ORM::factory('country', testutils::get_random_id('country')); // Test fetching countries by database id $_GET = array('task' => 'countries', 'by' => 'countryid', 'id' => $country->id); // Fetch the content ob_start(); $this->api_controller->index(); $contents = json_decode(ob_get_clean()); $this->assertEquals($country->id, $contents->payload->countries[0]->country->id); $this->assertEquals(0, (int) $contents->error->code); // Test "No Data Found" // Test using invalid country id $_GET['id'] = 'PL'; ob_start(); $this->api_controller->index(); $contents = json_decode(ob_get_clean()); $this->assertEquals("007", $contents->error->code); }