예제 #1
0
     if (empty($requestObject->listingType) === true) {
         throw new InvalidArgumentException("listing type info cannot be empty", 405);
     }
     //perform the actual put or post
     if ($method === "PUT") {
         $listingType = ListingType::getListingTypeById($pdo, $id);
         if ($listingType === null) {
             throw new RuntimeException("Listing type does not exist", 404);
         }
         $listingType = new ListingType($id, $requestObject->listingType);
         $listingType->update($pdo);
         $reply->message = "Listing type updated OK";
     } else {
         if ($method === "POST") {
             $listingType = new ListingType(null, $requestObject->listingType);
             $listingType->insert($pdo);
             $reply->message = "Listing type created OK";
         }
     }
 } else {
     if ($method === "DELETE") {
         //verifyXsrf();
         $listingType = ListingType::getListingTypeById($pdo, $id);
         if ($listingType === null) {
             throw new RuntimeException("Listing type does not exist", 404);
         }
         $listingType->delete($pdo);
         $deletedObject = new stdClass();
         $deletedObject->listingTypeId = $id;
         $reply->message = "Listing type deleted OK";
     }
예제 #2
0
 /**
  * test inserting an organization and regrabbing it from mySQL
  */
 public function testGetValidListingTypeById()
 {
     //count the rows in the database
     $numRows = $this->getConnection()->getRowCount("listingType");
     $listingtype = new ListingType(null, $this->VALID_TYPE);
     $listingtype->insert($this->getPDO());
     //grab data from SQL and ensure it matches
     $pdoListingType = ListingType::getListingTypeById($this->getPDO(), $listingtype->getListingTypeId());
     $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("listingType"));
     $this->assertSame($pdoListingType->getListingTypeInfo(), $this->VALID_TYPE);
 }
 /**
  * test getting all listing Types
  */
 public function testValidGetAll2()
 {
     //test getting by parameter new listing type
     //create a new listing type, and insert into the database
     $listingType = new ListingType(null, $this->VALID_TYPE_2);
     $listingType->insert($this->getPDO());
     $listingType = new ListingType(null, $this->VALID_TYPE);
     $listingType->insert($this->getPDO());
     //send the get request to the API
     $response = $this->guzzle->get('https://bootcamp-coders.cnm.edu/~tfenstermaker/bread-basket/public_html/php/api/listingtype', ['headers' => ['X-XSRF-TOKEN' => $this->token]]);
     //ensure the response was sent, and the api returned a positive status
     $this->assertSame($response->getStatusCode(), 200);
     $body = $response->getBody();
     $retrievedListingType = json_decode($body);
     $this->assertSame(200, $retrievedListingType->status);
     //ensure the response returned a non-empty array
     $this->assertGreaterThan(0, sizeof($retrievedListingType->data->listingTypeId));
 }