public function testToArray() { $book = new Book(); $title = 'test title'; $author = 'test author'; $book->setTitle($title); $book->setAuthor($author); $result = $book->toArray(); $this->assertTrue(is_array($result)); $this->assertTrue(array_key_exists('id', $result)); $this->assertTrue(isset($result['title'])); $this->assertTrue(isset($result['author'])); $this->assertEquals($title, $result['title']); $this->assertEquals($author, $result['author']); }
/** * Only the create function should work. Other methods should trigger * exceptions indicating those RUD methods are not supported by this * strategy. * * @param array $write_strategies * @param array $read_strategies */ protected function _testGoldenCPath(array $write_strategies, array $read_strategies) { // Create a DAO. $bookDao = new BookDao($write_strategies, $read_strategies); // Make a book and set its properties. $book = new Book(); $title = uniqid(); $author = uniqid(); $book->setTitle($title); $book->setAuthor($author); // Run the "C" create function. $bookDao->create($book); // Ensure a UUID was defined as the id. $this->assertTrue(strlen($book->getId()) == 36); $correctReadExceptionDetected = false; $correctUpdateExceptionDetected = false; $correctDeleteExceptionDetected = false; // Do a "R"ead and ensure everything comes back. try { $returnedBook = $bookDao->read($book->getId()); } catch (\Octopus\Strategy\Exception\InvalidStrategyMethod $e) { $correctReadExceptionDetected = true; } // "U"pdate the record. try { $book->setTitle('foo123'); $bookDao->update($book); } catch (\Octopus\Strategy\Exception\InvalidStrategyMethod $e) { $correctUpdateExceptionDetected = true; } // "R"emove it try { $bookDao->delete($book); } catch (\Octopus\Strategy\Exception\InvalidStrategyMethod $ex) { $correctDeleteExceptionDetected = true; } $this->assertTrue($correctReadExceptionDetected); $this->assertTrue($correctUpdateExceptionDetected); $this->assertTrue($correctDeleteExceptionDetected); }
/** * * @param string $bianHao * @param string $title * @param string $author * @param string $publisher * @param string $publishedDate * @param string $language * @param int $printLength * @param string $ISBN * @param string $price * @param string $description * @param string $imageUrl * @return \Json\Commands\BookResponse */ function AddBook($bianHao, $title, $author, $publisher, $publishedDate, $language, $printLength, $ISBN, $price, $description, $imageUrl) { $response = new BookResponse(); try { $result = $this->doctrinemodel->getRepository('Models\\Book')->findOneBy(array('BianHao' => $bianHao)); if ($result != NULL) { $response->_returnCode = ErrorCode::BianHaoAlreadyExists; } else { $book = new Book($bianHao, $title, $author); $book->setPublisher($publisher); $book->setPublishedDate($publishedDate); $book->setLanguage($language); $book->setPrintLength($printLength); $book->setISBN($ISBN); $book->setPrice($price); $book->SetDescription($description); $this->doctrinemodel->persist($book); $this->doctrinemodel->flush(); // Create a pic on the server side under gtcclibrary/Images // Image name is the ISBN.jpg if (!empty($imageUrl)) { $img = file_get_contents($imageUrl); $imageName = __DIR__ . '/../../Images/' . $ISBN . '.jpg'; if (!file_exists($imageName)) { //echo $imageName; file_put_contents($imageName, $img); } } $response->_returnCode = ErrorCode::OK; $response->book = $book; } } catch (Exception $e) { $response->_returnCode = ErrorCode::Failed; $response->_returnMessage = $e->__toString(); } return $response; }
<?php $app->get('/', function () use($app) { if (isset($_GET['out'])) { unset($_SESSION['logged']); } if (isset($_SESSION['logged'])) { $app->render('home.html', array("logged" => "Logout")); } else { $app->render('home.html', array("notLogged" => "Login")); } }); $app->get('/allBooks', function () use($app) { if ($_SESSION['logged']) { $books = \models\Book::getAll(); $app->render('allBooks.html', array("books" => $books)); } else { $app->render('serverMsg/serverResp.php', array('error_msg' => "in order to see all books you have to login")); } }); $app->post('/home', function () use($app) { $unique = round(microtime(true)); $uploader = new \models\FileUploader($unique); $uploadMessage = $uploader->uploadFile($unique); $title = $_POST['title']; $publish = $_POST['date']; $author = $_POST['author']; $format = $_POST['format']; $count = $_POST['count']; $resume = $_POST['resume']; $isbn = $_POST['isbn'];
public function __construct(\Models\Book $book) { $this->bianhao = $book->GetBianHao(); $this->title = $book->GetTitle(); $this->author = $book->GetAuthor(); $this->publisher = $book->getPublisher(); $this->publishedDate = $book->getPublishedDate(); $this->language = $book->getLanguage(); $this->printLength = $book->getPrintLength(); $this->ISBN = $book->getISBN(); $this->bookDescription = $book->GetDescription(); $this->price = $book->getPrice(); }