tests/Feature/Admin/ManagePostsControllerTest.php
/**
     * Test that new posts can be created, and associated to a category.
     */
Test that new posts can be created, and associated to a category.
Test that new posts can be created and associated to a category .
public function testStoreWithCategory()
    {
        $this->beAdminUser();
        $category = factory(Category::class)->create();
        $params = [
            'title' => $this->faker->sentence,
            'post_body' => $this->faker->paragraph,
            'meta_desc' => $this->faker->paragraph,
            'short_description' => $this->faker->paragraph,
            'category' => [$category->id => '1'],
        ];
        $response = $this->post(route('blogetc.admin.store_post'), $params);
        $response->assertRedirect()->assertSessionDoesntHaveErrors();
        $post = Post::where('title', $params['title'])->firstOrFail();
        $postCategories = $post->categories;
        $this->assertCount(1, $postCategories);
        $this->assertTrue($postCategories->first()->is($category));
    }
public function testStoreWithCategory ( ) { $ this -> beAdminUser ( ) ; $ category = factory ( Category :: class ) -> create ( ) ; $ params = [ 'title' => $ this -> faker -> sentence , 'post_body' => $ this -> faker -> paragraph , 'meta_desc' => $ this -> faker -> paragraph , 'short_description' => $ this -> faker -> paragraph , 'category' => [ $ category -> id => '1' ] , ] ; $ response = $ this -> post ( route ( 'blogetc.admin.store_post' ) , $ params ) ; $ response -> assertRedirect ( ) -> assertSessionDoesntHaveErrors ( ) ; $ post = Post :: where ( 'title' , $ params [ 'title' ] ) -> firstOrFail ( ) ; $ postCategories = $ post -> categories ; $ this -> assertCount ( 1 , $ postCategories ) ; $ this -> assertTrue ( $ postCategories -> first ( ) -> is ( $ category ) ) ; }
Test that new posts can be created, and associated to a category.
Test that new posts can be created and associated to a category .