make(); $response = $this->actingAs($user) ->get('/admin/blog'); $response->assertSeeText('Select article to edit:'); } #[Test] public function adminCanLoadFormToCreateArticle(): void { $user = User::factory()->make(); $response = $this->actingAs($user) ->get('/admin/blog/create'); $response->assertSeeText('Title (URL)'); } #[Test] public function admiNCanCreateNewArticle(): void { $user = User::factory()->make(); $this->actingAs($user) ->post('/admin/blog', [ 'title' => 'Test Title', 'main' => 'Article content', ]); $this->assertDatabaseHas('articles', ['title' => 'Test Title']); } #[Test] public function adminCanCreateNewArticleWithFile(): void { $user = User::factory()->make(); $faker = Factory::create(); $text = $faker->text; if ($fh = fopen(sys_get_temp_dir() . '/article.md', 'w')) { fwrite($fh, $text); fclose($fh); } $path = sys_get_temp_dir() . '/article.md'; $file = new UploadedFile($path, 'article.md', 'text/plain', null, true); $this->actingAs($user) ->post('/admin/blog', [ 'title' => 'Uploaded Article', 'article' => $file, ]); $this->assertDatabaseHas('articles', [ 'title' => 'Uploaded Article', 'main' => $text, ]); } #[Test] public function articleCanLoadFormToEditArticle(): void { $user = User::factory()->make(); $article = Article::factory()->create([ 'main' => 'This is *my* new blog. It uses `Markdown`.', ]); $response = $this->actingAs($user) ->get('/admin/blog/' . $article->id . '/edit'); $response->assertSeeText('This is *my* new blog. It uses `Markdown`.'); } #[Test] public function adminCanEditArticle(): void { $user = User::factory()->make(); $article = Article::factory()->create(); $this->actingAs($user) ->post('/admin/blog/' . $article->id, [ '_method' => 'PUT', 'title' => 'My New Blog', 'main' => 'This article has been edited', ]); $this->assertDatabaseHas('articles', [ 'title' => 'My New Blog', 'main' => 'This article has been edited', ]); } #[Test] public function adminCanDeleteArticle(): void { $user = User::factory()->make(); $article = Article::factory()->create(); $this->actingAs($user) ->post('/admin/blog/' . $article->id, [ '_method' => 'DELETE', ]); $this->assertSoftDeleted('articles', [ 'title' => $article->title, ]); } }