function testGetBookName() { $book_name = "Siddhartha"; $test_book = new Book($book_name); $result = $test_book->getTitle(); $this->assertEquals($book_name, $result); }
public function testFormatALotOfResults() { $nbBooks = 50; $con = Propel::getConnection(BookPeer::DATABASE_NAME); Propel::disableInstancePooling(); $book = new Book(); for ($i = 0; $i < $nbBooks; $i++) { $book->clear(); $book->setTitle('BookTest' . $i); $book->save($con); } $stmt = $con->query('SELECT * FROM book'); $formatter = new PropelOnDemandFormatter(); $formatter->init(new ModelCriteria('bookstore', 'Book')); $books = $formatter->format($stmt); $this->assertTrue($books instanceof PropelOnDemandCollection, 'PropelOnDemandFormatter::format() returns a PropelOnDemandCollection'); $this->assertEquals($nbBooks, count($books), 'PropelOnDemandFormatter::format() returns a collection that counts as many rows as the results in the query'); $i = 0; foreach ($books as $book) { $this->assertTrue($book instanceof Book, 'PropelOnDemandFormatter::format() returns a collection of Model objects'); $this->assertEquals('BookTest' . $i, $book->getTitle(), 'PropelOnDemandFormatter::format() returns the model objects matching the query'); $i++; } Propel::enableInstancePooling(); }
public function testWeCanCreateABookWithInformation() { $title = 'New Title'; $author = "Author"; $book = new Book($title, $author); $this->assertEquals($title, $book->getTitle()); $this->assertEquals($author, $book->getAuthor()); }
function test_getTitle() { $title = "Three Blind Mice"; $id = 1; $test_book = new Book($title, $id); $result = $test_book->getTitle(); $this->assertEquals($title, $result); }
function testUpdate() { $title = "Anathem"; $test_book = new Book($title); $test_book->save(); $new_title = "crypotnomicon"; $test_book->update($new_title); $this->assertEquals($new_title, $test_book->getTitle()); }
function test_getTitle() { //Arrange $title = "America"; $test_book = new Book($title); //Act $result = $test_book->getTitle(); //Assert $this->assertEquals($title, $result); }
function test_getTitle() { //Arrange $title = "Whimsical Fairytales...and other stories"; $genre = "Fantasy"; $test_book = new Book($title, $genre); //Act $result = $test_book->getTitle(); //Assert $this->assertEquals($title, $result); }
public function testUtf8() { $db = Propel::getDB(BookPeer::DATABASE_NAME); $title = "Смерть на брудершафт. Младенец и черт"; // 1234567890123456789012345678901234567 // 1 2 3 $a = new Author(); $a->setFirstName("Б."); $a->setLastName("АКУНИН"); $p = new Publisher(); $p->setName("Детектив российский, остросюжетная проза"); $b = new Book(); $b->setTitle($title); $b->setISBN("B-59246"); $b->setAuthor($a); $b->setPublisher($p); $b->save(); $b->reload(); $this->assertEquals(37, iconv_strlen($b->getTitle(), 'utf-8'), "Expected 37 characters (not bytes) in title."); $this->assertTrue(strlen($b->getTitle()) > iconv_strlen($b->getTitle(), 'utf-8'), "Expected more bytes than characters in title."); }
function testUpdate() { //Arrange $title = "Little Cat"; $id = 1; $test_book = new Book($title, $id); $test_book->save(); $new_title = "Big Cat"; //Act $test_book->update($new_title); //Assert $this->assertEquals("Big Cat", $test_book->getTitle()); }
function testUpdate() { //Arrange $title = "Harry Potter"; $id = 1; $test_book = new Book($title, $id); $test_book->save(); $new_title = "Moby Dick"; //Act $test_book->update($new_title); //Assert $this->assertEquals("Moby Dick", $test_book->getTitle()); }
<?php ini_set('display_errors', '1'); function __autoload($class_name) { set_include_path('class'); include_once $class_name . '.php'; } // client writeln('BEGIN TESTING FACADE PATTERN'); writeln(''); $book = new Book('Design Patterns', 'Gamma, Helm, Johnson, and Vlissides'); writeln('Original book title: ' . $book->getTitle()); writeln(''); $bookTitleReversed = CaseReverseFacade::reverseStringCase($book->getTitle()); writeln('Reversed book title: ' . $bookTitleReversed); writeln(''); writeln('END TESTING FACADE PATTERN'); function writeln($line_in) { echo $line_in . "<br/>"; }
} public function getAuthors() { return $this->related(new Author()); } } class Author extends RedBean_DomainObject { public function setName($name) { $this->bean->name = $name; } public function getName() { return $this->bean->name; } } $book = new Book(); $author = new Author(); $book->setTitle("A can of beans"); $author->setName("Mr. Bean"); $book->addAuthor($author); $id = $book->getID(); $book2 = new Book(); $book2->find($id); asrt($book2->getTitle(), "A can of beans"); $authors = $book2->getAuthors(); asrt(count($authors), 1); $he = array_pop($authors); asrt($he->getName(), "Mr. Bean"); printtext("\nALL TESTS PASSED. REDBEAN SHOULD WORK FINE.\n");
function add_to_shelf() { global $current_user; /*@var $current_user CurrentUser*/ $this->ca(); $bookId = max(0, (int) $_POST['id']); $shelf = max(0, (int) $_POST['shelf_id']); $this->data['shelf_id'] = $shelf; $this->data['id'] = $bookId; if ($bookId && $shelf) { if ($current_user->authorized) { $book = new Book($bookId); if ($book->getTitle()) { $this->data['title'] = trim(implode(' ', $book->getTitle())); $current_user->AddBookShelf($book->id, $shelf); $this->data['success'] = 1; $current_user->reloadPolkaCounters(); $current_user->save(); } } } }
function test_updateTitle() { //Arrange $title = "Revenge of the Martians"; $test_book = new Book($title); $test_book->save(); $title2 = "Star Wars"; $test_book2 = new Book($title2); $test_book2->save(); //Act $test_book2->updateTitle($title); $result = Book::find($test_book2->getId()); //Assert $this->assertEquals($test_book->getTitle(), $result->getTitle()); }
foreach ($courses as $c) { echo $c->getDescription() . "\n"; } $c = new Course(); $c->setId(1); $c->load(); echo $c->getDescription() . "\n"; $students = $c->getStudents(); foreach ($students as $s) { echo $s->getName() . "\n"; } //SEARCH $p = new Person(); $p->setName('Mat'); $search = $p->search(); $search->orderBy('name'); $list = $search->execute(); foreach ($list as $p) { echo $p->getName() . "\n"; } //Recursive Search $c = new City(); $c->setName('San'); $p = new Person(); $p->setCity($c); $b = new Book(); $b->setAuthor($p); $list = $b->search()->execute(); foreach ($list as $b) { echo $b->getTitle() . "\n"; }
function testUpdateTitle() { $title = "The Life and Times of Carrot Top"; $id = 1; $test_book = new Book($title, $id); $test_book->save(); $new_title = "The Old Man Had to Pee"; $test_book->updateTitle($new_title); $this->assertEquals("The Old Man Had to Pee", $test_book->getTitle()); }
function testUpdate() { //Arrange $title = "Title"; $test_book = new Book($title); $test_book->save(); $new_title = "New Title"; //Act $test_book->update($new_title); //Assert $this->assertEquals($test_book->getTitle(), $new_title); }
/** * Tests the Base[Object]::setByName() method */ public function testSetByName() { $book = new Book(); $types = array(BasePeer::TYPE_PHPNAME => 'Title', BasePeer::TYPE_STUDLYPHPNAME => 'title', BasePeer::TYPE_COLNAME => 'book.TITLE', BasePeer::TYPE_FIELDNAME => 'title', BasePeer::TYPE_NUM => 1); $title = 'Harry Potter and the Order of the Phoenix'; foreach ($types as $type => $name) { $book->setByName($name, $title, $type); $result = $book->getTitle(); $this->assertEquals($title, $result); } }
function getMessageNode() { $messageA = array(); $node = false; if ($r = Request::get('redirect')) { list($type, $id) = explode('_', $r); switch ($type) { case 's': $query = 'SELECT * FROM `series` WHERE `id`=' . (int) $id; $res = Database::sql2row($query); if ($res && isset($res['is_s_duplicate']) && $res['is_s_duplicate']) { $messageA = array('html' => 'Cерия «' . $res['title'] . '» была склеена с данной серией'); $node = XMLClass::createNodeFromObject($messageA, false, 'message', true); } break; case 'b': $query = 'SELECT * FROM `book` WHERE `id`=' . (int) $id; $book = new Book((int) $id); if ($book->getDuplicateId()) { $messageA = array('html' => 'Книга «' . $book->getTitle(true) . '» была склеена с данной книгой'); $node = XMLClass::createNodeFromObject($messageA, false, 'message', true); } break; case 'a': $person = new Person((int) $id); if ($person->getDuplicateId()) { $messageA = array('html' => 'Автор «' . $person->getName() . '» был склеен с данным автором'); $node = XMLClass::createNodeFromObject($messageA, false, 'message', true); } break; } } return $node; }
function locate(Book $book) { // returns the position in the library // ie. shelf number & room number $libraryMap->findBookBy($book->getTitle(), $book->getAuthor()); }
public function testLoadObject() { $newAuthor = new Author(); $newAuthor->setName('James Joyce'); $newAuthor->setCreationDatetime(date('Y-m-d H:i:s')); $newAuthor->save(); $newBook = new Book(); $newBook->setTitle('Ulysses'); $newBook->setAuthorId($newAuthor->getAuthorId()); $newBook->setIntroduction('1264 pages of bs by one of the masters.'); $newBook->setCreationDatetime(date('Y-m-d H:i:s')); $newBook->save(); $sameBook = Book::constructByKey($newBook->getBookId()); // this one fails; see ticket #27, http://trac.coughphp.com/ticket/27 //$this->assertIdentical($newBook->getBookId(), $sameBook->getBookId()); $this->assertEqual($newBook->getBookId(), $sameBook->getBookId()); $this->assertIdentical($newBook->getTitle(), $sameBook->getTitle()); // again, this is broke; see ticket #27 //$this->assertIdentical($newBook->getAuthorId(), $sameBook->getAuthorId()); $this->assertEqual($newBook->getAuthorId(), $sameBook->getAuthorId()); $this->assertIdentical($newBook->getIntroduction(), $sameBook->getIntroduction()); $this->assertIdentical($newBook->getCreationDatetime(), $sameBook->getCreationDatetime()); }
<?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);
function testUpdateTitle() { //Arrange $title = "The Cat in the Hat"; $test_book = new Book($title); $test_book->save(); $new_title = "Green Eggs and Ham"; //Act $test_book->updateTitle($new_title); //Assert $this->assertEquals("Green Eggs and Ham", $test_book->getTitle()); }
foreach ($arrayIn as $oneChar) { $string_out .= $oneChar; } return $string_out; } public static function stringToArray($stringIn) { return str_split($stringIn); } } echo tagins("html"); echo tagins("head"); echo tagins("/head"); echo tagins("body"); echo "BEGIN TESTING FACADE PATTERN"; echo tagins("br") . tagins("br"); $book = new Book("Design Patterns", "Gamma, Helm, Johnson, and Vlissides"); echo "Original book title: " . $book->getTitle(); echo tagins("br") . tagins("br"); $bookTitleReversed = CaseReverseFacade::reverseStringCase($book->getTitle()); echo "Reversed book title: " . $bookTitleReversed; echo tagins("br") . tagins("br"); echo "END TESTING FACADE PATTERN"; echo tagins("br"); echo tagins("/body"); echo tagins("/html"); //doing this so code can be displayed without breaks function tagins($stuffing) { return "<" . $stuffing . ">"; }
function testUpdate() { //Arrange $book_name = "Intro to Art"; $test_book = new Book($book_name); $test_book->save(); //Act $new_book_name = "Intro to Fine Arts"; $test_book->update($new_book_name); //Assert $this->assertEquals("Intro to Fine Arts", $test_book->getTitle()); }
function getBookInfo($id) { $book = new Book($id); if ($book->loadForFullView()) { $this->data['book'] = array(); $this->data['book']['id'] = $book->id; $langId = $book->data['id_lang']; foreach (Config::$langs as $code => $id_lang) { if ($id_lang == $langId) { $langCode = $code; } } $this->data['book']['lang_code'] = $langCode; $this->data['book']['lang_title'] = Config::$langRus[$langCode]; $this->data['book']['lang_id'] = $langId; $title = $book->getTitle(); $this->data['book']['title'] = $title['title']; $this->data['book']['subtitle'] = $title['subtitle']; $this->setPageTitle($title['title'] . ($title['subtitle'] ? '. ' . $title['subtitle'] : '')); $this->data['book']['public'] = $book->isPublic(); $persons = $book->getPersons(); uasort($persons, 'sort_by_role'); $this->data['book']['authors'] = $persons; $this->data['book']['genres'] = $book->getGenres(); $this->data['book']['isbn'] = $book->getISBN(); $this->data['book']['rightsholder'] = $book->getRightsholder(); $this->data['book']['annotation'] = $book->getAnnotation(); $this->data['book']['cover'] = $book->getCover(); $this->data['book']['files'] = $book->getFiles(); $this->data['book']['mark'] = $book->data['mark'] / 10; $this->data['book']['lastSave'] = $book->data['modify_time']; $this->data['book']['year'] = (int) $book->data['year'] ? (int) $book->data['year'] : ''; $this->data['book']['book_type'] = Book::$book_types[$book->data['book_type']]; } else throw new Exception('no book #' . $id . ' in database'); }
function AssertBook(Book $book, $id, $title, $pageNumber) { $this->assertEquals($id, $book->getId()); $this->assertEquals($title, $book->getTitle()); $this->assertEquals($pageNumber, (int) $book->getPageNumber()); }
<?php /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ function __autoload($class) { require_once '../class.' . $class . ".php"; } //$book = new Book('PHP Object-Oriented Solutions', 300); //$dvd = new Dvd('Gladiator', '120 minutes'); // //$book->display(); //$dvd->display(); // //echo get_class($book); // //echo get_parent_class($book); $book = new Book('PHP Object-Oriented Solutions', 300); $book->setManufacturerName('friends of Ed'); echo '<p>' . $book->getTitle() . ' is manufactured by ' . $book->getManufacturerName() . '</p>'; $book2 = clone $book; $book2->setTitle('Website Disasters'); $book2->setManufacturerName('enemies of Ed'); echo '<p>' . $book2->getTitle() . ' is manufactured by ' . $book2->getManufacturerName() . '</p>'; echo '<p>' . $book->getTitle() . ' is manufactured by ' . $book->getManufacturerName() . '</p>';
function testUpdate() { //Arrange $title = "Grapes of Wrath"; $test_book = new Book($title); $test_book->save(); $new_title = "Harry Potter"; //Act $test_book->update($new_title); //Assert $this->assertEquals("Harry Potter", $test_book->getTitle()); }
} $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();