示例#1
0
 function testGetAuthors()
 {
     //Arrange
     $book_title = "Snow Crash";
     $id = 1;
     $test_book = new Book($book_title, $id);
     $test_book->save();
     $author_name = "Super Dog";
     $id2 = 2;
     $test_author = new Author($author_name, $id2);
     $test_author->save();
     $author_name2 = "Neal Stephenson";
     $id3 = 3;
     $test_author2 = new Author($author_name2, $id3);
     $test_author2->save();
     //Act
     $test_book->addAuthor($test_author);
     $test_book->addAuthor($test_author2);
     $result = $test_book->getAuthors();
     //Assert
     $this->assertEquals($result, [$test_author, $test_author2]);
 }
示例#2
0
 function testGetAuthors()
 {
     $title = "Carrie";
     $test_book = new Book($title);
     $test_book->save();
     $name = "Stephen King";
     $test_author = new Author($name);
     $test_author->save();
     $name2 = "Joe Hill";
     $test_author2 = new Author($name2);
     $test_author2->save();
     $test_book->addAuthor($test_author);
     $test_book->addAuthor($test_author2);
     $this->assertEquals([$test_author2, $test_author], $test_book->getAuthors());
 }
示例#3
0
 function testUpdateAuthor()
 {
     $name = "Uncle Ben";
     $id3 = 3;
     $test_author = new Author($name, $id3);
     $test_author->save();
     $name2 = "Goof Ball";
     $id2 = 2;
     $test_author2 = new Author($name2, $id2);
     $test_author2->save();
     $title = "Kama Sutra";
     $id = 1;
     $test_book = new Book($title, $id);
     $test_book->save();
     //Act
     $test_book->addAuthor($test_author);
     $test_book->updateAuthor($test_author2);
     //Assert
     $this->assertEquals($test_book->getAuthors(), [$test_author2]);
 }
示例#4
0
 function testGetAuthor()
 {
     //Arrange
     $author_name = "Stephen King";
     $id = 1;
     $test_author = new Author($author_name, $id);
     $test_author->save();
     $author_name2 = "Bob Smith";
     $id2 = 2;
     $test_author2 = new Author($author_name2, $id2);
     $test_author2->save();
     $book_name = "Gattica";
     $id = 1;
     $test_book = new Book($book_name, $id);
     $test_book->save();
     //Act
     $test_book->addAuthor($test_author);
     $test_book->addAuthor($test_author2);
     //Assert
     $this->assertEquals($test_book->getAuthors(), [$test_author, $test_author2]);
 }
示例#5
0
 function testAddAuthor()
 {
     //Arrange
     $book_name = "Intro to Art";
     $test_book = new Book($book_name);
     $test_book->save();
     $name = "Ben";
     $test_author = new Author($name);
     $test_author->save();
     //Act
     $test_book->addAuthor($test_author);
     //Assert
     $this->assertEquals($test_book->getAuthors(), [$test_author]);
 }
 function testGetAuthors()
 {
     //Arrange
     $id = null;
     $name = "A Series of Unfortunate Events";
     $test_book = new Book($id, $name);
     $test_book->save();
     $name2 = "Lemony Snicket";
     $test_author = new Author($id, $name2);
     $test_author->save();
     $test_book->addAuthor($test_author);
     $name3 = "J.R.R. Tolkien";
     $test_author2 = new Author($id, $name3);
     $test_author2->save();
     $test_book->addAuthor($test_author2);
     //Act
     $result = $test_book->getAuthors();
     //Assert
     $this->assertEquals([$test_author, $test_author2], $result);
 }
示例#7
0
 function test_getAuthors()
 {
     //Arrange
     $name = "Giacomo Bordello";
     $test_author = new Author($name);
     $test_author->save();
     $name2 = "Dude Guy";
     $test_author2 = new Author($name2);
     $test_author2->save();
     $title = "Clarinet Seduction";
     $genre = "Romance";
     $test_book = new Book($title, $genre);
     $test_book->save();
     //Act
     $test_book->addAuthor($test_author);
     $test_book->addAuthor($test_author2);
     //Assert
     $this->assertEquals($test_book->getAuthors(), [$test_author, $test_author2]);
 }
示例#8
0
 function test_addAuthor()
 {
     //Arrange
     $title = "Adventures on Mars";
     $test_book = new Book($title);
     $test_book->save();
     $name = "David Foster Wallace";
     $test_author = new Author($name);
     $test_author->save();
     //Act
     $test_book->addAuthor($test_author);
     $result = $test_book->getAuthors();
     //Assert
     $this->assertEquals([$test_author], $result);
 }
示例#9
0
 function test_AddAuthor()
 {
     //Arrange
     $author_name = "Jack London";
     $test_author = new Author($author_name);
     $test_author->save();
     $title = "Sea Wolf";
     $test_book = new Book($title);
     $test_book->save();
     //Act
     $result = [$test_author];
     $test_book->addAuthor($test_author);
     //Assert
     $this->assertEquals($test_book->getAuthors(), $result);
 }
示例#10
0
 function testGetAuthors()
 {
     //Arrange
     $title = "Eat a Cupcake";
     $year_published = 1999;
     $id = null;
     $test_book = new Book($title, $year_published, $id);
     $test_book->save();
     $name = "Nathan Young";
     $test_author = new Author($name, $id);
     $test_author->save();
     $name2 = "Kyle Pratuch";
     $test_author2 = new Author($name2, $id);
     $test_author2->save();
     //Act
     $test_book->addAuthor($test_author);
     $test_book->addAuthor($test_author2);
     //Assert
     $this->assertEquals([$test_author, $test_author2], $test_book->getAuthors());
 }
示例#11
0
 function test_deleteAllAuthors()
 {
     //Arrange
     $title = "Wesley Pong";
     $test_book = new Book($title);
     $test_book->save();
     $name = "History";
     $test_author = new Author($name);
     $test_author->save();
     $name2 = "Lit";
     $test_author2 = new Author($name2);
     $test_author2->save();
     $test_book->addAuthor($test_author);
     $test_book->addAuthor($test_author2);
     //Act
     $test_book->deleteAllAuthors();
     $result = $test_book->getAuthors();
     //Assert
     $this->assertEquals([], $result);
 }
示例#12
0
 function testAddAuthor()
 {
     $book_name = "Yer not a wizard harry";
     $test_book = new Book($book_name);
     $test_book->save();
     $author_name = "JK Rowling";
     $test_author = new Author($author_name);
     $test_author->save();
     $test_book->addAuthor($test_author);
     $result = $test_book->getAuthors();
     $this->assertEquals($test_author, $result[0]);
 }
示例#13
0
 function test_getAuthors()
 {
     //Arrange
     $test_book = new Book("World War Z", "Horror");
     $test_book->save();
     $test_book2 = new Book("Billy Bartle-Barnaby", "2015-07-09");
     $test_book2->save();
     $test_author = new Author("High Times", "CHEM420");
     $test_author->save();
     $test_author2 = new Author("Gavanese Jamelan", "MUSC69");
     $test_author2->save();
     //Act
     $test_book->addAuthor($test_author);
     $test_book->addAuthor($test_author2);
     $test_book2->addAuthor($test_author2);
     //Assert
     $this->assertEquals($test_book->getAuthors(), [$test_author, $test_author2]);
 }
示例#14
0
 function testGetAuthors()
 {
     //Arrange
     $title = "Little Cat";
     $id = 1;
     $test_book = new Book($title, $id);
     $test_book->save();
     $name = "Ben";
     $id = 1;
     $test_author = new Author($name, $id);
     $test_author->save();
     $name2 = "Jen";
     $id2 = 2;
     $test_author2 = new Author($name2, $id2);
     $test_author2->save();
     //Act
     $test_book->addAuthor($test_author);
     $test_book->addAuthor($test_author2);
     //Assert
     $this->assertEquals($test_book->getAuthors(), [$test_author, $test_author2]);
 }
示例#15
0
    }
    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");
示例#16
0
 function test_getAuthors()
 {
     //Arrange
     $title = "dog book";
     $test_book = new Book($title);
     $test_book->save();
     $name = "William Wegman";
     $test_author = new Author($name);
     $test_author->save();
     $name2 = "Bogus Dogtographer";
     $test_author2 = new Author($name2);
     $test_author2->save();
     //Act
     $test_book->addAuthor($test_author);
     $test_book->addAuthor($test_author2);
     //Assert
     $result = $test_book->getAuthors();
     $this->assertEquals([$test_author, $test_author2], $result);
 }
示例#17
0
 /**
  * Полностью подготавливаем документ книги для solr, с жанрами, авторами и всем прочим.
  * Ресурсоемко, использовать только демоном
  * @param Book $book
  */
 public function prepareBookFull(Book $book)
 {
     $fields = array("id" => '', "id_main_file" => '', "quality" => '', "year" => '', "mark" => '', "rating" => '', "book_type" => '', "download_count" => '', "title" => '', "subtitle" => '', "keywords" => '', "is_cover" => 'bool', "is_duplicate" => 'bool', "is_deleted" => 'bool', "is_blocked" => 'bool', "is_public" => 'bool');
     if (!$book->loaded) {
         return false;
     }
     $document = new Apache_Solr_Document();
     foreach ($fields as $name => $type) {
         if (isset($book->data[$name])) {
             if ($type == 'bool') {
                 $document->{$name} = $book->data[$name] > 0 ? 1 : 0;
             } else {
                 $document->{$name} = $book->data[$name];
             }
         }
     }
     // правообладатели - списочком
     if ($this->rightHolders === null) {
         $this->loadRightHolders();
     }
     $document->rightholder = $this->rightHolders[$book->data['id_rightholder']]['title'];
     // авторы
     $authors = $book->getAuthors();
     foreach ($authors as $author) {
         $document->setMultiValue("author", $author['first_name'] . ' ' . $author['last_name'] . ' ' . $author['middle_name'] . ' ');
     }
     // жанры
     $genres = $book->getGenres();
     foreach ($genres as $genre) {
         $document->setMultiValue("genre", $genre['title']);
     }
     // серии
     $series = $book->getSeries();
     foreach ($series as $serie) {
         $document->setMultiValue("serie", $serie['title']);
     }
     return $document;
 }
示例#18
0
 /**
  * method onEdit()
  * Executed whenever the user clicks at the edit button da datagrid
  */
 function onEdit($param)
 {
     try {
         if (isset($param['key'])) {
             // get the parameter $key
             $key = $param['key'];
             // open a transaction with database 'library'
             TTransaction::open('library');
             // instantiates object Book
             $object = new Book($key);
             // load the aggregates into the multifield field
             $object->author_list = $object->getAuthors();
             $object->subject_list = $object->getSubjects();
             $object->item_list = $object->getItems();
             // fill the form with the active record data
             $this->form->setData($object);
             // close the transaction
             TTransaction::close();
         } else {
             $this->form->clear();
         }
     } catch (Exception $e) {
         // shows the exception error message
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         // undo all pending operations
         TTransaction::rollback();
     }
 }
示例#19
0
 function testGetAuthors()
 {
     //Arrange
     $title = "Harry Potter";
     $id = 1;
     $test_book = new Book($title, $id);
     $test_book->save();
     $name = "JK Rowling";
     $id = 1;
     $test_author = new Author($name, $id);
     $test_author->save();
     $name2 = "George RR Martin";
     $id2 = 2;
     $test_author2 = new Author($name, $id);
     $test_author2->save();
     //Act
     $test_book->addAuthor($test_author);
     $test_book->addAuthor($test_author2);
     $result = $test_book->getAuthors();
     //Assert
     $this->assertEquals([$test_author, $test_author2], $result);
 }
示例#20
0
 function test_addAuthor_getAuthors()
 {
     $title = "Three Blind Mice";
     $test_book = new Book($title);
     $test_book->save();
     $title2 = "Chicken Dog";
     $test_book2 = new Book($title2);
     $test_book2->save();
     $author_name = "Jimmy Neutron";
     $test_author = new Author($author_name);
     $test_author->save();
     $test_book->addAuthor($test_author);
     $result = $test_book->getAuthors();
     $this->assertEquals([$test_author], $result);
 }
示例#21
0
文件: app.php 项目: jschold/Library
//add symfony debug component
use Symfony\Component\Debug\Debug;
Debug::enable();
$app = new Silex\Application();
$app['debug'] = true;
$server = 'mysql:host=localhost;dbname=library';
$username = '******';
$password = '******';
$DB = new PDO($server, $username, $password);
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    return $app['twig']->render('index.html.twig', array('books' => Book::getAll()));
});
$app->get("/books", function () use($app) {
    return $app['twig']->render('books.html.twig', array('books' => Book::getAll()));
});
// $app->get("/authors", function() use ($app) {
//     return $app['twig']->render('books.html.twig', array('authors' => Author::getAll()));
// });
//
$app->post("/books", function () use($app) {
    $title = $_POST['title'];
    $Book = new Book($_POST['title']);
    $Book->save();
    $author_name = $_POST['author_name'];
    $Author = new Author($_POST['author_name']);
    $Author->save();
    $Book->addAuthor($Author);
    return $app['twig']->render('index.html.twig', array('books' => Book::getAll(), 'author' => $Book->getAuthors()));
});
return $app;