Skip to content

Commit

Permalink
Merge pull request #140 from thedevdojo/fix-background-uploads
Browse files Browse the repository at this point in the history
Fix background and logo uploads
  • Loading branch information
tnylea authored Nov 18, 2024
2 parents 224800f + 2e6d9c7 commit f6847c4
Show file tree
Hide file tree
Showing 7 changed files with 304 additions and 131 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,4 @@ jobs:
APP_URL: http://127.0.0.1:8000
APP_ENV: testing
run: php artisan dusk -vvv
working-directory: ./laravel_app
working-directory: ./laravel_app
282 changes: 155 additions & 127 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/build/assets/styles.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Livewire/Setup/Background.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function updated($property, $value)
$filename = $value->getFileName();
$extension = pathinfo($filename, PATHINFO_EXTENSION);

$value->storeAs('public/auth', 'background.'.$extension);
$value->storeAs('auth', 'background.'.$extension, 'public');
$this->image = '/storage/auth/background.'.$extension;

$this->updateConfigKeyValue('background.image', '/storage/auth/background.'.$extension);
Expand Down
2 changes: 1 addition & 1 deletion src/Livewire/Setup/Logo.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function updating($property, $value)
$filename = $value->getFileName();
$extension = pathinfo($filename, PATHINFO_EXTENSION);

$value->storeAs('public/auth', 'logo.'.$extension);
$value->storeAs('auth', 'logo.'.$extension, 'public');
$this->logo_image_src = '/storage/auth/logo.'.$extension;

$this->updateConfigKeyValue('logo.image_src', '/storage/auth/logo.'.$extension);
Expand Down
68 changes: 68 additions & 0 deletions tests/Feature/BackgroundTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

use Devdojo\Auth\Livewire\Setup\Background;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;

beforeEach(function () {
Storage::fake('public');
config()->set('devdojo.auth.appearance.background', [
'color' => '#ffffff',
'image' => '',
'image_overlay_color' => '#000000',
'image_overlay_opacity' => '0.5',
]);
});

it('loads initial background settings from config', function () {
Livewire::test(Background::class)
->assertSet('color', '#ffffff')
->assertSet('image', '')
->assertSet('image_overlay_color', '#000000')
->assertSet('image_overlay_opacity', 50);
});

it('updates background color and triggers config update', function () {
Livewire::test(Background::class)
->set('color', '#ff0000')
->assertSet('color', '#ff0000');

expect(config('devdojo.auth.appearance.background.color'))->toBe('#ff0000');
});

it('handles background image upload and storage', function () {
$file = UploadedFile::fake()->image('background.jpg');

Livewire::test(Background::class)
->set('image', $file)
->assertSet('image', '/storage/auth/background.jpg');

Storage::disk('public')->assertExists('auth/background.jpg');
expect(config('devdojo.auth.appearance.background.image'))->toBe('/storage/auth/background.jpg');
});

it('updates image overlay opacity and converts to decimal', function () {
Livewire::test(Background::class)
->set('image_overlay_opacity', 75)
->assertSet('image_overlay_opacity', 75);

expect(config('devdojo.auth.appearance.background.image_overlay_opacity'))->toBe('0.75');
});

it('updates image overlay color', function () {
Livewire::test(Background::class)
->set('image_overlay_color', '#333333')
->assertSet('image_overlay_color', '#333333');

expect(config('devdojo.auth.appearance.background.image_overlay_color'))->toBe('#333333');
});

it('handles different image file types during upload', function () {
$file = UploadedFile::fake()->image('background.png');

Livewire::test(Background::class)
->set('image', $file)
->assertSet('image', '/storage/auth/background.png');

Storage::disk('public')->assertExists('auth/background.png');
});
77 changes: 77 additions & 0 deletions tests/Feature/LogoTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

use Devdojo\Auth\Livewire\Setup\Logo;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;

beforeEach(function () {
Storage::fake('public');
config()->set('devdojo.auth.appearance.logo', [
'type' => 'text',
'image_src' => '',
'svg_string' => '',
'height' => '40',
]);
});

it('loads initial logo settings from config', function () {
Livewire::test(Logo::class)
->assertSet('logo_type', 'text')
->assertSet('logo_image_src', '')
->assertSet('logo_svg_string', '')
->assertSet('logo_height', '40')
->assertSet('logo_image', false);
});

it('updates logo type', function () {
Livewire::test(Logo::class)
->set('logo_type', 'image')
->assertSet('logo_type', 'image');

expect(config('devdojo.auth.appearance.logo.type'))->toBe('image');
});

it('handles logo image upload and storage', function () {
$file = UploadedFile::fake()->image('logo.png');

Livewire::test(Logo::class)
->set('logo_image', $file)
->assertSet('logo_image_src', '/storage/auth/logo.png');

Storage::disk('public')->assertExists('auth/logo.png');
expect(config('devdojo.auth.appearance.logo.image_src'))->toBe('/storage/auth/logo.png');
});

it('updates logo height', function () {
Livewire::test(Logo::class)
->set('logo_height', '60')
->assertSet('logo_height', '60');

expect(config('devdojo.auth.appearance.logo.height'))->toBe('60');
});

it('updates svg string', function () {
$svgString = '<svg viewBox="0 0 100 100"><circle cx="50" cy="50" r="40"/></svg>';

Livewire::test(Logo::class)
->call('updateSvg', $svgString);

expect(config('devdojo.auth.appearance.logo.svg_string'))->toBe($svgString);
});

it('handles different image file types during upload', function () {
$file = UploadedFile::fake()->image('logo.jpg');

Livewire::test(Logo::class)
->set('logo_image', $file)
->assertSet('logo_image_src', '/storage/auth/logo.jpg');

Storage::disk('public')->assertExists('auth/logo.jpg');
});

it('sets logo_image to true when logo_image_src exists on mount', function () {
config()->set('devdojo.auth.appearance.logo.image_src', '/storage/auth/existing-logo.png');

Livewire::test(Logo::class)
->assertSet('logo_image', true);
});

0 comments on commit f6847c4

Please sign in to comment.