Commit 91d9eb11 authored by Karamel's avatar Karamel
Browse files

Remove pre-v8 tests.

parent 1be68138
<?php
// Pasteque server testing
//
// Copyright (C)
// 2012 Scil (http://scil.coop)
// 2017 Karamel, Association Pastèque (karamel@creativekara.fr, https://pasteque.org)
//
// This file is part of Pasteque.
//
// Pasteque is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pasteque is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pasteque. If not, see <http://www.gnu.org/licenses/>.
namespace Pasteque;
require_once(dirname(dirname(__FILE__)) . "/common_load.php");
class APIEngineTest extends \PHPUnit_Framework_TestCase {
public static function setUpBeforeClass() {
}
protected function tearDown() {
}
public static function tearDownAfterClass() {
}
public function testConstructEmpty() {
$broker = new APIBroker("api");
$this->assertEquals("api", $broker->getAPIName());
}
public function testAPIResult() {
$result = APIResult::success("content");
$this->assertEquals(APIResult::STATUS_CALL_OK, $result->status,
"Success result status failed");
$this->assertEquals("content", $result->content,
"Success result content failed");
$result = APIResult::reject("content");
$this->assertEquals(APIResult::STATUS_CALL_REJECTED, $result->status,
"Rejected result status failed");
$this->assertEquals("content", $result->content,
"Rejected result content failed");
$result = APIResult::fail("content");
$this->assertEquals(APIResult::STATUS_CALL_ERROR, $result->status,
"Fail result status failed");
$this->assertEquals("content", $result->content,
"Fail result content failed");
}
/** @depends testConstructEmpty
* @depends testAPIResult
*/
public function testNullAPI() {
$broker = new APIBroker(null);
$result = $broker->run("action", null);
$this->assertEquals(APIResult::STATUS_CALL_REJECTED, $result->status,
"Rejected status failed");
$this->assertEquals(APIError::$REJ_WRONG_API, $result->content,
"Rejected content failed");
}
/** @depends testConstructEmpty
* @depends testAPIResult
*/
public function testInexistentAPI() {
$broker = new APIBroker("You_won_t_find_me");
$result = $broker->run("action", null);
$this->assertEquals(APIResult::STATUS_CALL_REJECTED, $result->status,
"Rejected status failed");
$this->assertEquals(APIError::$REJ_WRONG_API, $result->content,
"Rejected content failed");
}
/** @depends testConstructEmpty
* @depends testAPIResult
*/
public function testDummyReject() {
$broker = new APIBroker("DummyAPI");
$result = $broker->run("Reject me", null);
$this->assertEquals(APIResult::STATUS_CALL_REJECTED, $result->status,
"Rejected status failed");
$this->assertEquals(APIError::$REJ_WRONG_PARAMS, $result->content,
"Rejected content failed");
}
/** @depends testConstructEmpty
* @depends testAPIResult
*/
public function testDummySuccess() {
$broker = new APIBroker("DummyAPI");
$result = $broker->run("succeed", null);
$this->assertEquals(APIResult::STATUS_CALL_OK, $result->status,
"Succeed status failed");
$this->assertEquals("I'm Dummy!", $result->content,
"Succeed content failed");
}
/** @depends testConstructEmpty
* @depends testAPIResult
*/
public function testDummyFail() {
$broker = new APIBroker("DummyAPI");
$result = $broker->run("fail", null);
$this->assertEquals(APIResult::STATUS_CALL_ERROR, $result->status,
"Fail status failed");
$this->assertEquals("I'm Dummy!", $result->content,
"Fail content failed");
}
/** @depends testConstructEmpty
* @depends testAPIResult
*/
public function testDummySuccessParam() {
$broker = new APIBroker("DummyAPI");
$result = $broker->run("param", array("result" => "succeed"));
$this->assertEquals(APIResult::STATUS_CALL_OK, $result->status,
"Succeed status failed");
$this->assertEquals("I'm Dummy!", $result->content,
"Succeed content failed");
}
/** @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");
}
}
?>
\ No newline at end of file
<?php
// Pasteque server testing
//
// Copyright (C)
// 2012 Scil (http://scil.coop)
// 2017 Karamel, Association Pastèque (karamel@creativekara.fr, https://pasteque.org)
//
// This file is part of Pasteque.
//
// Pasteque is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pasteque is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pasteque. If not, see <http://www.gnu.org/licenses/>.
namespace Pasteque;
require_once(dirname(dirname(__FILE__)) . "/common_load.php");
class AttributesAPITest extends \PHPUnit_Framework_TestCase {
const API = "AttributesAPI";
protected function tearDown() {
// Restore database in its empty state
$pdo = PDOBuilder::getPDO();
if ($pdo->exec("DELETE FROM ATTRIBUTEUSE") === false
|| $pdo->exec("DELETE FROM ATTRIBUTESET") === false
|| $pdo->exec("DELETE FROM ATTRIBUTEVALUE") === false
|| $pdo->exec("DELETE FROM ATTRIBUTE") === false) {
echo("[ERROR] Unable to restore db\n");
}
}
public function testGet() {
$broker = new APIBroker(AttributesAPITest::API);
// Init set
$set = new AttributeSet("set");
$attr = new Attribute("attr", 1);
$attr->id = AttributesService::createAttribute($attr);
$val1 = new AttributeValue("value1");
$val2 = new AttributeValue("value2");
$val1->id = AttributesService::createValue($val1, $attr->id);
$val2->id = AttributesService::createValue($val2, $attr->id);
$attr->addValue($val1);
$attr->addValue($val2);
$set->addAttribute($attr);
$set->id = AttributesService::createSet($set);
// Get it through API
$result = $broker->run("get", array("id" => $set->id));
$this->assertEquals(APIResult::STATUS_CALL_OK, $result->status,
"Result status check failed");
$content = $result->content;
$this->assertNotNull($content, "Content is null");
$this->assertEquals($set->id, $content->id, "Set id mismatch");
$this->assertEquals($set->label, $content->label, "Set label mismatch");
$this->assertTrue(is_array($set->attributes),
"Attributes is not an array");
$this->assertEquals(1, count($set->attributes),
"Attribute count mismatch");
$readAttr = $content->attributes[0];
$this->assertEquals($attr->id, $readAttr->id, "Attribute id mismatch");
$this->assertEquals($attr->label, $readAttr->label,
"Attribute label mismatch");
$this->assertEquals($attr->dispOrder, $readAttr->dispOrder,
"Attribute display order mismatch");
$this->assertTrue(is_array($readAttr->values),
"Values is not an array");
$this->assertEquals(2, count($readAttr->values));
$this->markTestIncomplete("Check values (order issue?)");
}
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");
}
}
\ No newline at end of file
<?php
// Pasteque server testing
//
// Copyright (C)
// 2012 Scil (http://scil.coop)
// 2017 Karamel, Association Pastèque (karamel@creativekara.fr, https://pasteque.org)
//
// This file is part of Pasteque.
//
// Pasteque is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pasteque is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pasteque. If not, see <http://www.gnu.org/licenses/>.
namespace Pasteque;
require_once(dirname(dirname(__FILE__)) . "/common_load.php");
class CashRegistersAPITest extends \PHPUnit_Framework_TestCase {
private $location;
protected function setUp() {
$srv = new LocationsService();
$location = new Location("Location");
$location->id = $srv->create($location);
$this->location = $location;
}
protected function tearDown() {
// Restore database in its empty state
$pdo = PDOBuilder::getPDO();
if ($pdo->exec("DELETE FROM CASHREGISTERS") === false
|| $pdo->exec("DELETE FROM LOCATIONS") === false) {
echo("[ERROR] Unable to restore db\n");
}
}
public function testGetById() {
$broker = new APIBroker("CashRegistersAPI");
$srv = new CashRegistersService();
// Init cash register
$cashReg = new CashRegister("Cash", $this->location->id, 1);
$id = $srv->create($cashReg);
// Get it through API
$result = $broker->run("get", array("id" => $id));
$this->assertEquals(APIResult::STATUS_CALL_OK, $result->status,
"Result status check failed");
$content = $result->content;
$this->assertNotNull($content, "Content is null");
$this->assertEquals($id, $content->id, "Id mismatch");
$this->assertEquals($cashReg->label, $content->label, "Label mismatch");
$this->assertEquals($cashReg->locationId, $content->locationId,
"Location id mismatch");
}
public function testGetInexistentId() {
$broker = new APIBroker("CashRegistersAPI");
$result = $broker->run("get", array("id" => "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 getByLabel() {
$broker = new APIBroker("CashRegistersAPI");
$srv = new CashRegistersService();
// Init cash register
$cashReg = new CashRegister("Cash", $this->location->id, 1);
$id = $srv->create($cashReg);
// Get it through API
$result = $broker->run("get", array("label" => $cashReg->label));
$this->assertEquals(APIResult::STATUS_CALL_OK, $result->status,
"Result status check failed");
$content = $result->content;
$this->assertNotNull($content, "Content is null");
$this->assertEquals($id, $content->id, "Id mismatch");
$this->assertEquals($cashReg->label, $content->label, "Label mismatch");
$this->assertEquals($cashReg->locationId, $content->locationId,
"Location id mismatch");
}
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");
}
}
\ No newline at end of file
<?php
// Pasteque server testing
//
// Copyright (C)
// 2012 Scil (http://scil.coop)
// 2017 Karamel, Association Pastèque (karamel@creativekara.fr, https://pasteque.org)
//
// This file is part of Pasteque.
//
// Pasteque is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pasteque is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pasteque. If not, see <http://www.gnu.org/licenses/>.
namespace Pasteque;
require_once(dirname(dirname(__FILE__)) . "/common_load.php");
class CashesAPITest extends \PHPUnit_Framework_TestCase {
private $cashRegisterId;
protected function setUp() {
$srv = new LocationsService();
$location = new Location("Location");
$location->id = $srv->create($location);
$srv = new CashRegistersService();
$cashReg = new CashRegister("CashReg", $location->id, 1);
$this->cashRegisterId = $srv->create($cashReg);
}
protected function tearDown() {
// Restore database in its empty state
$pdo = PDOBuilder::getPDO();
if ($pdo->exec("DELETE FROM CLOSEDCASH") === false
|| $pdo->exec("DELETE FROM CASHREGISTERS") === false
|| $pdo->exec("DELETE FROM LOCATIONS") === false) {
echo("[ERROR] Unable to restore db\n");
}
}
public function testGetById() {
$broker = new APIBroker("CashesAPI");
$srv = new CashesService();
// Init cash
$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 = 10.0;
$cash->closeCash = 12.0;
$cash->expectedCash = 25.0;
$srv->update($cash);
// Get it through API
$result = $broker->run("get", array("id" => $cash->id));
$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");
}
public function testGetOpenedByCashRegister() {
$broker = new APIBroker("CashesAPI");
$srv = new CashesService();
// Init cash
$cash = $srv->add($this->cashRegisterId);
$cash->openDate = stdtimefstr("2002-02-02 02:02:02");
$cash->openCash = 9.0;
$srv->update($cash);
// Get it through API
$result = $broker->run("get",
array("cashRegisterId" => $cash->cashRegisterId));
$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->openCash, $content->openCash,
"Open cash mismatch");
$this->assertEquals($cash->closeCash, $content->closeCash,
"Close cash mismatch");
$this->assertEquals($cash->expectedCash, $content->expectedCash,
"Expected cash mismatch");
}
public function testGetClosedByCashRegister() {
$broker = new APIBroker("CashesAPI");
$srv = new CashesService();
// Init cash
$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 = 8.0;
$cash->closeCash = 8.2;
$srv->update($cash);
// Get it through API
$result = $broker->run("get",
array("cashRegisterId" => $cash->cashRegisterId));
$this->assertEquals(APIResult::STATUS_CALL_OK, $result->status,
"Result status check failed");
$content = $result->content;
$this->assertNull($content, "Content is not null");
}
public function testGetInexistentId() {
$broker = new APIBroker("CashesAPI");
$result = $broker->run("get", array("id" => "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 testGetInexistentCashRegister() {
$broker = new APIBroker("CashesAPI");
$result = $broker->run("get", array("cashRegisterId" => "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 testUpdateCreate() {
$broker = new APIBroker("CashesAPI");
$cash = new Cash($this->cashRegisterId, 1,
stdtimefstr("2002-02-02 02:02:02"),
stdtimefstr("2002-02-03 03:03:03"), 7.0, 15.0, 17.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->assertNotNull($content->id, "Id not created");
$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");
}
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");
}
}
\ No newline at end of file
<?php
// Pasteque server testing
//
// Copyright (C)
// 2012 Scil (http://scil.coop)
// 2017 Karamel, Association Pastèque (karamel@creativekara.fr, https://pasteque.org)
//
// This file is part of Pasteque.
//
// Pasteque is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pasteque is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pasteque. If not, see <http://www.gnu.org/licenses/>.
namespace Pasteque;
require_once(dirname(dirname(__FILE__)) . "/common_load.php");
class CategoriesAPITest extends \PHPUnit_Framework_TestCase {
const API = "CategoriesAPI";
protected function tearDown() {
// Restore database in its empty state
$pdo = PDOBuilder::getPDO();
$sql = "DELETE FROM CATEGORIES WHERE PARENTID IS NOT NULL";
if ($pdo->exec($sql) === false) {
echo("[ERROR] Unable to restore db\n");
} else {
$sql2 = "DELETE FROM CATEGORIES";
if ($pdo->exec($sql2) === false) {
echo("[ERROR] Unable to restore db\n");
}
}
}
private function createCat($ref, $parentId, $label, $image, $dispOrder) {
$cat = new Category($ref, $parentId, $label, $image, $dispOrder);
$srv = new CategoriesService();
$id = $srv->createCat($cat);
$cat->id = $id;
return $cat;
}
private function checkCatEquality($expected, $read) {
$this->assertEquals($expected->id, $read->id, "Id mismatch");
$this->assertEquals($expected->reference, $read->reference,