Example #1
0
 public function testVersionAPI()
 {
     $broker = new APIBroker("VersionAPI");
     $result = $broker->run(null, null);
     $this->assertEquals(APIResult::STATUS_CALL_OK, $result->status, "Result status check failed");
     $this->assertEquals(PT::VERSION, $result->content->version, "Version check failed");
     $this->assertEquals(PT::DB_LEVEL, $result->content->level, "API level check failed");
 }
 public function getInexistentLabel()
 {
     $broker = new APIBroker("CashRegistersAPI");
     $result = $broker->run("get", array("label" => "junk"));
     $this->assertEquals(APIResult::STATUS_CALL_OK, $result->status, "Result status check failed");
     $content = $result->content;
     $this->assertNull($content, "Content is not null");
 }
 public function testGetAll()
 {
     $broker = new APIBroker(AttributesAPITest::API);
     // Get it through API
     $result = $broker->run("getAll", array());
     $this->assertEquals(APIResult::STATUS_CALL_OK, $result->status, "Result status check failed");
     $content = $result->content;
     $this->assertNotNull($content, "Content is null");
     $this->assertTrue(is_array($content), "Content is not an array");
     $this->markTestIncomplete("Check content");
 }
Example #4
0
 public function testGetAll()
 {
     $broker = new APIBroker(TaxesAPITest::API);
     $result = $broker->run("getAll", null);
     $this->assertEquals(APIResult::STATUS_CALL_OK, $result->status, "Result status check failed");
     $content = $result->content;
     $this->assertNotNull($content, "Content is null");
     $this->assertTrue(is_array($content), "Content is not an array");
     $this->assertEquals(2, count($content), "Content size mismatch");
     $this->markTestIncomplete("Check content");
 }
 public function testGet()
 {
     $broker = new APIBroker(ResourcesAPITest::API);
     $result = $broker->run("get", array("label" => "Window.Logo"));
     $this->assertEquals(APIResult::STATUS_CALL_OK, $result->status, "Result status check failed");
     $content = $result->content;
     $this->assertNotNull($content, "Content is null");
     $this->assertEquals("9", $content->id, "Id mismatch");
     $this->assertEquals("Window.Logo", $content->label, "Label mismatch");
     $this->assertEquals(1, $content->type, "Type mismatch");
     $this->assertNotNull($content->content, "Content is null");
     $this->markTestIncomplete("Test content");
 }
 public function testGetAll()
 {
     $prof = new DiscountProfile("Profile", 0.1);
     $srv = new DiscountProfilesService();
     $prof->id = $srv->create($prof);
     $prof2 = new DiscountProfile("Profile2", 0.5);
     $prof2->id = $srv->create($prof2);
     $broker = new APIBroker(DiscountProfilesAPITest::API);
     $result = $broker->run("getAll", null);
     $this->assertEquals(APIResult::STATUS_CALL_OK, $result->status, "Result status check failed");
     $content = $result->content;
     $this->assertNotNull($content, "Content is null");
     $this->assertTrue(is_array($content), "Content is not an array");
     $this->assertEquals(2, count($content), "Content size mismatch");
     $toCheck = array($prof, $prof2);
     $count = 0;
     foreach ($content as $rprof) {
         $ref = null;
         $count++;
         if ($rprof->id == $prof->id) {
             $ref = $prof;
         } else {
             if ($rprof->id == $prof2->id) {
                 $ref = $prof2;
             }
         }
         $this->assertNotNull($ref, "Unknown profile");
         $this->checkEquality($ref, $rprof);
         for ($i = 0; $i < count($toCheck); $i++) {
             $t = $toCheck[$i];
             if ($t->id == $ref->id) {
                 array_splice($toCheck, $i, 1);
                 break;
             }
         }
     }
     $this->assertEquals(0, count($toCheck), "Duplicated profiles");
 }
 public function testGetAll()
 {
     $broker = new APIBroker(LocationsAPITest::API);
     $result = $broker->run("getAll", null);
     $this->assertEquals(APIResult::STATUS_CALL_OK, $result->status, "Result status check failed");
     $content = $result->content;
     $this->assertNotNull($content, "Content is null");
     $this->assertTrue(is_array($content), "Content is not an array");
     $this->assertEquals(2, count($content), "Content size mismatch");
     foreach ($content as $loc) {
         if ($loc->id == $this->locations[0]->id) {
             $ref = $this->locations[0];
         } else {
             if ($loc->id == $this->locations[1]->id) {
                 $ref = $this->locations[1];
             } else {
                 $this->assertTrue(false, "Unknown location id returned");
             }
         }
         $this->assertEquals($loc->id, $ref->id, "Id mismatch");
         $this->assertEquals($loc->label, $ref->label, "Label mismatch");
     }
 }
 public function testGetAll()
 {
     $broker = new APIBroker(CompositionsAPITest::API);
     $result = $broker->run("getAll", null);
     $this->assertEquals(APIResult::STATUS_CALL_OK, $result->status, "Result status check failed");
     $content = $result->content;
     $this->assertNotNull($content, "Content is null");
     $this->assertTrue(is_array($content), "Content is not an array");
     $this->assertEquals(count($this->compositions), count($content), "Content size mismatch");
     foreach ($content as $cmp) {
         $refCmp = null;
         foreach ($this->compositions as $rcmp) {
             if ($cmp->id == $rcmp->id) {
                 $refCmp = $cmp;
                 break;
             }
         }
         $this->assertNotNull($refCmp, "Unknown composition");
         $this->checkEquality($refCmp, $cmp);
     }
 }
Example #9
0
 public function testDelShared()
 {
     $tkt = new SharedTicket("Shared", $this->custId, 1, $this->areaId, $this->discountProfileId, 13.37);
     $tkt->id = TicketsService::createSharedTicket($tkt, array());
     $broker = new APIBroker(TicketsAPITest::API);
     $result = $broker->run("delShared", array("id" => $tkt->id));
     $this->assertEquals(APIResult::STATUS_CALL_OK, $result->status, "Result status check failed");
     $content = $result->content;
     $this->assertTrue($content, "Content is not true");
     $this->assertNull(TicketsService::getSharedTicket($tkt->id), "Shared ticket is still there");
 }
 public function testCreate()
 {
     $broker = new APIBroker(CustomersAPITest::API);
     $srv = new CustomersService();
     $cust = new Customer(null, "Cust", "It's me", "card", null, null, 12.0, 10.0, 5.0, stdtimefstr("2012-01-01 00:00:00"), "It's", "me", "*****@*****.**", "012345", "23456", "11111", "Address1", "Address2", "59000", "City", "Region", "France", "Note", true);
     unset($cust->id);
     $result = $broker->run("save", array("customer" => json_encode($cust)));
     $this->assertEquals(APIResult::STATUS_CALL_OK, $result->status, "Result status check failed");
     $content = $result->content;
     $id = $content['saved'][0];
     $cust->id = $id;
     $this->assertNotNull($content, "Result not found");
     $read = $srv->get($id);
     $this->checkCustEquality($cust, $read);
 }
Example #11
0
    if (isset($_GET['action'])) {
        $action = $_GET['action'];
    } else {
        $action = null;
    }
} else {
    if (isset($_POST[PT::URL_ACTION_PARAM])) {
        if ($config['debug'] === true) {
            trigger_error(serialize($_POST));
        }
        $api = $_POST[PT::URL_ACTION_PARAM];
        $params = $_POST;
        if (isset($_POST['action'])) {
            $action = $_POST['action'];
        } else {
            $action = null;
        }
    } else {
        $api = null;
    }
}
$broker = new APIBroker($api);
$result = $broker->run($action, $params);
if ($api == "ImagesAPI") {
    // Special case of images api with binary data
    header("Cache-Control: max-age=864000");
    echo $result;
} else {
    header("Content type: application/json");
    echo json_encode($result);
}
Example #12
0
 /** @depends testConstructEmpty
  * @depends testAPIResult
  */
 public function testDummyFailParam()
 {
     $broker = new APIBroker("DummyAPI");
     $result = $broker->run("param", array("result" => "fail"));
     $this->assertEquals(APIResult::STATUS_CALL_ERROR, $result->status, "Fail status failed");
     $this->assertEquals("I'm Dummy!", $result->content, "Fail content failed");
 }
Example #13
0
 public function testUpdate()
 {
     $broker = new APIBroker("CashesAPI");
     $srv = new CashesService();
     $cash = $srv->add($this->cashRegisterId);
     $cash->openDate = stdtimefstr("2002-02-02 02:02:02");
     $cash->closeDate = stdtimefstr("2002-02-03 03:03:03");
     $cash->openCash = 1.0;
     $cash->closeCash = 13.0;
     $cash->expectedCash = 15.0;
     $result = $broker->run("update", array("cash" => json_encode($cash)));
     $this->assertEquals(APIResult::STATUS_CALL_OK, $result->status, "Result status check failed");
     $content = $result->content;
     $this->assertNotNull($content, "Content is null");
     $this->assertEquals($cash->id, $content->id, "Id mismatch");
     $this->assertEquals($cash->cashRegisterId, $content->cashRegisterId, "Cash register id mismatch");
     $this->assertEquals($cash->sequence, $content->sequence, "Sequence mismatch");
     $this->assertEquals($cash->openDate, $content->openDate, "Open date mismatch");
     $this->assertEquals($cash->closeDate, $content->closeDate, "Close date mismatch");
     $this->assertEquals($cash->openCash, $content->openCash, "Open cash mismatch");
     $this->assertEquals($cash->closeCash, $content->closeCash, "Close cash mismatch");
     $this->assertEquals($cash->expectedCash, $content->expectedCash, "Expected cash mismatch");
 }
Example #14
0
 public function testGetAllInexistent()
 {
     $broker = new APIBroker(StocksAPITest::API);
     $result = $broker->run("getAll", array("locationId" => "junk"));
     $this->assertEquals(APIResult::STATUS_CALL_OK, $result->status, "Result status check failed");
     $content = $result->content;
     $this->assertNull($content, "Content is null with junk id");
 }