Beispiel #1
0
 public function test_can_add_tags_to_posts()
 {
     $post = Post::create(['title' => 'My Post', 'content' => 'My content', 'slug' => 'my-post']);
     $tag1 = Tag::create(['name' => 'Tag 1']);
     $tag2 = Tag::create(['name' => 'Tag 2']);
     $tag1->posts()->save($post);
     $tag2->posts()->save($post);
     $this->assertCount(1, Post::all());
     $this->assertEquals('My Post', $tag1->posts->first()->title);
     $this->assertEquals('My Post', $tag2->posts->first()->title);
     $tags = Post::find(1)->tags;
     $this->assertCount(2, $tags);
     $this->assertEquals('Tag 1', $tags[0]->name);
     $this->assertEquals('Tag 2', $tags[1]->name);
 }
Beispiel #2
0
 public function test_can_force_delete()
 {
     $post = Post::create(['title' => 'Post test 1', 'content' => 'Content post 1']);
     $post->forceDelete();
     $this->assertCount(0, Post::all());
 }