Skip to content

Commit

Permalink
[item] fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rastislav-chynoransky committed Jan 19, 2024
1 parent d8ba325 commit 64646e9
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 15 deletions.
8 changes: 8 additions & 0 deletions app/Enums/FrontendEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace App\Enums;

enum FrontendEnum: string
{
case WEBUMENIA = 'webumenia.sk';
}
3 changes: 2 additions & 1 deletion config/app.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Enums\FrontendEnum;
use Illuminate\Support\Facades\Facade;

return [
Expand Down Expand Up @@ -225,5 +226,5 @@
'iip_private' => env('IIP_PRIVATE', 'http://127.0.0.1:8002'),
'iip_public' => env('IIP_PUBLIC', 'https://img.webumenia.sk'),

'frontend' => env('APP_FRONTEND', 'webumenia.sk'),
'frontend' => env('APP_FRONTEND', FrontendEnum::WEBUMENIA->value),
];
11 changes: 11 additions & 0 deletions database/factories/ItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Database\Factories;

use App\Enums\FrontendEnum;
use App\Frontend;
use App\Item;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
Expand Down Expand Up @@ -44,4 +47,12 @@ public function definition()
'updated_at' => fake()->date,
];
}

public function webumeniaFrontend()
{
$webumeniaFrontend = Frontend::where('name', FrontendEnum::WEBUMENIA)->first();
return $this->afterCreating(fn (Item $item) =>
$item->frontends()->attach($webumeniaFrontend)
);
}
}
6 changes: 3 additions & 3 deletions tests/BrowserKit/ZoomViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ZoomViewTest extends TestCase

public function testMultipleImages()
{
$item = Item::factory()->create();
$item = Item::factory()->webumeniaFrontend()->create();

$image = ItemImage::factory()->make();
$image->item()->associate($item);
Expand All @@ -32,7 +32,7 @@ public function testRelatedItems()
{
$related_items = [];
for ($i = 0; $i < ($count = 2); $i++) {
$item = Item::factory()->create([
$item = Item::factory()->webumeniaFrontend()->create([
'related_work' => 'some_related_work',
'related_work_order' => $i,
'author' => 'some_author',
Expand All @@ -57,7 +57,7 @@ public function testRelatedItems()
public function testPrioritizedMultipleImages()
{
$count = 2;
$item = Item::factory()->create([
$item = Item::factory()->webumeniaFrontend()->create([
'related_work' => 'some_related_work',
'related_work_order' => 2,
'author' => 'some_author',
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Api/V2/ItemsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function test_detail()
{
$authority = Authority::factory()->create(['name' => 'Wouwerman, Philips']);
$item_image = ItemImage::factory()->make(['iipimg_url' => 'test_iipimg_url']);
$item = Item::factory()->create([
$item = Item::factory()->webumeniaFrontend()->create([
'id' => 'test_id',
'title' => 'test_title',
'author' => 'Věšín, Jaroslav',
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/SharedUserCollectionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SharedUserCollectionsTest extends TestCase

public function testCreation()
{
$item = Item::factory()->create();
$item = Item::factory()->webumeniaFrontend()->create();

$this->get(
route('frontend.shared-user-collections.create', ['ids' => [$item->id]])
Expand Down
2 changes: 1 addition & 1 deletion tests/Views/Frontend/ImageViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ImageViewTest extends TestCase

public function testGetResize()
{
$item = Item::factory()->create();
$item = Item::factory()->webumeniaFrontend()->create();
$response = $this->get(sprintf('/dielo/nahlad/%s/800', $item->id));
$response->assertStatus(200);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Views/Frontend/ItemViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ class ItemViewTest extends TestCase

public function testGetItemDetail()
{
$item = Item::factory()->create();
$item = Item::factory()->webumeniaFrontend()->create();
$response = $this->get("/dielo/{$item->id}");
$response->assertStatus(200);
}

public function testListsAssociatedPublishedCollections()
{
$item = Item::factory()->create();
$item = Item::factory()->webumeniaFrontend()->create();
$publishedCollection = Collection::factory()->create([
'is_published' => true,
'name' => 'a published collection',
Expand Down
2 changes: 1 addition & 1 deletion tests/Views/Frontend/PatternLibViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PatternLibViewTest extends TestCase
public function testGetIndex()
{
Article::factory()->create();
$item = Item::factory()->create();
$item = Item::factory()->webumeniaFrontend()->create();
$image = ItemImage::factory()->make(['iipimg_url' => true]);
$item->images()->save($image);

Expand Down
10 changes: 5 additions & 5 deletions tests/Views/Frontend/WebRoutesViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public function testGetThankYou()

public function testGetOrderItem()
{
$item = Item::factory()->create(['gallery' => 'Slovenská národná galéria, SNG']);
$item = Item::factory()->webumeniaFrontend()->create(['gallery' => 'Slovenská národná galéria, SNG']);
$response = $this->get(sprintf('/dielo/%s/objednat', $item->id));
$response->assertRedirect(sprintf('/dielo/%s', $item->id));
}

public function testGetUnorderItem()
{
$item = Item::factory()->create();
$item = Item::factory()->webumeniaFrontend()->create();
$response = $this->get(sprintf('/dielo/%s/odstranit', $item->id));
$response->assertRedirect('/');
}
Expand All @@ -55,7 +55,7 @@ public function testGetDownloadItem()
{
$this->markTestSkipped();

$item = Item::factory()->create([
$item = Item::factory()->webumeniaFrontend()->create([
'gallery' => 'Slovenská národná galéria, SNG',
'author' => 'neznámy',
]);
Expand All @@ -76,7 +76,7 @@ public function testGetItemDetail()
->willReturn(new SearchResult(collect(), 0));
$this->app->instance(ItemRepository::class, $itemRepositoryMock);

$item = Item::factory()->create();
$item = Item::factory()->webumeniaFrontend()->create();
$response = $this->get(sprintf('/dielo/%s', $item->id));
$response->assertStatus(200);
}
Expand All @@ -92,7 +92,7 @@ public function testGetColorRelatedItems()
->willReturn(new SearchResult(collect(), 0));
$this->app->instance(ItemRepository::class, $itemRepositoryMock);

$item = Item::factory()->create();
$item = Item::factory()->webumeniaFrontend()->create();
$response = $this->get(sprintf('/dielo/%s/colorrelated', $item->id));
$response->assertStatus(200);
}
Expand Down

0 comments on commit 64646e9

Please sign in to comment.