/**
  * @test
  */
 public function a_posts_tags_can_be_synced_by_posting_to_an_api_endpoint()
 {
     $post = factory(Post::class)->create();
     $this->withoutMiddleware();
     $response = $this->call('POST', '/admin/api/posts/' . $post->id . '/tags', ['tags' => ['health', 'wealth', 'stealth']]);
     $this->assertEquals(200, $response->status());
     $post = Post::findOrFail($post->id);
     $this->assertEquals(['health', 'wealth', 'stealth'], $post->tags->pluck('tag')->toArray());
 }
Ejemplo n.º 2
0
 /**
  * @test
  */
 public function syncing_tags_overrides_old_ones()
 {
     $tagIds1 = $this->getIdsOfCreatedTags(3);
     $tagIds2 = $this->getIdsOfCreatedTags(3);
     $post = factory(Post::class)->create();
     $post->syncTags($tagIds1);
     $oldTags = $post->tags;
     $post->syncTags($tagIds2);
     $post = Post::findOrFail($post->id);
     //refresh post instance
     $newTags = $post->tags;
     $this->assertFalse($newTags->contains($oldTags->last()));
     $this->assertFalse($newTags->contains($oldTags->first()));
     $this->assertCount(3, $newTags);
 }
Ejemplo n.º 3
0
 /**
  * @test
  */
 public function a_posts_published_at_date_is_set_when_it_is_first_published()
 {
     $post = factory(Post::class)->create();
     $post->setPublishedStatus(true);
     $this->assertEquals(Carbon::now()->toFormattedDateString(), Post::findOrFail($post->id)->published_at->toFormattedDateString());
 }
Ejemplo n.º 4
0
 public function setCategory($id, Request $request)
 {
     $category = PostCategory::findOrFail($request->new_category_id);
     Post::findOrFail($id)->attachTo($category);
     return redirect('admin/blog/categories/' . $category->id . '/posts');
 }