Skip to content

Commit

Permalink
request: remove request class dependecies from the repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
suraj-webkul committed Feb 21, 2024
1 parent 7102d2e commit 168b17f
Show file tree
Hide file tree
Showing 38 changed files with 344 additions and 284 deletions.
6 changes: 2 additions & 4 deletions packages/Webkul/Admin/src/Database/Factories/ThemeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ class ThemeFactory extends Factory
*/
public function definition()
{
$lastTheme = ThemeCustomizationModel::query()->orderBy('id', 'desc')->limit(1)->first();

$types = ['product_carousel', 'category_carousel', 'image_carousel', 'footer_links', 'services_content'];
$types = ['product_carousel', 'category_carousel', 'image_carousel', 'footer_links', 'services_content', 'static_content'];

return [
'type' => $this->faker->randomElement($types),
'name' => $this->faker->name,
'sort_order' => ($lastTheme ? $lastTheme->id : 0) + 1,
'sort_order' => 1,
'channel_id' => core()->getCurrentChannel()->id,
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,11 @@ public function search()
'name' => request('query'),
'sort' => 'created_at',
'order' => 'desc',
'path' => request()->url(),
'query_data' => request()->query(),
]);

$products = $this->productRepository->searchFromDatabase();
$products = $this->productRepository->searchFromDatabase(request()->input());

foreach ($products as $product) {
$results[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ public function store()

/* design */
'theme' => 'nullable',
'logo.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp',
'favicon.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp,ico',
'logo' => 'array',
'logo.*' => 'image|mimes:bmp,jpeg,jpg,png,webp',
'favicon' => 'array',
'favicon.*' => 'image|mimes:bmp,jpeg,jpg,png,webp,ico',

/* seo */
'seo_title' => 'required|string',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,4 +461,4 @@ class="block leading-5 text-xs text-gray-600 dark:text-gray-300 font-medium"
});
</script>
@endPushOnce
@endif
@endif
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
$this->loginAsAdmin();

postJson(route('admin.catalog.families.store'), [
'code' => $code = strtolower(fake()->words(1, true)),
'code' => $code = fake()->regexify('/^[a-zA-Z]+[a-zA-Z0-9_]+$/'),
'name' => $name = fake()->name(),
'attribute_groups' => [
[
Expand Down Expand Up @@ -116,7 +116,7 @@
$this->loginAsAdmin();

putJson(route('admin.catalog.families.update', $attributeFamily->id), [
'code' => $updatedCode = strtolower(fake()->words(1, true)),
'code' => $updatedCode = fake()->regexify('/^[a-zA-Z]+[a-zA-Z0-9_]+$/'),
'name' => $attributeFamily->name,
])
->assertRedirectToRoute('admin.catalog.families.index')
Expand Down
5 changes: 2 additions & 3 deletions packages/Webkul/Admin/tests/Feature/Catalog/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
])
->assertOk()
->assertJsonPath('records.0.id', $attribute->id)
->assertJsonPath('records.0.code', $attribute->code)
->assertJsonPath('meta.total', 29);
->assertJsonPath('records.0.code', $attribute->code);
});

it('should returns attributes options', function () {
Expand Down Expand Up @@ -73,7 +72,7 @@

postJson(route('admin.catalog.attributes.store'), [
'admin_name' => $name = fake()->name(),
'code' => $code = strtolower(fake()->word()),
'code' => $code = fake()->regexify('/^[a-zA-Z]+[a-zA-Z0-9_]+$/'),
'type' => 'text',
'default_value' => 1,
])
Expand Down
19 changes: 16 additions & 3 deletions packages/Webkul/Admin/tests/Feature/Catalog/CategoryTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Illuminate\Http\UploadedFile;
use Webkul\Attribute\Models\Attribute;
use Webkul\Category\Models\Category;
use Webkul\Category\Models\CategoryTranslation;
Expand Down Expand Up @@ -60,6 +61,12 @@
'position' => rand(1, 5),
'description' => $description = substr(fake()->paragraph(), 0, 50),
'attributes' => $attributes,
'logo_path' => [
UploadedFile::fake()->image('logo_path.jpg'),
],
'banner_path' => [
UploadedFile::fake()->image('banner_path.jpg'),
],
])
->assertRedirect(route('admin.catalog.categories.index'))
->isRedirection();
Expand Down Expand Up @@ -186,9 +193,15 @@
'description' => $description = substr(fake()->paragraph(), 0, 50),
],

'locale' => config('app.locale'),
'attributes' => $attributes,
'position' => rand(1, 5),
'locale' => config('app.locale'),
'attributes' => $attributes,
'position' => rand(1, 5),
'logo_path' => [
UploadedFile::fake()->image('logo_path.jpg'),
],
'banner_path' => [
UploadedFile::fake()->image('banner_path.jpg'),
],
])
->assertRedirect(route('admin.catalog.categories.index'))
->isRedirection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
$this->loginAsAdmin();

postJson(route('admin.customers.groups.store'), [
'code' => $code = strtolower(fake()->words(1, true)),
'code' => $code = fake()->regexify('/^[a-zA-Z]+[a-zA-Z0-9_]+$/'),
'name' => $name = fake()->name(),
])
->assertOk()
Expand Down
45 changes: 45 additions & 0 deletions packages/Webkul/Admin/tests/Feature/Settings/ChannelsTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Illuminate\Http\UploadedFile;
use Webkul\Core\Models\Channel;

use function Pest\Laravel\deleteJson;
Expand Down Expand Up @@ -46,6 +47,38 @@
->assertUnprocessable();
});

it('should not store the new channel if the file has been tampered with', function () {
// Act and Assert
$this->loginAsAdmin();

postJson(route('admin.settings.channels.store'), [
'code' => $code = fake()->regexify('/^[a-zA-Z]+[a-zA-Z0-9_]+$/'),
'theme' => $code,
'hostname' => 'http://'.fake()->ipv4(),
'root_category_id' => 1,
'default_locale_id' => 1,
'base_currency_id' => 1,
'name' => fake()->name(),
'description' => substr(fake()->paragraph, 0, 50),
'inventory_sources' => [1],
'locales' => [1],
'currencies' => [1],
'seo_title' => fake()->title(),
'seo_description' => substr(fake()->paragraph(), 0, 50),
'seo_keywords' => fake()->name(),
'is_maintenance_on' => fake()->boolean(),
'logo' => [
UploadedFile::fake()->image('tampered1.php'),
],
'favicon' => [
UploadedFile::fake()->image('tampered2.php'),
],
])
->assertJsonValidationErrorFor('logo.0')
->assertJsonValidationErrorFor('favicon.0')
->assertUnprocessable();
});

it('should store the newly created channels', function () {
// Act and Assert
$this->loginAsAdmin();
Expand All @@ -66,6 +99,12 @@
'seo_description' => substr(fake()->paragraph(), 0, 50),
'seo_keywords' => fake()->name(),
'is_maintenance_on' => fake()->boolean(),
'logo' => [
UploadedFile::fake()->image('logo.png'),
],
'favicon' => [
UploadedFile::fake()->image('favicon.png'),
],
])
->assertRedirect(route('admin.settings.channels.index'))
->isRedirection();
Expand Down Expand Up @@ -142,6 +181,12 @@
'locales' => [1],
'currencies' => [1],
'is_maintenance_on' => fake()->boolean(),
'logo' => [
UploadedFile::fake()->image('logo.png'),
],
'favicon' => [
UploadedFile::fake()->image('favicon.png'),
],
])
->assertRedirect(route('admin.settings.channels.index'))
->isRedirection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
$this->loginAsAdmin();

postJson(route('admin.settings.inventory_sources.store'), [
'code' => $code = strtolower(fake()->word),
'code' => $code = fake()->regexify('/^[a-zA-Z]+[a-zA-Z0-9_]+$/'),
'name' => $name = fake()->name(),
'priority' => $priority = rand(1, 10),
'contact_number' => $contactNumber = rand(1111111111, 9999999999),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
$this->loginAsAdmin();

postJson(route('admin.settings.taxes.categories.store'), [
'code' => $code = fake()->uuid(),
'code' => $code = fake()->regexify('/^[a-zA-Z]+[a-zA-Z0-9_]+$/'),
'name' => $name = fake()->words(2, true),
'description' => $description = fake()->sentence(10),
'taxrates' => TaxRate::factory()->count(2)->create()->pluck('id')->toArray(),
Expand Down Expand Up @@ -94,7 +94,7 @@

putJson(route('admin.settings.taxes.categories.update'), [
'id' => $taxCategory->id,
'code' => $code = fake()->uuid(),
'code' => $code = fake()->regexify('/^[a-zA-Z]+[a-zA-Z0-9_]+$/'),
'name' => $name = fake()->words(2, true),
'description' => $description = fake()->sentence(10),
'taxrates' => TaxRate::factory()->count(2)->create()->pluck('id')->toArray(),
Expand Down
10 changes: 10 additions & 0 deletions packages/Webkul/Admin/tests/Feature/Settings/ThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@
],
];

break;

case ThemeCustomization::STATIC_CONTENT:
$data[app()->getLocale()] = [
'options' => [
'html' => fake()->randomHtml(),
'css' => '<style>body{color:red;}</style>',
],
];

break;
}

Expand Down

0 comments on commit 168b17f

Please sign in to comment.