public function testUpdateUnit() { $args = array("name" => "anotherUnit"); $response = $this->executeRequest(array("id" => 1, "values" => $args), true); $this->verifyOk($response, 204); $unit = unitQuery::create()->findPk(1); $this->assertEquals("anotherUnit", $unit->getname()); }
public function testCreateUnit() { $args = array("name" => "newUnit"); $response = $this->executeRequest($args, true); $this->verifyOk($response); $result = $response->json(); $created = unitQuery::create()->findPk($result["id"]); $this->assertEquals("newUnit", $created->getname()); }
<?php session_start(); require_once '../../bootstrap.php'; require '../../services/UserService.php'; require '../../services/ForeignService.php'; UserService::withRole(UserService::$CONTRIBUTOR, function () { if (array_key_exists("id", $_GET)) { $unitId = $_GET["id"]; $unit = unitQuery::create()->findPk($unitId); } $force = false; if (array_key_exists("force", $_GET)) { $force = $_GET["force"]; } if (isset($unit)) { try { $databaseName = unitPeer::DATABASE_NAME; $constraints = array("ingredient" => "unitId"); if ($force == true) { ForeignService::forceForeignConstraints($databaseName, $constraints, $unitId, true); $unit->delete(); http_response_code(204); } else { $result = ForeignService::verifyForeignConstraints($databaseName, $constraints, $unitId); if ($result) { $unit->delete(); http_response_code(204); } else { echo json_encode(array("result" => "Cette unité est référencée dans des ingredients de recette.")); }
<?php require_once '../../bootstrap.php'; $query = unitQuery::create()->select(array('id', 'name'))->orderByName()->find(); $data = $query->getData(); echo json_encode($data); ?>