You've already forked Atomcms-edit
241 lines
6.6 KiB
PHP
Executable File
241 lines
6.6 KiB
PHP
Executable File
<?php
|
|
|
|
use App\Models\Articles\WebsiteArticle;
|
|
|
|
test('articles index page loads', function () {
|
|
installHotel();
|
|
|
|
$article = WebsiteArticle::factory()->create([
|
|
'title' => 'Test Article',
|
|
'slug' => 'test-article',
|
|
'full_story' => 'Test content',
|
|
]);
|
|
|
|
$response = $this->get('/community/articles');
|
|
|
|
// Status check
|
|
$response->assertStatus(200);
|
|
|
|
// View check
|
|
$response->assertViewIs('community.articles');
|
|
|
|
// Content checks
|
|
$response->assertSee('Test Article');
|
|
|
|
// Database checks
|
|
$this->assertDatabaseHas('website_articles', [
|
|
'id' => $article->id,
|
|
'title' => 'Test Article',
|
|
'slug' => 'test-article',
|
|
]);
|
|
|
|
// Count check
|
|
expect(WebsiteArticle::count())->toBe(1);
|
|
|
|
// Article object checks
|
|
expect($article->id)->toBeInt();
|
|
expect($article->id)->toBeGreaterThan(0);
|
|
expect($article->title)->toBe('Test Article');
|
|
expect($article->slug)->toBe('test-article');
|
|
expect($article->full_story)->toBe('Test content');
|
|
|
|
// Type checks
|
|
expect($article->title)->toBeString();
|
|
expect($article->slug)->toBeString();
|
|
expect($article->full_story)->toBeString();
|
|
|
|
// String checks
|
|
expect($article->title)->toHaveLength(12);
|
|
expect($article->slug)->toHaveLength(12);
|
|
});
|
|
|
|
test('published article can be viewed', function () {
|
|
installHotel();
|
|
|
|
$article = WebsiteArticle::factory()->create([
|
|
'title' => 'Test Article',
|
|
'slug' => 'test-article',
|
|
'full_story' => 'Test content',
|
|
]);
|
|
|
|
$response = $this->get("/community/article/{$article->slug}");
|
|
|
|
// Status check
|
|
$response->assertStatus(200);
|
|
|
|
// View check
|
|
$response->assertViewIs('community.article');
|
|
|
|
// Content checks
|
|
$response->assertSee('Test Article');
|
|
$response->assertSee('Test content');
|
|
|
|
// Database checks
|
|
$this->assertDatabaseHas('website_articles', [
|
|
'id' => $article->id,
|
|
'title' => 'Test Article',
|
|
'slug' => 'test-article',
|
|
]);
|
|
|
|
// Retrieve and verify
|
|
$retrievedArticle = WebsiteArticle::find($article->id);
|
|
expect($retrievedArticle)->not->toBeNull();
|
|
expect($retrievedArticle->title)->toBe('Test Article');
|
|
});
|
|
|
|
test('unpublished article can be viewed', function () {
|
|
installHotel();
|
|
|
|
$article = WebsiteArticle::factory()->create([
|
|
'title' => 'Draft Article',
|
|
'slug' => 'draft-article',
|
|
'full_story' => 'Draft content',
|
|
]);
|
|
|
|
$response = $this->get("/community/article/{$article->slug}");
|
|
|
|
// Status check
|
|
$response->assertStatus(200);
|
|
|
|
// Database checks
|
|
$this->assertDatabaseHas('website_articles', [
|
|
'id' => $article->id,
|
|
'title' => 'Draft Article',
|
|
'slug' => 'draft-article',
|
|
]);
|
|
});
|
|
|
|
test('multiple articles appear on index', function () {
|
|
installHotel();
|
|
|
|
$article1 = WebsiteArticle::factory()->create(['title' => 'Article 1', 'slug' => 'article-1']);
|
|
$article2 = WebsiteArticle::factory()->create(['title' => 'Article 2', 'slug' => 'article-2']);
|
|
$article3 = WebsiteArticle::factory()->create(['title' => 'Article 3', 'slug' => 'article-3']);
|
|
|
|
$response = $this->get('/community/articles');
|
|
|
|
$response->assertStatus(200);
|
|
|
|
// All articles should be visible
|
|
$response->assertSee('Article 1');
|
|
$response->assertSee('Article 2');
|
|
$response->assertSee('Article 3');
|
|
|
|
// Count check
|
|
expect(WebsiteArticle::count())->toBe(3);
|
|
|
|
// Database checks
|
|
$this->assertDatabaseHas('website_articles', ['title' => 'Article 1']);
|
|
$this->assertDatabaseHas('website_articles', ['title' => 'Article 2']);
|
|
$this->assertDatabaseHas('website_articles', ['title' => 'Article 3']);
|
|
});
|
|
|
|
test('article with special characters in title', function () {
|
|
installHotel();
|
|
|
|
$article = WebsiteArticle::factory()->create([
|
|
'title' => 'Test & Article! @ # $ %',
|
|
'slug' => 'special-article',
|
|
'full_story' => 'Content with special chars: <>&"\'',
|
|
]);
|
|
|
|
$response = $this->get("/community/article/{$article->slug}");
|
|
|
|
$response->assertStatus(200);
|
|
|
|
// Should escape special characters
|
|
$response->assertSee('Test & Article');
|
|
});
|
|
|
|
test('article with long content', function () {
|
|
installHotel();
|
|
|
|
$longContent = str_repeat('Lorem ipsum dolor sit amet. ', 100);
|
|
|
|
$article = WebsiteArticle::factory()->create([
|
|
'title' => 'Long Article',
|
|
'slug' => 'long-article',
|
|
'full_story' => $longContent,
|
|
]);
|
|
|
|
$response = $this->get("/community/article/{$article->slug}");
|
|
|
|
$response->assertStatus(200);
|
|
|
|
// Should contain beginning of content
|
|
$response->assertSee('Lorem ipsum');
|
|
|
|
// Content length check
|
|
expect(strlen($article->full_story))->toBeGreaterThan(1000);
|
|
});
|
|
|
|
test('non-existent article returns 404', function () {
|
|
installHotel();
|
|
|
|
$response = $this->get('/community/article/non-existent-article');
|
|
|
|
expect($response->status())->toBe(404);
|
|
});
|
|
|
|
test('article url contains correct slug', function () {
|
|
installHotel();
|
|
|
|
$article = WebsiteArticle::factory()->create([
|
|
'title' => 'My Article',
|
|
'slug' => 'my-article',
|
|
]);
|
|
|
|
$url = "/community/article/{$article->slug}";
|
|
expect($url)->toBe('/community/article/my-article');
|
|
expect($url)->toContain('my-article');
|
|
expect($url)->toContain('/community/article/');
|
|
});
|
|
|
|
test('articles can be filtered or sorted', function () {
|
|
installHotel();
|
|
|
|
$oldArticle = WebsiteArticle::factory()->create([
|
|
'title' => 'Old Article',
|
|
'slug' => 'old-article',
|
|
'created_at' => now()->subDays(10),
|
|
]);
|
|
|
|
$newArticle = WebsiteArticle::factory()->create([
|
|
'title' => 'New Article',
|
|
'slug' => 'new-article',
|
|
'created_at' => now(),
|
|
]);
|
|
|
|
$response = $this->get('/community/articles');
|
|
|
|
$response->assertStatus(200);
|
|
|
|
// Both should be visible
|
|
$response->assertSee('Old Article');
|
|
$response->assertSee('New Article');
|
|
|
|
// Check order (newest first)
|
|
$content = $response->getContent();
|
|
$newPos = strpos($content, 'New Article');
|
|
$oldPos = strpos($content, 'Old Article');
|
|
expect($newPos)->toBeLessThan($oldPos);
|
|
});
|
|
|
|
test('article page has proper meta tags', function () {
|
|
installHotel();
|
|
|
|
$article = WebsiteArticle::factory()->create([
|
|
'title' => 'SEO Article',
|
|
'slug' => 'seo-article',
|
|
'full_story' => 'Content for SEO',
|
|
]);
|
|
|
|
$response = $this->get("/community/article/{$article->slug}");
|
|
|
|
$response->assertStatus(200);
|
|
|
|
// Should have proper HTML structure
|
|
$response->assertSee('<title');
|
|
$response->assertSee('<meta');
|
|
});
|