public function testFirst()
 {
     $post = Post::first();
     $debug = last(DB::getQueryLog());
     $this->assertEquals('Bar', $post->title);
     $this->assertEquals('select * from "posts" where "published" = ? and "status" = ? limit 1', $debug['query']);
 }
示例#2
0
 public function run()
 {
     DB::table('comments')->delete();
     $user_id = User::first()->id;
     $post_id = Post::first()->id;
     DB::table('comments')->insert(array(array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content1, 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content2, 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content3, 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('user_id' => $user_id, 'post_id' => $post_id + 1, 'content' => $this->content1, 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('user_id' => $user_id, 'post_id' => $post_id + 1, 'content' => $this->content2, 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('user_id' => $user_id, 'post_id' => $post_id + 2, 'content' => $this->content1, 'created_at' => new DateTime(), 'updated_at' => new DateTime())));
 }
 public function run()
 {
     DB::table('comments')->delete();
     $user_id = User::first()->id;
     $post_id = Post::first()->id;
     DB::table('comments')->insert(array(array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content1), array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content2), array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content3), array('user_id' => $user_id, 'post_id' => $post_id + 1, 'content' => $this->content1), array('user_id' => $user_id, 'post_id' => $post_id + 1, 'content' => $this->content2), array('user_id' => $user_id, 'post_id' => $post_id + 2, 'content' => $this->content1)));
 }
 public function indexAction($sub)
 {
     App::setLocale("en");
     if (Input::get("lang") === "nl") {
         App::setLocale("nl");
     }
     return View::make("index/index", ["post" => Post::first()]);
 }
示例#5
0
 public function testSyncInManyToManyRelationship()
 {
     $post = Post::forceCreate(['title' => 'Post title']);
     $tag = Tag::forceCreate(['title' => 'Tag title']);
     $post->tags()->sync([$tag->id]);
     $this->assertEquals(1, Post::first()->tags->count());
     $this->assertEquals('Tag title', Post::first()->tags()->first()->title);
 }
示例#6
0
 public function myaccount($s = "user")
 {
     $view = $this->getActionView();
     if (RequestMethods::post('delete')) {
         $del = Post::first(array('id = ?' => RequestMethods::post('id')));
         $del->delete();
     }
     if (RequestMethods::post('block')) {
         $block = User::first(array("id = ?" => RequestMethods::post('id')));
         $block->live = 0;
         $block->save();
     }
     if (RequestMethods::post('unblock')) {
         $block = User::first(array("id = ?" => RequestMethods::post('id')));
         $block->live = 1;
         $block->save();
     }
     if (isset($this->_user)) {
         $admin = User::first(array("admin = ?" => '1', "id = ?" => $this->user->id));
         if (!empty($admin)) {
             if ($s != 'post') {
                 $admin_table = $s::all();
             }
             if ($s == 'post') {
                 $database = Registry::get("database");
                 $conn = $database->initialize();
                 $admin_table = $conn->query()->from('posts')->join("users", "posts.from_user = users.id")->all();
             }
             $view->set("admin_table", $admin_table);
         } else {
             $posts = Post::all(array("from_user = ?" => $this->user->id));
             $view->set("posts", $posts);
         }
         $view->set("admin", $admin)->set('table', $s);
     }
 }
 /**
  * Test Non static call for findBySlug is working
  *
  * @test
  */
 public function testNonStaticCallOfFindBySlug()
 {
     $post1 = $this->makePost('My first post');
     $post1->save();
     $post = Post::first();
     $resultId = $post->findBySlug('my-first-post')->id;
     $this->assertEquals($post1->id, $resultId);
 }
示例#8
0
 public function testDeleteWithoutTranslations()
 {
     Post::forceCreate(['title' => 'Title']);
     Post::i18nQuery()->truncate();
     $post = Post::first();
     $post->delete();
     $this->assertCount(0, Post::all());
 }
示例#9
0
 /** @test **/
 public function it_fetches_the_cover_associated_with_the_post()
 {
     $this->createComponent('posts');
     $this->createComponent('cover_photos');
     $this->insertOn('posts', ['title' => 'Random Blog Post']);
     $this->insertOn('cover_photos', ['image' => '/path/to/image.jpg']);
     Post::usesOne(CoverPhoto::class);
     CoverPhoto::first()->registerTo(Post::first());
     $cover = Post::first()->cover_photo;
     $this->assertEquals('/path/to/image.jpg', $cover->image);
 }
示例#10
0
<?php

/**
 * Copyright (c) 2014 Keith Casey.
 *
 * This code is designed to accompany the lynda.com video course "Design Patterns in PHP"
 *   by Keith Casey. If you've received this code without seeing the videos, go watch the
 *   videos. It will make way more sense and be more useful in general.
 */
include_once __DIR__ . '/vendor/autoload.php';
include_once 'posts.php';
echo "<pre style='color:#59E817; background-color:black; word-wrap:break-word;'>";
var_dump(Post::first());
echo '</pre>';
// $post = new Post();
//
// $post->title = 'Sample Title';
// $post->body = 'This is the body';
//
// $post->save();
示例#11
0
 public function testBootMethodAgainAndAgain()
 {
     Post::create(['comments_count' => 2]);
     $this->assertEquals(1, Post::count());
     $this->assertEquals(6, Post::first()->comments_count);
 }