public function run() { DB::table('authors')->delete(); Author::create(['name' => 'Lauren', 'surname' => 'Oliver']); Author::create(['name' => 'Stephenie', 'surname' => 'Meyer']); Author::create(['name' => 'Dan', 'surname' => 'Brown']); }
public function up() { // DB::table('authors')->delete(); Author::create(array('name' => 'Lauren', 'surname' => 'Olivier')); Author::create(array('name' => 'Stephenie', 'surname' => 'Meyer')); Author::create(array('name' => 'Dan', 'surname' => 'Brown')); }
public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { Author::create([]); } }
public function testRenderAuthorWithTwitter() { $author = Author::create()->withURL('http://twitter.com/evertonrosario')->withName('Everton Rosario')->withDescription('Passionate coder and mountain biker'); $expected = '<address>' . '<a href="http://twitter.com/evertonrosario">Everton Rosario</a>' . 'Passionate coder and mountain biker' . '</address>'; $rendered = $author->render(); $this->assertEquals($expected, $rendered); }
public function testIsRTLEnabled() { $article = InstantArticle::create()->withCanonicalURL('http://wp.localtest.me/2016/04/12/stress-on-earth/')->enableAutomaticAdPlacement()->enableRTL()->withHeader(Header::create()->withTitle(H1::create()->appendText('Peace on <b>earth</b>'))->addAuthor(Author::create()->withName('bill'))->withPublishTime(Time::create(Time::PUBLISHED)->withDatetime(\DateTime::createFromFormat('j-M-Y G:i:s', '14-Aug-1984 19:30:00'))))->addChild(Paragraph::create()->appendText('Yes, peace is good for everybody!')->appendText(LineBreak::create())->appendText(' Man kind.')); $result = $article->render(); $expected = '<!doctype html>' . '<html dir="rtl">' . '<head>' . '<link rel="canonical" href="http://wp.localtest.me/2016/04/12/stress-on-earth/"/>' . '<meta charset="utf-8"/>' . '<meta property="op:generator" content="facebook-instant-articles-sdk-php"/>' . '<meta property="op:generator:version" content="1.5.2"/>' . '<meta property="op:markup_version" content="v1.0"/>' . '</head>' . '<body>' . '<article>' . '<header>' . '<h1>Peace on <b>earth</b></h1>' . '<time class="op-published" datetime="1984-08-14T19:30:00+00:00">August 14th, 7:30pm</time>' . '<address>' . '<a>bill</a>' . '</address>' . '</header>' . '<p>Yes, peace is good for everybody!<br/> Man kind.</p>' . '</article>' . '</body>' . '</html>'; $this->assertEquals($expected, $result); }
public function run() { $faker = Faker\Factory::create(); foreach (range(1, 40) as $index) { $username = $faker->userName; Author::create(['name' => $username, 'deck' => $faker->sentence(12), 'website' => $faker->url, 'donate_link' => $faker->url, 'bio' => $faker->paragraph(5), 'slug' => Str::slug($username), 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')]); } }
public function run() { $faker = Faker::create(); Author::truncate(); foreach (range(1, 5) as $index) { Author::create(['name' => $faker->name]); } }
public function store() { $validator = Validator::make($data = Input::all(), Author::$rules); if ($validator->fails()) { return Redirect::back()->withPesan('Terdapat kesalahan validasi')->withInput(); } $author = Author::create($data); return Redirect::route('admin.authors.index')->withPesan("Berhasil menyimpan {$author->name}"); }
public function testCompleteHeader() { date_default_timezone_set('UTC'); $inline = '<script>alert("test & more test");</script>'; $header = Header::create()->withTitle('Big Top Title')->withSubTitle('Smaller SubTitle')->withPublishTime(Time::create(Time::PUBLISHED)->withDatetime(\DateTime::createFromFormat('j-M-Y G:i:s', '14-Aug-1984 19:30:00')))->withModifyTime(Time::create(Time::MODIFIED)->withDatetime(\DateTime::createFromFormat('j-M-Y G:i:s', '10-Feb-2016 10:00:00')))->addAuthor(Author::create()->withName('Author One')->withDescription('Passionate coder and mountain biker'))->addAuthor(Author::create()->withName('Author Two')->withDescription('Weend surfer with heavy weight coding skils')->withURL('http://facebook.com/author'))->withKicker('Some kicker of this article')->withCover(Image::create()->withURL('https://jpeg.org/images/jpegls-home.jpg')->withCaption(Caption::create()->appendText('Some caption to the image')))->addAd(Ad::create()->withSource('http://foo.com'))->addAd(Ad::create()->withSource('http://foo.com')->withWidth(350)->withHeight(50)->enableDefaultForReuse())->addAd(Ad::create()->withWidth(300)->withHeight(250)->enableDefaultForReuse()->withHTML($inline)); $expected = '<header>' . '<figure>' . '<img src="https://jpeg.org/images/jpegls-home.jpg"/>' . '<figcaption>Some caption to the image</figcaption>' . '</figure>' . '<h1>Big Top Title</h1>' . '<h2>Smaller SubTitle</h2>' . '<time class="op-published" datetime="1984-08-14T19:30:00+00:00">August 14th, 7:30pm</time>' . '<time class="op-modified" datetime="2016-02-10T10:00:00+00:00">February 10th, 10:00am</time>' . '<address>' . '<a>Author One</a>' . 'Passionate coder and mountain biker' . '</address>' . '<address>' . '<a href="http://facebook.com/author" rel="facebook">Author Two</a>' . 'Weend surfer with heavy weight coding skils' . '</address>' . '<h3 class="op-kicker">Some kicker of this article</h3>' . '<section class="op-ad-template">' . '<figure class="op-ad">' . '<iframe src="http://foo.com"></iframe>' . '</figure>' . '<figure class="op-ad op-ad-default">' . '<iframe src="http://foo.com" width="350" height="50"></iframe>' . '</figure>' . '<figure class="op-ad">' . '<iframe width="300" height="250">' . '<script>alert("test & more test");</script>' . '</iframe>' . '</figure>' . '</section>' . '</header>'; $rendered = $header->render(); $this->assertEquals($expected, $rendered); }
public function postCreate() { $validation = Author::validate(Input::all()); if ($validation->fails()) { return Redirect::route('new_author')->withErrors($validation)->withInput(); } else { Author::create(array('name' => Input::get('name'), 'bio' => Input::get('bio'))); return Redirect::route('authors')->with('message', 'Author was created successfuly.'); } }
camp_html_add_msg($translator->trans('Cannot remove author alias.', array(), 'users')); } } $first_name = Input::Get('first_name'); $last_name = Input::Get('last_name'); $can_save = false; if ($id > -1 && strlen($first_name) > 0 && strlen($last_name) > 0) { $can_save = true; } if ($can_save) { $author = new Author(); if ($id > 0) { $author = new Author($id); $isNewAuthor = false; } else { $author->create(array('first_name' => $first_name, 'last_name' => $last_name)); $isNewAuthor = true; } $uploadFileSpecified = isset($_FILES['file']) && isset($_FILES['file']['name']) && !empty($_FILES['file']['name']); $author->setFirstName($first_name); $author->setLastName($last_name); $author->commit(); // Reset types $types = Input::Get('type', 'array', array()); AuthorAssignedType::ResetAuthorAssignedTypes($author->getId()); foreach ($types as $type) { $author->setType($type); } $author->setSkype(Input::Get('skype')); $author->setJabber(Input::Get('jabber')); $author->setAim(Input::Get('aim'));
public function test_transaction_rolledback_by_throwing_exception() { $original = Author::count(); $exception = null; try { Author::transaction(function () { Author::create(array("name" => "blah")); throw new Exception("blah"); }); } catch (Exception $e) { $exception = $e; } $this->assert_not_null($exception); $this->assert_equals($original, Author::count()); }
public function test_inserting_with_explicit_pk() { $author = Author::create(array('author_id' => 9999, 'name' => 'blah')); $this->assert_not_null(Author::find($author->id)); }
/** * Set authors for an article, uses legacy classes * * @param Article $article * @param \Newscoop\IngestPluginBundle\Entity\Entry $entry */ protected function setArticleAuthorsLegacy(\Article $article, \Newscoop\IngestPluginBundle\Entity\Feed\Entry $entry) { $authors = $entry->getAuthors(); $order = 0; if (count($authors) > 0) { foreach ($authors as $author) { $name = trim($author['firstname'] . ' ' . $author['lastname']); $author = new \Author($name); if (!$author->exists()) { $author->create(); } $article->setAuthor($author, $order++); } } else { $name = $entry->getProduct() ?: $entry->getFeed()->getName(); $author = new \Author($name); if (!$author->exists()) { $author->create(); } $article->setAuthor($author); } }
function camp_set_author(ArticleTypeField $p_sourceField, &$p_errors) { $translator = \Zend_Registry::get('container')->getService('translator'); $p_errors = array(); $articles = Article::GetArticlesOfType($p_sourceField->getArticleType()); foreach ($articles as $article) { $articleData = $article->getArticleData(); $authorName = trim($articleData->getFieldValue($p_sourceField->getPrintName())); if (empty($authorName)) { continue; } $author = new Author($authorName); if (!$author->exists()) { if (!$author->create()) { $p_errors[] = $translator->trans('Unable to create author $1 for article no. $2 ($3) of type $4.', array('$1' => $author->getName(), '$2' => $article->getArticleNumber(), '$3' => $article->getName(), '$4' => $article->getType()), 'home'); continue; } } if (!$article->setAuthorId($author->getId())) { $p_errors[] = $translator->trans('Error setting the author $1 for article no. $2 ($3) of type $4.', array('$1' => $author->getName(), '$2' => $article->getArticleNumber(), '$3' => $article->getName(), '$4' => $article->getType()), 'home'); continue; } } $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache'); $cacheService->clearNamespace('authors'); $cacheService->clearNamespace('article'); return count($p_errors); }
function camp_set_author(ArticleTypeField $p_sourceField, &$p_errors) { $p_errors = array(); $articles = Article::GetArticlesOfType($p_sourceField->getArticleType()); foreach ($articles as $article) { $articleData = $article->getArticleData(); $authorName = trim($articleData->getFieldValue($p_sourceField->getPrintName())); if (empty($authorName)) { continue; } $author = new Author($authorName); if (!$author->exists()) { if (!$author->create()) { $p_errors[] = getGS('Unable to create author "$1" for article no. $2 ("$3") of type $4.', $author->getName(), $article->getArticleNumber(), $article->getName(), $article->getType()); continue; } } if (!$article->setAuthorId($author->getId())) { $p_errors[] = getGS('Error setting the author "$1" for article no. $2 ("$3") of type $4.', $author->getName(), $article->getArticleNumber(), $article->getName(), $article->getType()); continue; } } return count($p_errors); }
public function testTransactionRolledbackByThrowingException() { $original = Author::count(); $exception = null; try { Author::transaction(function () { Author::create(array("name" => "blah")); throw new Exception("blah"); }); } catch (Exception $e) { $exception = $e; } $this->assertNotNull($exception); $this->assertEquals($original, Author::count()); }
public function test_inserting_with_explicit_pk() { $author = Author::create(array('author_id' => 9999, 'name' => 'blah')); $this->assert_equals(9999, $author->author_id); }
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()); }
$authors = $em->getRepository('Newscoop\\Entity\\ArticleAuthor')->getArticleAuthors($articleObj->getArticleNumber(), $language->getCode())->getArrayResult(); ArticleAuthor::OnArticleLanguageDelete($articleObj->getArticleNumber(), $articleObj->getLanguageId()); foreach ($authors as $author) { $dispatcher->dispatch("user.set_points", new \Newscoop\EventDispatcher\Events\GenericEvent($this, array('authorId' => $author['fk_author_id']))); } $i = 0; foreach ($f_article_author as $author) { $authorObj = new Author($author); $author = trim($author); if (!$authorObj->exists() && isset($author[0])) { if ($blogService->isBlogger($g_user)) { // blogger can't create authors continue; } $authorData = Author::ReadName($author); $authorObj->create($authorData); } elseif ($blogService->isBlogger($g_user)) { // test if using authors from blog if (!$blogService->isBlogAuthor($authorObj, $blogInfo)) { continue; } } // Sets the author type selected $author_type = $f_article_author_type[$i]; $authorObj->setType($author_type); // Links the author to the article if ($authorObj->getId() != 0) { $articleAuthorObj = new ArticleAuthor($articleObj->getArticleNumber(), $articleObj->getLanguageId(), $authorObj->getId(), $author_type, $i + 1); } if (isset($articleAuthorObj) && !$articleAuthorObj->exists()) { $articleAuthorObj->create();
/** * 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 testIsValid() { $ia = InstantArticle::create()->withCanonicalURL('http://wp.localtest.me/2016/04/12/stress-on-earth/')->enableAutomaticAdPlacement()->withHeader(Header::create()->withTitle(H1::create()->appendText('Peace on <b>earth</b>'))->addAuthor(Author::create()->withName('bill'))->withPublishTime(Time::create(Time::PUBLISHED)->withDatetime(\DateTime::createFromFormat('j-M-Y G:i:s', '14-Aug-1984 19:30:00'))))->addChild(Paragraph::create()->appendText('Yes, peace is good for everybody!')->appendText(LineBreak::create())->appendText(' Man kind.')); $this->assertTrue($ia->isValid()); }
public function test_update_our_datetime() { $author = Author::create(array('name' => 'Blah Blah')); $our_datetime = new DateTime('1983-12-05'); $author->some_date = $our_datetime; $this->assert_true($our_datetime === $author->some_date); }
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()); }
/** * Set article authors * * @param Article $article * @param Newscoop\Entity\Ingest\Feed\Entry $entry * @return void */ private function setArticleAuthors(\Article $article, Entry $entry) { $name = $entry->getFeed()->getTitle(); $author = new \Author($name); if (!$author->exists()) { $author->create(); } $article->setAuthor($author); }