You've already forked Atomcms-edit
Initial commit
This commit is contained in:
Executable
+297
@@ -0,0 +1,297 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Shop\WebsiteShopArticle;
|
||||
use App\Models\Shop\WebsiteShopCategory;
|
||||
|
||||
test('shop page loads without category', function () {
|
||||
installHotel();
|
||||
|
||||
$category = WebsiteShopCategory::factory()->create();
|
||||
$article = WebsiteShopArticle::factory()->create([
|
||||
'name' => 'Test Item',
|
||||
'info' => 'Test description',
|
||||
'costs' => 1000,
|
||||
]);
|
||||
|
||||
$response = $this->get('/shop');
|
||||
|
||||
// Status check
|
||||
$response->assertStatus(200);
|
||||
|
||||
// Content checks
|
||||
$response->assertSee('Test Item');
|
||||
$response->assertSee('Test description');
|
||||
|
||||
// Database checks
|
||||
$this->assertDatabaseHas('website_shop_articles', [
|
||||
'id' => $article->id,
|
||||
'name' => 'Test Item',
|
||||
'costs' => 1000,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('website_shop_categories', [
|
||||
'id' => $category->id,
|
||||
]);
|
||||
|
||||
// Object checks
|
||||
expect($article->name)->toBe('Test Item');
|
||||
expect($article->costs)->toBe(1000);
|
||||
expect($article->info)->toBe('Test description');
|
||||
|
||||
// Type checks
|
||||
expect($article->name)->toBeString();
|
||||
expect($article->costs)->toBeInt();
|
||||
expect($article->info)->toBeString();
|
||||
|
||||
// Count checks
|
||||
expect(WebsiteShopArticle::count())->toBe(1);
|
||||
expect(WebsiteShopCategory::count())->toBe(1);
|
||||
});
|
||||
|
||||
test('shop page loads with item', function () {
|
||||
installHotel();
|
||||
|
||||
$article = WebsiteShopArticle::factory()->create([
|
||||
'name' => 'Special Item',
|
||||
'costs' => 500,
|
||||
]);
|
||||
|
||||
$response = $this->get('/shop');
|
||||
|
||||
// Status check
|
||||
$response->assertStatus(200);
|
||||
|
||||
// Content checks
|
||||
$response->assertSee('Special Item');
|
||||
|
||||
// Database checks
|
||||
$this->assertDatabaseHas('website_shop_articles', [
|
||||
'id' => $article->id,
|
||||
'name' => 'Special Item',
|
||||
'costs' => 500,
|
||||
]);
|
||||
|
||||
// Object checks
|
||||
expect($article->name)->toBe('Special Item');
|
||||
expect($article->costs)->toBe(500);
|
||||
});
|
||||
|
||||
test('shop page shows multiple items', function () {
|
||||
installHotel();
|
||||
|
||||
$item1 = WebsiteShopArticle::factory()->create(['name' => 'Item 1', 'costs' => 100]);
|
||||
$item2 = WebsiteShopArticle::factory()->create(['name' => 'Item 2', 'costs' => 200]);
|
||||
$item3 = WebsiteShopArticle::factory()->create(['name' => 'Item 3', 'costs' => 300]);
|
||||
|
||||
$response = $this->get('/shop');
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
// All items should be visible
|
||||
$response->assertSee('Item 1');
|
||||
$response->assertSee('Item 2');
|
||||
$response->assertSee('Item 3');
|
||||
|
||||
// Count check
|
||||
expect(WebsiteShopArticle::count())->toBe(3);
|
||||
|
||||
// Database checks
|
||||
$this->assertDatabaseHas('website_shop_articles', ['name' => 'Item 1']);
|
||||
$this->assertDatabaseHas('website_shop_articles', ['name' => 'Item 2']);
|
||||
$this->assertDatabaseHas('website_shop_articles', ['name' => 'Item 3']);
|
||||
});
|
||||
|
||||
test('shop items have correct prices', function () {
|
||||
installHotel();
|
||||
|
||||
$cheapItem = WebsiteShopArticle::factory()->create(['name' => 'Cheap', 'costs' => 10]);
|
||||
$expensiveItem = WebsiteShopArticle::factory()->create(['name' => 'Expensive', 'costs' => 10000]);
|
||||
|
||||
$response = $this->get('/shop');
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$response->assertSee('Cheap');
|
||||
$response->assertSee('Expensive');
|
||||
|
||||
// Price checks
|
||||
expect($cheapItem->costs)->toBe(10);
|
||||
expect($expensiveItem->costs)->toBe(10000);
|
||||
expect($expensiveItem->costs)->toBeGreaterThan($cheapItem->costs);
|
||||
});
|
||||
|
||||
test('shop items can have categories', function () {
|
||||
installHotel();
|
||||
|
||||
$category = WebsiteShopCategory::factory()->create(['name' => 'Furniture']);
|
||||
$article = WebsiteShopArticle::factory()->create([
|
||||
'name' => 'Chair',
|
||||
'costs' => 100,
|
||||
'category_id' => $category->id,
|
||||
]);
|
||||
|
||||
$response = $this->get('/shop');
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$response->assertSee('Chair');
|
||||
|
||||
// Relationship check
|
||||
expect($article->category_id)->toBe($category->id);
|
||||
|
||||
// Database checks
|
||||
$this->assertDatabaseHas('website_shop_articles', [
|
||||
'id' => $article->id,
|
||||
'category_id' => $category->id,
|
||||
]);
|
||||
});
|
||||
|
||||
test('shop page with no items shows empty state', function () {
|
||||
installHotel();
|
||||
|
||||
// Ensure no items exist
|
||||
WebsiteShopArticle::query()->delete();
|
||||
|
||||
$response = $this->get('/shop');
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
// Count check
|
||||
expect(WebsiteShopArticle::count())->toBe(0);
|
||||
});
|
||||
|
||||
test('shop item has all required fields', function () {
|
||||
installHotel();
|
||||
|
||||
$article = WebsiteShopArticle::factory()->create([
|
||||
'name' => 'Complete Item',
|
||||
'info' => 'Item description',
|
||||
'costs' => 500,
|
||||
]);
|
||||
|
||||
// All fields should be present
|
||||
expect($article->id)->toBeInt();
|
||||
expect($article->id)->toBeGreaterThan(0);
|
||||
expect($article->name)->toBeString();
|
||||
expect($article->info)->toBeString();
|
||||
expect($article->costs)->toBeInt();
|
||||
|
||||
// Not null checks
|
||||
expect($article->name)->not->toBeNull();
|
||||
expect($article->costs)->not->toBeNull();
|
||||
|
||||
// Database verification
|
||||
$this->assertDatabaseHas('website_shop_articles', [
|
||||
'name' => 'Complete Item',
|
||||
'info' => 'Item description',
|
||||
'costs' => 500,
|
||||
]);
|
||||
});
|
||||
|
||||
test('shop item can be updated', function () {
|
||||
installHotel();
|
||||
|
||||
$article = WebsiteShopArticle::factory()->create([
|
||||
'name' => 'Old Name',
|
||||
'costs' => 100,
|
||||
]);
|
||||
|
||||
// Update article
|
||||
$article->name = 'New Name';
|
||||
$article->costs = 200;
|
||||
$article->save();
|
||||
|
||||
$article->refresh();
|
||||
|
||||
expect($article->name)->toBe('New Name');
|
||||
expect($article->costs)->toBe(200);
|
||||
|
||||
$this->assertDatabaseHas('website_shop_articles', [
|
||||
'id' => $article->id,
|
||||
'name' => 'New Name',
|
||||
'costs' => 200,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseMissing('website_shop_articles', [
|
||||
'id' => $article->id,
|
||||
'name' => 'Old Name',
|
||||
]);
|
||||
});
|
||||
|
||||
test('shop item can be deleted', function () {
|
||||
installHotel();
|
||||
|
||||
$article = WebsiteShopArticle::factory()->create(['name' => 'To Delete']);
|
||||
$articleId = $article->id;
|
||||
|
||||
expect(WebsiteShopArticle::find($articleId))->not->toBeNull();
|
||||
|
||||
$article->delete();
|
||||
|
||||
expect(WebsiteShopArticle::find($articleId))->toBeNull();
|
||||
expect(WebsiteShopArticle::count())->toBe(0);
|
||||
|
||||
$this->assertDatabaseMissing('website_shop_articles', [
|
||||
'id' => $articleId,
|
||||
]);
|
||||
});
|
||||
|
||||
test('shop with multiple categories', function () {
|
||||
installHotel();
|
||||
|
||||
$category1 = WebsiteShopCategory::factory()->create(['name' => 'Category 1']);
|
||||
$category2 = WebsiteShopCategory::factory()->create(['name' => 'Category 2']);
|
||||
|
||||
$item1 = WebsiteShopArticle::factory()->create([
|
||||
'name' => 'Item in Cat 1',
|
||||
'category_id' => $category1->id,
|
||||
]);
|
||||
|
||||
$item2 = WebsiteShopArticle::factory()->create([
|
||||
'name' => 'Item in Cat 2',
|
||||
'category_id' => $category2->id,
|
||||
]);
|
||||
|
||||
$response = $this->get('/shop');
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('Item in Cat 1');
|
||||
$response->assertSee('Item in Cat 2');
|
||||
|
||||
expect(WebsiteShopCategory::count())->toBe(2);
|
||||
expect(WebsiteShopArticle::count())->toBe(2);
|
||||
});
|
||||
|
||||
test('shop item with zero cost', function () {
|
||||
installHotel();
|
||||
|
||||
$freeItem = WebsiteShopArticle::factory()->create([
|
||||
'name' => 'Free Item',
|
||||
'costs' => 0,
|
||||
]);
|
||||
|
||||
$response = $this->get('/shop');
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('Free Item');
|
||||
|
||||
expect($freeItem->costs)->toBe(0);
|
||||
expect($freeItem->costs)->toBeInt();
|
||||
});
|
||||
|
||||
test('shop item with very high cost', function () {
|
||||
installHotel();
|
||||
|
||||
$expensiveItem = WebsiteShopArticle::factory()->create([
|
||||
'name' => 'Luxury Item',
|
||||
'costs' => 999999,
|
||||
]);
|
||||
|
||||
$response = $this->get('/shop');
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('Luxury Item');
|
||||
|
||||
expect($expensiveItem->costs)->toBe(999999);
|
||||
expect($expensiveItem->costs)->toBeGreaterThan(0);
|
||||
});
|
||||
Reference in New Issue
Block a user