public function testWeCanCreateABookWithInformation() { $title = 'New Title'; $author = "Author"; $book = new Book($title, $author); $this->assertEquals($title, $book->getTitle()); $this->assertEquals($author, $book->getAuthor()); }
function testGetAuthor() { //Arrange $title = "Grapes of Wrath"; $test_book = new Book($title); $test_book->save(); $first_name = "J.K."; $last_name = "Rowling"; $test_author = new Author($first_name, $last_name); $test_author->save(); $first_name2 = "John"; $last_name2 = "Steinbeck"; $test_author2 = new Author($first_name2, $last_name2); $test_author2->save(); //Act $test_book->addAuthor($test_author); $test_book->addAuthor($test_author2); $result = $test_book->getAuthor(); //Assert $this->assertEquals([$test_author, $test_author2], $result); }
/** * Test the doSelectJoin*() methods when the related object is NULL. */ public function testDoSelectJoin_NullFk() { $b1 = new Book(); $b1->setTitle("Test NULLFK 1"); $b1->setISBN("NULLFK-1"); $b1->save(); $b2 = new Book(); $b2->setTitle("Test NULLFK 2"); $b2->setISBN("NULLFK-2"); $b2->setAuthor(new Author()); $b2->getAuthor()->setFirstName("Hans")->setLastName("L"); $b2->save(); BookPeer::clearInstancePool(); AuthorPeer::clearInstancePool(); $c = new Criteria(); $c->add(BookPeer::ISBN, 'NULLFK-%', Criteria::LIKE); $c->addAscendingOrderByColumn(BookPeer::ISBN); $matches = BookPeer::doSelectJoinAuthor($c); $this->assertEquals(2, count($matches), "Expected 2 matches back from new books; got back " . count($matches)); $this->assertNull($matches[0]->getAuthor(), "Expected first book author to be null"); $this->assertInstanceOf('Author', $matches[1]->getAuthor(), "Expected valid Author object for second book."); }
function locate(Book $book) { // returns the position in the library // ie. shelf number & room number $libraryMap->findBookBy($book->getTitle(), $book->getAuthor()); }
<?php require 'connect.php'; require 'client/Book.php'; require 'client/Employee.php'; require 'client/Client.php'; require 'client/Hire.php'; $book = new Book(1, 'Metro', 'Gluhowsky', 'apokalipsa'); $employee = new Employee(2, 'Jan', 'Kowalski', '*****@*****.**', 'Warszawa'); $client = new Client(3, 'Anna', 'Kowalska', '*****@*****.**'); $hire = new Hire(4, $book, $employee, '2015-12-15', '2015-12-26'); $query = "INSERT INTO `book` (`id`, `title`, `author`, `type`) VALUES ('1', '{$book->getTitle()}', '{$book->getAuthor()}', '{$book->getType()}')"; $libraryRequest = mysql_query($query); $query = "INSERT INTO `employee` (`id`, `firstname`, `lastname`, `email`, `city`) VALUES ('2', '{$employee->getfirstName()}', '{$employee->getlastName()}', '{$employee->getEmail()}', '{$employee->getCity()}')"; $libraryRequest = mysql_query($query); $query = "INSERT INTO `client` (`id`, `firstname`, `lastname`, `email`) VALUES ('3', '{$client->getfirstName()}', '{$client->getlastName()}', '{$client->getEmail()}')"; $libraryRequest = mysql_query($query); $query = "INSERT INTO `hire` (`id`, `id_client`, `id_book`, `id_employee`, `hiredate`, `returndate`) VALUES ('4', '{$client->getId()}', '{$book->getId()}', '{$employee->getId()}', '{$hire->getHireDate()}', '{$hire->getReturnDate()}')"; var_dump($query); $libraryRequest = mysql_query($query);
public function __construct(Book $book) { $this->setId($book->getId())->setTitle($book->getType())->setAuthor($book->getAuthor())->setType($book->getType())->setYear($book->getYear())->setPrice($book->getPrice()); }
function testGetAuthor() { //Arrange $title = "Title"; $id = 1; $test_book = new Book($title, $id); $test_book->save(); $name = "Ping Pong"; $id2 = 1; $test_author = new Author($name, $id2); $test_author->save(); $name2 = "Ding Dong"; $id3 = 2; $test_author2 = new Author($name2, $id3); $test_author2->save(); //Act $test_book->addAuthor($test_author->getId()); $test_book->addAuthor($test_author2->getId()); //Assert $this->assertEquals($test_book->getAuthor(), [$test_author, $test_author2]); }
} $books = new SimpleXMLElement($xmlstr); $aut = $books->book[0]->author; $tit = $books->book[0]->title; $gen = $books->book[0]->genre; $pri = $books->book[0]->price; $pub = $books->book[0]->publish_date; $des = $books->book[0]->description; $b = new Book(); //set with magic method __SET $b->author = $aut; $b->title = $tit; $b->genre = $gen; $b->price = $pri; $b->publish_date = $pub; $b->description = $des; //get with magic method __GET echo "with magic method __GET<br/>"; echo $b->author; echo $b->title; echo $b->genre; echo $b->price; echo $b->publish_date; echo $b->description; echo "<br/>with magic method __CALL<br/>"; echo $b->getAuthor(); echo $b->getTitle(); echo $b->getGenre(); echo $b->getPrice(); echo $b->getPublish_date(); echo $b->getDescription();
function testAddAuthor() { //Arrange $title = "Grapes of Wrath"; $test_book = new Book($title); $test_book->save(); $title2 = "Cannery Row"; $test_book2 = new Book($title2); $test_book2->save(); $author_first = "John"; $author_last = "Steinbeck"; $test_author = new Author($author_first, $author_last); $test_author->save(); //Act $test_book->addAuthor($test_author); //Assert $this->assertEquals($test_book->getAuthor(), [$test_author]); }
function save(Book $book) { $filename = '/documents/' . $book->getTitle() . ' - ' . $book->getAuthor(); file_put_contents($filename, serialize($book)); }
/** * Prints the metadata and prices for an item * @param Item|Book $item an Item (Section mode) or Book (ISBN mode) object * @param int $requiredStatus */ function printItemRow($item, $status = null) { global $app; ?> <tr> <th> <span class="tooltip" style="display: none;"> <img src="<?php echo $item->getImageUrl(); ?> "> <h1><?php echo $item->getTitle(); ?> </h1> <h2><?php echo $item->getAuthor(); ?> </h2> <?php if ($edition = $item->getEdition()) { ?> <div class="edition"><strong>Edition:</strong> <?php echo $edition; ?> </div> <?php } if ($publisher = $item->getPublisher()) { ?> <div class="publisher"><strong>Publisher:</strong> <?php echo $publisher; ?> </div> <?php } if ($isbn = $item->getIsbn()) { ?> <div class="isbn"><strong>ISBN:</strong> <span class="isbn"><?php echo $isbn; ?> </span></div> <?php } ?> </span> <?php $indented = $item->isPackageComponent() || $status === SectionHasItem::BOOKSTORE_RECOMMENDED; $class = $indented ? " packageComponent" : ""; ?> <span class="bookdata <?php echo $class; ?> "> <span class="title"><?php echo $item->getTitle(); ?> </span><br> <?php if ($edition || $item->getAuthor()) { ?> <span class="minimetadata"><?php echo ($edition ? "{$edition}, " : "") . $item->getAuthor(); ?> </span> <?php } ?> <?php // e.g. (Recommended) if ($stat = Item::getStatusText($status)) { ?> <br/><span class="minimetadata"><?php echo $stat; ?> </span> <?php } // sentence about being a package or component if ($description = $item->getDescription($status)) { ?> <br/><span class="minimetadata important"><?php echo $description; ?> </span> <?php } ?> </span> </th> <?php foreach ($item->prices as $v => $p) { if ($p === null) { if ($v === $GLOBALS['results']->bookstore) { ?> <td data-price="-1" class="empty" data-unknown="true">unknown</td> <?php } else { ?> <td data-price="-1" class="empty">—</td> <?php } } else { ?> <td data-price="<?php echo money($p->total); ?> " <?php if ($p->asteriskPrice) { ?> data-used="<?php echo money($p->asteriskPrice); ?> " <?php } ?> data-subtotal="<?php echo money($p->subtotal); ?> " data-shipping="<?php echo money($p->shipping + $p->tax); ?> "> <a href="<?php echo $app->urlFor('redirect', array('url' => '', 'type' => 'single', 'vendor' => $p->vendorName)) . $p->url; ?> " data-confirm="<?php echo $p->getDescription(); ?> "> <?php if ($p->total == 0) { ?> unknown <?php } else { ?> $<?php echo money($p->total); echo $p->asteriskPrice ? '*' : ''; ?> <?php } ?> </a> </td> <?php } ?> <?php } // end: foreach $item->prices ?> </tr> <?php if ($item->getIsPackage()) { $components = Item::getComponents(array($item->getId())); foreach ($components as $c) { printItemRow($c); } } }