jonnybarnes.uk/tests/Feature/ArticlesTest.php
Jonny Barnes d9e2467ba5
fix: Improve routing specificity and add new test.
- Update regular expressions for two routes in `routes/web.php` to match specific numeral values
- Add new test for incorrect URL parsing in `tests/Feature/ArticlesTest.php`
2023-06-16 13:02:00 +01:00

68 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature;
use App\Models\Article;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Jonnybarnes\IndieWeb\Numbers;
use Tests\TestCase;
class ArticlesTest extends TestCase
{
use RefreshDatabase;
/** @test */
public function articlesPageLoads(): void
{
$response = $this->get('/blog');
$response->assertViewIs('articles.index');
}
/** @test */
public function singleArticlePageLoads()
{
$article = Article::factory()->create();
$response = $this->get($article->link);
$response->assertViewIs('articles.show');
}
/** @test */
public function wrongDateInUrlRedirectsToCorrectDate()
{
$article = Article::factory()->create();
$response = $this->get('/blog/1900/01/' . $article->titleurl);
$response->assertRedirect('/blog/' . date('Y') . '/' . date('m') . '/' . $article->titleurl);
}
/** @test */
public function oldUrlsWithIdAreRedirected()
{
$article = Article::factory()->create();
$num60Id = resolve(Numbers::class)->numto60($article->id);
$response = $this->get('/blog/s/' . $num60Id);
$response->assertRedirect($article->link);
}
/** @test */
public function unknownSlugGetsNotFoundResponse()
{
$response = $this->get('/blog/' . date('Y') . '/' . date('m') . '/unknown-slug');
$response->assertNotFound();
}
/** @test */
public function unknownArticleIdGetsNotFoundResponse()
{
$response = $this->get('/blog/s/22');
$response->assertNotFound();
}
/** @test */
public function someUrlsDoNotParseCorrectly(): void
{
$response = $this->get('/blog/feed.js');
$response->assertNotFound();
}
}