From 64646e960a9c5ea6839e30215b65780602ac37ea Mon Sep 17 00:00:00 2001 From: Rastislav Chynoransky Date: Fri, 19 Jan 2024 18:29:46 +0100 Subject: [PATCH] [item] fix tests --- app/Enums/FrontendEnum.php | 8 ++++++++ config/app.php | 3 ++- database/factories/ItemFactory.php | 11 +++++++++++ tests/BrowserKit/ZoomViewTest.php | 6 +++--- tests/Feature/Api/V2/ItemsTest.php | 2 +- tests/Feature/SharedUserCollectionsTest.php | 2 +- tests/Views/Frontend/ImageViewTest.php | 2 +- tests/Views/Frontend/ItemViewTest.php | 4 ++-- tests/Views/Frontend/PatternLibViewTest.php | 2 +- tests/Views/Frontend/WebRoutesViewTest.php | 10 +++++----- 10 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 app/Enums/FrontendEnum.php diff --git a/app/Enums/FrontendEnum.php b/app/Enums/FrontendEnum.php new file mode 100644 index 000000000..58080e249 --- /dev/null +++ b/app/Enums/FrontendEnum.php @@ -0,0 +1,8 @@ + 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), ]; diff --git a/database/factories/ItemFactory.php b/database/factories/ItemFactory.php index 940da0d56..299663ef6 100644 --- a/database/factories/ItemFactory.php +++ b/database/factories/ItemFactory.php @@ -2,6 +2,9 @@ namespace Database\Factories; +use App\Enums\FrontendEnum; +use App\Frontend; +use App\Item; use Illuminate\Database\Eloquent\Factories\Factory; /** @@ -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) + ); + } } diff --git a/tests/BrowserKit/ZoomViewTest.php b/tests/BrowserKit/ZoomViewTest.php index dbf0d404c..17b786579 100644 --- a/tests/BrowserKit/ZoomViewTest.php +++ b/tests/BrowserKit/ZoomViewTest.php @@ -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); @@ -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', @@ -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', diff --git a/tests/Feature/Api/V2/ItemsTest.php b/tests/Feature/Api/V2/ItemsTest.php index c82abbb83..f80df3ffe 100644 --- a/tests/Feature/Api/V2/ItemsTest.php +++ b/tests/Feature/Api/V2/ItemsTest.php @@ -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', diff --git a/tests/Feature/SharedUserCollectionsTest.php b/tests/Feature/SharedUserCollectionsTest.php index 7ed1a42a4..45d33db37 100644 --- a/tests/Feature/SharedUserCollectionsTest.php +++ b/tests/Feature/SharedUserCollectionsTest.php @@ -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]]) diff --git a/tests/Views/Frontend/ImageViewTest.php b/tests/Views/Frontend/ImageViewTest.php index 709feb867..db0899bbc 100644 --- a/tests/Views/Frontend/ImageViewTest.php +++ b/tests/Views/Frontend/ImageViewTest.php @@ -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); } diff --git a/tests/Views/Frontend/ItemViewTest.php b/tests/Views/Frontend/ItemViewTest.php index b7b14bb81..8bf334763 100644 --- a/tests/Views/Frontend/ItemViewTest.php +++ b/tests/Views/Frontend/ItemViewTest.php @@ -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', diff --git a/tests/Views/Frontend/PatternLibViewTest.php b/tests/Views/Frontend/PatternLibViewTest.php index e740e5588..50665cc73 100644 --- a/tests/Views/Frontend/PatternLibViewTest.php +++ b/tests/Views/Frontend/PatternLibViewTest.php @@ -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); diff --git a/tests/Views/Frontend/WebRoutesViewTest.php b/tests/Views/Frontend/WebRoutesViewTest.php index 130f5cc01..2321438ea 100644 --- a/tests/Views/Frontend/WebRoutesViewTest.php +++ b/tests/Views/Frontend/WebRoutesViewTest.php @@ -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('/'); } @@ -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', ]); @@ -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); } @@ -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); }