public function postEdit($id) { if (!$this->checkRoute()) { return Redirect::route('index'); } $title = 'Edit An Author - ' . $this->site_name; $author = Author::find($id); $input = Input::only('name', 'deck', 'website', 'donate_link', 'bio', 'slug'); $messages = ['unique' => 'The author already exists in the database.', 'url' => 'The :attribute field is not a valid URL.']; $validator = Validator::make($input, ['name' => 'required|unique:authors,name,' . $author->id, 'website' => 'url', 'donate_link' => 'url'], $messages); if ($validator->fails()) { return Redirect::action('AuthorController@getEdit', [$id])->withErrors($validator)->withInput(); } $author->name = $input['name']; $author->deck = $input['deck']; $author->website = $input['website']; $author->donate_link = $input['donate_link']; $author->bio = $input['bio']; if ($input['slug'] == '' || $input['slug'] == $author->slug) { $slug = Str::slug($input['name']); } else { $slug = $input['slug']; } $author->slug = $slug; $author->last_ip = Request::getClientIp(); $success = $author->save(); if ($success) { return View::make('authors.edit', ['title' => $title, 'success' => true, 'author' => $author]); } return Redirect::action('AuthorController@getEdit', [$id])->withErrors(['message' => 'Unable to add author.'])->withInput(); }
/** * Get one Author * * return array {@type Author} * * @view authorDetailView * */ public function get($id) { if (!($feedback = Author::find($id))) { throw new RestException(404, 'feedback not found'); } return $feedback; }
public function author($id) { $author = Author::find($id); $books = DB::table('katalog')->join('author_katalog', 'katalog.id', '=', 'author_katalog.idkatalog')->where('author_katalog.author', '=', $id)->get(array('katalog.title', 'katalog.release', 'katalog.id', 'katalog.category')); $comment = Comment::where('id_obj', '=', $author->id)->where('cat_comment', '=', 2)->get(); $act = 'person'; return View::make('front.author', compact('author', 'books', 'comment', 'act')); }
function test_find() { $name = "Jerry Garcia"; $test_author = new Author($name); $test_author->save(); $name2 = "Frank Sinatra"; $test_author2 = new Author($name2); $test_author2->save(); $result = Author::find($test_author->getId()); $this->assertEquals($test_author, $result); }
function testFind() { $name = "Stephen King"; $test_author = new Author($name); $test_author->save(); $name2 = "Neal Stephenson"; $test_author2 = new Author($name2); $test_author2->save(); $result = Author::find($test_author->getId()); $this->assertEquals($result, $test_author); }
/** <tt>find a unexistent record</tt> */ public function testSaveSelect() { $item = new Author(); $item->name = 'Mihai Eminescu'; $item->save(); try { $items = Author::find(100); $this->fail('Should throw an exception!'); } catch (Exception $ex) { $this->assertIsA($ex, 'RecordNotFoundException'); } $item->delete(); }
function test_find() { //Arrange $name = "Intro to Art"; $test_author = new Author($name); $test_author->save(); $name2 = "Intro to Spanish"; $test_author2 = new Author($name2); $test_author2->save(); //Act $result = Author::find($test_author->getId()); //Assert $this->assertEquals($test_author, $result); }
function test_find() { //Arrange $name = "Ashlin Aronin"; $test_author = new Author($name); $test_author->save(); $name2 = "Vincent Adultman"; $test_author2 = new Author($name2); $test_author2->save(); //Act $result = Author::find($test_author->getId()); //Assert $this->assertEquals($test_author, $result); }
function testFind() { //Arrange $id = null; $name = "Lemony Snicket"; $test_author = new Author($id, $name); $test_author->save(); $name2 = "J.R.R. Tolkien"; $test_author2 = new Author($id, $name2); $test_author2->save(); //Act $result = Author::find($test_author->getId()); //Assert $this->assertEquals($test_author, $result); }
function testFind() { //Arrange $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 $result = Author::find($test_author2->getId()); //Assert $this->assertEquals($test_author2, $result); }
public function test_find_by_datetime() { $now = new DateTime(); $arnow = new ActiveRecord\DateTime(); $arnow->setTimestamp($now->getTimestamp()); Author::find(1)->update_attribute('created_at', $now); $this->assert_not_null(Author::find_by_created_at($now)); $this->assert_not_null(Author::find_by_created_at($arnow)); }
function testFind() { //Arrange $author_name = "Frank Herbert"; $id = null; $test_author = new Author($author_name, $id); $test_author->save(); $author_name2 = "Neal Stephenson"; $id2 = null; $test_author2 = new Author($author_name2, $id2); $test_author2->save(); //Act $result = Author::find($test_author->getId()); //Assert $this->assertEquals($test_author, $result); }
$new_book->save(); return $app['twig']->render('books.html.twig', array('books' => Book::getAll())); }); $app->post("/authors", function () use($app) { $new_author = new Author($_POST['name']); $new_author->save(); return $app['twig']->render('authors.html.twig', array('authors' => Author::getAll())); }); $app->post("/patrons", function () use($app) { $new_patron = new Patron($_POST['name']); $new_patron->save(); return $app['twig']->render('patrons.html.twig', array('patrons' => Patron::getAll())); }); $app->post("/add_author", function () use($app) { $book = Book::find($_POST['book_id']); $author = Author::find($_POST['author_id']); $book->addAuthor($author); return $app['twig']->render('book.html.twig', array('copies' => $book->getCopies(), 'book' => $book, 'authors' => $book->getAuthors(), 'all_authors' => Author::getAll())); }); $app->post("/add_book", function () use($app) { $book = Book::find($_POST['book_id']); $author = Author::find($_POST['author_id']); $author->addBook($book); return $app['twig']->render('author.html.twig', array('author' => $author, 'books' => $author->getBooks(), 'all_books' => Book::getAll())); }); $app->post("/add_copy", function () use($app) { $book = Book::find($_POST['book_id']); $book->addCopy(); return $app['twig']->render('book.html.twig', array('copies' => $book->getCopies(), 'book' => $book, 'authors' => $book->getAuthors(), 'all_authors' => Author::getAll())); }); return $app;
/** * testCreationOfEmptyRecord method * * @return void */ public function testCreationOfEmptyRecord() { $this->loadFixtures('Author'); $TestModel = new Author(); $this->assertEquals(4, $TestModel->find('count')); $TestModel->deleteAll(true, false, false); $this->assertEquals(0, $TestModel->find('count')); $result = $TestModel->save(); $this->assertTrue(isset($result['Author']['created'])); $this->assertTrue(isset($result['Author']['updated'])); $this->assertEquals(1, $TestModel->find('count')); }
/** * test that saveAll and with models at initial insert (no id has set yet) * with validation interact well * * @return void */ public function testValidatesWithModelsAndSaveAllWithoutId() { $this->loadFixtures('Post', 'Author'); $data = array('Author' => array('name' => 'Foo Bar'), 'Post' => array(array('title' => 'Hello'), array('title' => 'World'))); $Author = new Author(); $Post = $Author->Post; $Post->validate = array('author_id' => array('rule' => 'numeric')); $Author->create(); $result = $Author->saveAll($data, array('validate' => 'only')); $this->assertTrue($result); $result = $Author->validateAssociated($data); $this->assertTrue($result); $this->assertTrue($result); $Author->create(); $result = $Author->saveAll($data, array('validate' => 'first')); $this->assertTrue($result); $this->assertNotNull($Author->id); $id = $Author->id; $count = $Author->find('count', array('conditions' => array('Author.id' => $id))); $this->assertSame(1, $count); $count = $Post->find('count', array('conditions' => array('Post.author_id' => $id))); $this->assertEquals($count, count($data['Post'])); }
public function testFindByDatetime() { $now = new DateTime(); $arnow = new ActiveRecord\DateTime(); $arnow->setTimestamp($now->getTimestamp()); Author::find(1)->updateAttribute('created_at', $now); $this->assertNotNull(Author::findByCreatedAt($now)); $this->assertNotNull(Author::findByCreatedAt($arnow)); }
public function testSetDateFlagsDirtyWithPhpDatetime() { $author = Author::create(array('some_date' => new \DateTime())); $author = Author::find($author->id); $author->some_date->setDate(2010, 1, 1); $this->assertHasKeys('some_date', $author->dirtyAttributes()); }
function find() { //Arrange $name = "Name"; $id = 1; $test_author = new Author($name, $id); $name2 = "Different Name"; $id2 = 2; $test_author2 = new Author($name2, $id2); //Act $result = Author::find($test_author2->getId()); //Assert $this->assertEquals($test_student2, $result); }
function test_find() { $name = "Uncle Ben"; $id = 1; $test_author1 = new Author($name, $id); $test_author1->save(); $name2 = "Goof Ball"; $id2 = 2; $test_author2 = new Author($name2, $id2); $test_author2->save(); $result = Author::find($test_author2->getId()); $this->assertEquals($test_author2, $result); }
/** * 查找多个对象 */ function testFindMore() { $id_list = $this->_createAuthors(15); // 查找全部 $authors = Author::find()->all()->query(); $this->assertGreaterThanOrEqual(15, count($authors)); $this->_checkAuthors($authors); unset($authors); // 查找ID 大于等于特定值的 $authors = Author::find('author_id >= ?', $id_list[5])->all()->query(); $this->assertEquals(10, count($authors)); $this->_checkAuthors($authors); unset($authors); }
/** * @expectedException ActiveRecord\RecordNotFound */ public function test_find_by_zero() { Author::find(0); }
/** * @expectedException ActiveRecord\RecordNotFound */ public function test_dont_attempt_eager_load_when_record_does_not_exist() { Author::find(999999, array('include' => array('books'))); }
/** * Test format of $results in afterFind * * @return void */ public function testUseConsistentAfterFind() { $this->loadFixtures('Author', 'Post'); $expected = array('Author' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'test' => 'working'), 'Post' => array(array('id' => '1', 'author_id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), array('id' => '3', 'author_id' => '1', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'))); $Author = new Author(); $Post = $this->getMock('Post', array('afterFind'), array(), '', true); $Post->expects($this->at(0))->method('afterFind')->with(array(array('Post' => $expected['Post'][0])), $this->isFalse())->will($this->returnArgument(0)); $Post->expects($this->at(1))->method('afterFind')->with(array(array('Post' => $expected['Post'][1])), $this->isFalse())->will($this->returnArgument(0)); $Author->bindModel(array('hasMany' => array('Post' => array('limit' => 2, 'order' => 'Post.id')))); $Author->Post = $Post; $result = $Author->find('first', array('conditions' => array('Author.id' => 1), 'recursive' => 1)); $this->assertEquals($expected, $result); // Backward compatiblity $Author = new Author(); $Post = $this->getMock('Post', array('afterFind'), array(), '', true); $Post->expects($this->once())->method('afterFind')->with($expected['Post'], $this->isFalse())->will($this->returnArgument(0)); $Post->useConsistentAfterFind = false; $Author->bindModel(array('hasMany' => array('Post' => array('limit' => 2, 'order' => 'Post.id')))); $Author->Post = $Post; $result = $Author->find('first', array('conditions' => array('Author.id' => 1), 'recursive' => 1)); $this->assertEquals($expected, $result); }
public function testWorksWithDatetime() { Author::find(1)->updateAttribute('created_at', new DateTime()); $this->assertRegExp('/<updated_at>[0-9]{4}-[0-9]{2}-[0-9]{2}/', Author::find(1)->toXml()); $this->assertRegExp('/"updated_at":"[0-9]{4}-[0-9]{2}-[0-9]{2}/', Author::find(1)->toJson()); }
public function test_set_date_flags_dirty_with_php_datetime() { $author = Author::create(array('some_date' => new \DateTime())); $author = Author::find($author->id); $author->some_date->setDate(2010, 1, 1); $this->assert_has_keys('some_date', $author->dirty_attributes()); }
public function test_inserting_with_explicit_pk() { $author = Author::create(array('author_id' => 9999, 'name' => 'blah')); $this->assert_not_null(Author::find($author->id)); }
return $app['twig']->render("main_admin.html.twig", array('books' => Book::getAll())); }); //INDIVIDUAL AUTHOR PAGE $app->get("/author/{id}", function ($id) use($app) { $author = Author::find($id); $books = $author->getBooks(); return $app['twig']->render('author.html.twig', array('author' => $author, "books" => $books)); }); //Add book on the individual author page $app->post("/author/{id}/add_book", function ($id) use($app) { $find_author = Author::find($id); $title = $_POST['title']; $new_book = new Book($title); $new_book->save(); $find_author->addBook($new_book); $books = $find_author->getBooks(); return $app['twig']->render('author.html.twig', array('author' => $find_author, 'books' => $books)); }); //Update author's name $app->patch("/author/{id}", function ($id) use($app) { $author = Author::find($id); $author->update($_POST['title']); $books = $author->getBooks(); return $app['twig']->render('author.html.twig', array('author' => $author, 'books' => $books)); }); $app->delete("/author/{id}", function ($id) use($app) { $author = Author::find($id); $author->delete(); return $app['twig']->render('main_admin.html.twig', array('author' => $author, 'books' => Book::getAll())); }); return $app;
/** * @expectedException ActiveRecord\UndefinedPropertyException */ public function test_invalid_attribute() { $author = Author::find('first', array('conditions' => 'author_id=1')); $author->some_invalid_field_name; }
/** * testAssociationAfterFindCallbacksDisabled method * * @return void */ public function testAssociationAfterFindCalbacksDisabled() { $this->loadFixtures('Post', 'Author', 'Comment'); $TestModel = new Post(); $result = $TestModel->find('all', array('callbacks' => false, 'order' => array('Post.id' => 'ASC'))); $expected = array(array('Post' => array('id' => '1', 'author_id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), 'Author' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31')), array('Post' => array('id' => '2', 'author_id' => '3', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), 'Author' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31')), array('Post' => array('id' => '3', 'author_id' => '1', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'), 'Author' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'))); $this->assertEquals($expected, $result); unset($TestModel); $Author = new Author(); $Author->Post->bindModel(array('hasMany' => array('Comment' => array('className' => 'ModifiedComment', 'foreignKey' => 'article_id')))); $result = $Author->find('all', array('conditions' => array('Author.id' => 1), 'recursive' => 2, 'order' => array('Author.id' => 'ASC'), 'callbacks' => false)); $expected = array('id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'); $this->assertEquals($expected, $result[0]['Post'][0]['Comment'][0]); }
public function test_works_with_datetime() { Author::find(1)->update_attribute('created_at', new DateTime()); $this->assert_reg_exp('/<updated_at>[0-9]{4}-[0-9]{2}-[0-9]{2}/', Author::find(1)->to_xml()); $this->assert_reg_exp('/"updated_at":"[0-9]{4}-[0-9]{2}-[0-9]{2}/', Author::find(1)->to_json()); }