function testSetname() { //Arrange $name = "Mary Shelly"; $test_author = new Author($name); //Act $test_author->setName("Dean Koontz"); $result = $test_author->getName(); //Assert $this->assertEquals("Dean Koontz", $result); }
function test_setName() { //Arrange $name = "Kevin"; $test_author = new Author($name); //Act $name2 = "Ian"; $test_author->setName($name2); $result = $test_author->getName(); //Assert $this->assertEquals($name2, $result); }
function testSetName() { //Arrange $name = "Paul Jones"; $id = 1; $test_author = new Author($name, $id); //Act $test_author->setName("Steve Smith"); $result = $test_author->getName(); //Assert $this->assertEquals("Steve Smith", $result); }
function test_setName() { //Arrange $name = "Stephen King"; $id = null; $test_author = new Author($name, $id); //Act $test_author->setName("James Patterson"); $result = $test_author->getName(); //Assert $this->assertEquals("James Patterson", $result); }
public function save($data) { $ret = parent::save($data); if (isset($data['author'])) { $id = $this->getId(); $authors = explode(";", $data['author']); foreach ($authors as $author) { $a = new Author(); $a->setName($author); $a->commit(); $bookAuthor = new BookAuthor(); $bookAuthor->setBookId($id); $bookAuthor->setAuthorId($a->getId()); $bookAuthor->commit(); } } return $ret; }
} $title = $request->request->get('title'); $message = $request->request->get('message'); $postModel->set($title, $message, $authorId); return $app->redirect($app["url_generator"]->generate("post_index")); })->bind('post_add'); $app->get('/authors', function () use($app) { $authorModel = new Author($app['db']); $authorsToDisplay = $authorModel->getAll(); return $app['twig']->render('author_index.html.twig', array('authors' => $authorsToDisplay)); })->bind('author_index'); $app->get('/author/{author_id}', function ($author_id) use($app) { $authorModel = new Author($app['db']); $authorToDisplay = $authorModel->get($author_id); if (!$authorToDisplay) { $app->abort(404, 'The article could not be found'); } return $app['twig']->render('author_single.html.twig', array('author' => $authorToDisplay)); })->assert('author_id', '\\d+')->bind('author_single'); $app->get('/author/new', function () use($app) { return $app['twig']->render('author_new.html.twig'); })->bind('author_new'); $app->post('/author/add', function (Request $request) use($app) { $authorModel = new Author($app['db']); $name = $request->request->get('name'); $authorModel->setName($name); return $app->redirect($app["url_generator"]->generate("author_index")); })->bind('author_add'); // This should be the last line $app->run(); // Start the application, i.e. handle the request
<?php /* * This file is part of the symfony package. * (c) Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ $app = 'frontend'; include dirname(__FILE__) . '/../../bootstrap/functional.php'; include $configuration->getSymfonyLibDir() . '/vendor/lime/lime.php'; $t = new lime_test(2); // ->__construct() $t->diag('->__construct()'); class DefaultValuesForm extends AuthorForm { public function configure() { $this->setDefault('name', 'John Doe'); } } $author = new Author(); $form = new DefaultValuesForm($author); $t->is($form->getDefault('name'), 'John Doe', '->__construct() uses form defaults for new objects'); $author = new Author(); $author->setName('Jacques Doe'); $author->save(); $form = new DefaultValuesForm($author); $t->is($form->getDefault('name'), 'Jacques Doe', '->__construct() uses object value as a default for existing objects'); $author->delete();
/* * This file is part of the symfony package. * (c) 2004-2006 Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ $app = 'frontend'; $fixtures = 'fixtures/fixtures.yml'; require_once dirname(__FILE__) . '/../bootstrap/functional.php'; $t = new lime_test(22); $authors = Doctrine_Core::getTable('Author')->findAll(); $t->is(count($authors), 2); $author = new Author(); // Accessor overriding $author->setName('Jonathan H. Wage'); $author->save(); // Propel style accessors with column name $t->is($author->getName(), $author->name); // Propel style accessors for id // Also check new author was not created since Jonathan H. Wage exists in fixtures/fixtures.yml $t->is($author->getId(), 1); // Make sure we still have only 2 authors $authors = Doctrine_Core::getTable('Author')->findAll(); $t->is(count($authors), 2); $article = new Article(); $article->title = 'test'; // __toString() automatic column finder $t->is((string) $article, 'test'); // Different style accessors $t->is($article->getAuthor_id(), $article->author_id);
public function testTransactions() { $author = new Author(); $author->setName('Haruki Murakami'); $this->assertTrue($author->save()); $db = Author::getDb(); $db->startTransaction(); $db->delete('author', array(1 => 1)); $db->rollback(); $authors = new Author_Collection(); $authors->load(); $this->assertEqual(count($authors), 1); }
$t->is($nbArticles, 1, 'join() allows to join to another table (one-to-many)'); $nbArticles = sfPropelFinder::from('Article')->where('Comment.Content', 'foo')->count(); $t->is($nbArticles, 1, 'join() can be omitted if column names are explicit (one-to-many)'); $article = sfPropelFinder::from('Article')->join('Comment')->where('Comment.Content', 'foo')->findOne(); $t->is($article->getTitle(), 'bbbbb', 'join() allows to join to another table (one-to-many)'); CommentPeer::doDeleteAll(); ArticlePeer::doDeleteAll(); AuthorPeer::doDeleteAll(); $article1 = new Article(); $article1->setTitle('aaaaa'); $article1->setCategory($category1); $article1->save(); $author1 = new Author(); $author1->setName('John'); $author1->save(); $comment = new Comment(); $comment->setContent('foo'); $comment->setArticleId($article1->getId()); $comment->setAuthor($author1); $comment->save(); $article = sfPropelFinder::from('Article')->join('Comment')->join('Author')->where('Author.Name', 'John')->findOne(); $t->is($article->getTitle(), 'aaaaa', 'you can chain several join() statements'); $article = sfPropelFinder::from('Article')->join('Comment')->where('Author.Name', 'John')->findOne(); $t->is($article->getTitle(), 'aaaaa', 'join() can be omitted if column names are explicit'); $article = sfPropelFinder::from('Article')->joinComment()->joinAuthor()->where('Author.Name', 'John')->findOne(); $t->is($article->getTitle(), 'aaaaa', 'joinXXX() does a join according to the XXX column name'); $comment = sfPropelFinder::from('Comment')->join('Article')->join('Author')->where('Author.Name', 'John')->findOne(); $t->is($comment->getContent(), 'foo', 'you can add several join() statements');
function getAllAuthor() { $key = 'author'; $collection = CacheManager::get($key, TRUE); if ($collection) { return $collection; } $collection = new Collection(); $this->connect(); $result = $this->conn->query("CALL sp_get_all_author()"); if ($result) { //$row = $result->fetch_assoc(); while ($obj = $result->fetch_object()) { $author = new Author(); $author->setId($obj->Author_id); $author->setName($obj->Author_name); $collection->addItem($author, $obj->Author_id); } $result->close(); // for fetch_object() } //$result->free_result(); // for fetch_assoc() $this->close(); CacheManager::set($key, $collection, TRUE); return $collection; }
$t->diag('sfPropelFinder::with() does not fail with two left joins and missing related objects'); CommentPeer::doDeleteAll(); ArticlePeer::doDeleteAll(); Articlei18nPeer::doDeleteAll(); AuthorPeer::doDeleteAll(); $article1 = new Article(); $article1->setTitle('aaa'); $article1->save(); $comment1 = new Comment(); $comment1->setArticleId($article1->getId()); $comment1->save(); $author1 = new Author(); $author1->setName('auth1'); $author1->save(); $comment2 = new Comment(); $comment2->setArticleId($article1->getId()); $comment2->setAuthor($author1); $comment2->save(); $finder = sfPropelFinder::from('Comment')-> leftJoin('Author')->with('Author')-> leftJoin('Article')->with('Article'); $comments = $finder->find(); $latestQuery = $finder->getLatestQuery(); $t->is($comments[0]->getAuthor(), null, 'First object has no author'); $t->is(Propel::getConnection()->getLastExecutedQuery(), $latestQuery, 'Related hydration occurred correctly'); $t->isnt($comments[0]->getArticle(), null, 'First object has an article'); $t->is(Propel::getConnection()->getLastExecutedQuery(), $latestQuery, 'Related hydration occurred correctly');
} 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");
/* * This file is part of the symfony package. * (c) Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ $app = 'frontend'; include dirname(__FILE__) . '/../../bootstrap/functional.php'; include $configuration->getSymfonyLibDir() . '/vendor/lime/lime.php'; $t = new lime_test(2); // ->clean() $t->diag('->clean()'); $validator = new sfValidatorPropelUnique(array('model' => 'Author', 'column' => 'name')); $author = new Author(); $author->setName('==NAME=='); $author->save(); try { $validator->clean(array('name' => '==NAME==')); $t->fail('->clean() throws an error on the column'); } catch (sfValidatorErrorSchema $errors) { $t->is(isset($errors['name']), true, '->clean() throws an error on the column'); } catch (Exception $e) { $t->fail('->clean() throws an error on the column'); $t->diag(' ' . $e->getMessage()); } $validator->setOption('field', 'author_name'); try { $validator->clean(array('author_name' => '==NAME==')); $t->fail('->clean() throws an error on the field'); } catch (sfValidatorErrorSchema $errors) {
<?php use Gries\JsonObjectResolver\JsonResolver; require_once __DIR__ . '/../vendor/autoload.php'; require_once __DIR__ . '/Author.php'; require_once __DIR__ . '/Book.php'; $book = new \Book(); $book->setTitle('test-title-1'); $book2 = new \Book(); $book2->setTitle('test-title-2'); $author = new \Author(); $author->setName('test-author'); $author->setBooks([$book, $book2]); $resolver = new JsonResolver(); $json = $resolver->encode($author); $decodedAuthor = $resolver->decode($json); var_dump($author); var_dump($decodedAuthor); //class Author#4 (2) { // protected $name => // string(11) "test-author" // protected $books => // array(2) { // [0] => // class Book#2 (1) { // protected $title => // string(12) "test-title-1" // } // [1] => // class Book#3 (1) { // protected $title =>
function buildAuthor($authorXMLObject) { $author = new Author(); $author->setName($authorXMLObject->name); $author->setUri($authorXMLObject->uri); $author->setEmail($authorXMLObject->email); return $author; }