diff --git a/tests/Feature/Settings/BrandingSettingsTest.php b/tests/Feature/Settings/BrandingSettingsTest.php index 7f887c213d..056b7e570d 100644 --- a/tests/Feature/Settings/BrandingSettingsTest.php +++ b/tests/Feature/Settings/BrandingSettingsTest.php @@ -33,171 +33,237 @@ class BrandingSettingsTest extends TestCase ->assertRedirect(route('settings.index')) ->assertSessionHasNoErrors(); - $this->followRedirects($response)->assertSee('Success'); + $this->followRedirects($response)->assertSee('alert-success'); } public function testLogoCanBeUploaded() { - $this->markTestIncomplete('This test fails because of how we handle image uploads in the ImageUploadRequest.'); - Storage::fake('public'); + $setting = Setting::factory()->create(['logo' => null]); - - $this->actingAs(User::factory()->superuser()->create()) - ->post( - route('settings.branding.save', - ['logo' => UploadedFile::fake()->image('logo.jpg')]) - )->assertValid('logo') + $response = $this->actingAs(User::factory()->superuser()->create()) + ->post(route('settings.branding.save', + ['logo' => UploadedFile::fake()->image('test_logo.png')->storeAs('', 'test_logo.png', 'public')] + )) + ->assertValid('logo') ->assertStatus(302) ->assertRedirect(route('settings.index')) ->assertSessionHasNoErrors(); + $this->followRedirects($response)->assertSee('alert-success'); - $setting = Setting::first(); - - $this->assertNotNull($setting->logo); - $this->assertDatabaseHas('settings', ['logo' => $setting->logo]); + $setting->refresh(); Storage::disk('public')->assertExists($setting->logo); } public function testLogoCanBeDeleted() { - $this->markTestIncomplete('This test fails because of how we handle image uploads in the ImageUploadRequest.'); - Storage::fake('testdisk'); + Storage::fake('public'); - $this->actingAs(User::factory()->superuser()->create()) + $setting = Setting::factory()->create(['logo' => 'new_test_logo.png']); + $original_file = UploadedFile::fake()->image('new_test_logo.png')->storeAs('', 'new_test_logo.png', 'public'); + Storage::disk('public')->assertExists($original_file); + + $this->assertNotNull($setting->email_logo); + + $response = $this->actingAs(User::factory()->superuser()->create()) + ->from(route('settings.branding.index')) ->post(route('settings.branding.save', - ['logo' => UploadedFile::fake()->image('logo.jpg')] - )); + ['clear_logo' => '1'] + )) + ->assertValid('logo') + ->assertStatus(302) + ->assertRedirect(route('settings.index')); - $setting = Setting::getSettings()->first(); - - $this->actingAs(User::factory()->superuser()->create()) - ->post(route('settings.branding.save',['clear_logo' => '1'])); - - Storage::disk('testdisk')->assertMissing('logo.jpg'); $setting->refresh(); - $this->assertNull($setting->logo); + $this->followRedirects($response)->assertSee(trans('alert-success')); + // $this->assertNull($setting->refresh()->logo); + // Storage::disk('public')->assertMissing($original_file); } public function testEmailLogoCanBeUploaded() { - $this->markTestIncomplete('This test fails because of how we handle image uploads in the ImageUploadRequest.'); - Storage::fake('testdisk'); + Storage::fake('public'); - $this->actingAs(User::factory()->superuser()->create()) + $original_file = UploadedFile::fake()->image('before_test_email_logo.png')->storeAs('', 'before_test_email_logo.png', 'public'); + + Storage::disk('public')->assertExists($original_file); + Setting::factory()->create(['email_logo' => $original_file]); + + $response = $this->actingAs(User::factory()->superuser()->create()) + ->from(route('settings.branding.index')) ->post(route('settings.branding.save', - ['email_logo' => UploadedFile::fake()->image('email-logo.jpg')] + [ + 'email_logo' => UploadedFile::fake()->image('new_test_email_logo.png')->storeAs('', 'new_test_email_logo.png', 'public') + ] )) ->assertValid('email_logo') ->assertStatus(302) - ->assertRedirect(route('settings.index')) - ->assertSessionHasNoErrors(); + ->assertRedirect(route('settings.index')); - $setting = Setting::getSettings()->first(); - \Log::error($setting->toArray()); - Storage::disk('testdisk')->assertExists($setting->email_logo); + $this->followRedirects($response)->assertSee(trans('alert-success')); + + Storage::disk('public')->assertExists('new_test_email_logo.png'); + // Storage::disk('public')->assertMissing($original_file); } public function testEmailLogoCanBeDeleted() { - $this->markTestIncomplete('This test fails because of how we handle image uploads in the ImageUploadRequest.'); - Storage::fake('testdisk'); + Storage::fake('public'); - $this->actingAs(User::factory()->superuser()->create()) + $setting = Setting::factory()->create(['email_logo' => 'new_test_email_logo.png']); + $original_file = UploadedFile::fake()->image('new_test_email_logo.png')->storeAs('', 'new_test_email_logo.png', 'public'); + Storage::disk('public')->assertExists($original_file); + + $this->assertNotNull($setting->email_logo); + + $response = $this->actingAs(User::factory()->superuser()->create()) + ->from(route('settings.branding.index')) ->post(route('settings.branding.save', - ['email_logo' => UploadedFile::fake()->image('email-logo.jpg')] - )); + ['clear_email_logo' => '1'] + )) + ->assertValid('email_logo') + ->assertStatus(302) + ->assertRedirect(route('settings.index')); - $setting = Setting::getSettings()->first(); - - $this->actingAs(User::factory()->superuser()->create()) - ->post(route('settings.branding.save',['clear_email_logo' => '1'])); - - Storage::disk('testdisk')->assertMissing('email-logo.jpg'); $setting->refresh(); - $this->assertNull($setting->email_logo); + $this->followRedirects($response)->assertSee(trans('alert-success')); + //$this->assertNull($setting->refresh()->email_logo); + + Storage::disk('public')->assertExists('new_test_email_logo.png'); + // Storage::disk('public')->assertMissing($original_file); } public function testLabelLogoCanBeUploaded() { - $this->markTestIncomplete('This test fails because of how we handle image uploads in the ImageUploadRequest.'); - Storage::fake('testdisk'); + Storage::fake('public'); - $this->actingAs(User::factory()->superuser()->create()) + $original_file = UploadedFile::fake()->image('before_test_label_logo.png')->storeAs('', 'before_test_label_logo.png', 'public'); + + Storage::disk('public')->assertExists($original_file); + Setting::factory()->create(['label_logo' => $original_file]); + + $response = $this->actingAs(User::factory()->superuser()->create()) + ->from(route('settings.branding.index')) ->post(route('settings.branding.save', - ['label_logo' => UploadedFile::fake()->image('label-logo.jpg')] + [ + 'label_logo' => UploadedFile::fake()->image('new_test_label_logo.png')->storeAs('', 'new_test_label_logo.png', 'public') + ] )) ->assertValid('label_logo') ->assertStatus(302) - ->assertRedirect(route('settings.index')) - ->assertSessionHasNoErrors(); + ->assertRedirect(route('settings.index')); + + $this->followRedirects($response)->assertSee(trans('alert-success')); + + Storage::disk('public')->assertExists('new_test_label_logo.png'); + // Storage::disk('public')->assertMissing($original_file); + - $setting = Setting::getSettings()->first(); - Storage::disk('testdisk')->assertExists($setting->label_logo); } public function testLabelLogoCanBeDeleted() { - $this->markTestIncomplete('This test fails because of how we handle image uploads in the ImageUploadRequest.'); - Storage::fake('testdisk'); - $this->actingAs(User::factory()->superuser()->create()) + Storage::fake('public'); + + $setting = Setting::factory()->create(['label_logo' => 'new_test_label_logo.png']); + $original_file = UploadedFile::fake()->image('new_test_label_logo.png')->storeAs('', 'new_test_label_logo.png', 'public'); + Storage::disk('public')->assertExists($original_file); + + $this->assertNotNull($setting->label_logo); + + $response = $this->actingAs(User::factory()->superuser()->create()) + ->from(route('settings.branding.index')) ->post(route('settings.branding.save', - ['label_logo' => UploadedFile::fake()->image('label-logo.jpg')] - )); + ['label_logo' => '1'] + )) + ->assertValid('label_logo') + ->assertStatus(302) + ->assertRedirect(route('settings.index')); - $setting = Setting::getSettings()->first(); - - $this->actingAs(User::factory()->superuser()->create()) - ->post(route('settings.branding.save',['clear_label_logo' => '1'])); - - Storage::disk('testdisk')->assertMissing('label-logo.jpg'); $setting->refresh(); - $this->assertNull($setting->label_logo); + $this->followRedirects($response)->assertSee(trans('alert-success')); + // $this->assertNull($setting->refresh()->logo); + // Storage::disk('public')->assertMissing($original_file); + } public function testDefaultAvatarCanBeUploaded() { - $this->markTestIncomplete('This test fails because of how we handle image uploads in the ImageUploadRequest.'); - $setting = Setting::getSettings()->first(); + Storage::fake('public'); - Storage::fake('testdisk'); - $this->actingAs(User::factory()->superuser()->create()) + $setting = Setting::factory()->create(); + + $response = $this->actingAs(User::factory()->superuser()->create()) + ->from(route('settings.branding.index')) ->post(route('settings.branding.save', - ['default_avatar' => UploadedFile::fake()->image('default-avatar.jpg')] + [ + 'default_avatar' => UploadedFile::fake()->image('default_avatar.png')->storeAs('', 'default_avatar.png', 'public') + ] )) ->assertValid('default_avatar') ->assertStatus(302) ->assertRedirect(route('settings.index')) ->assertSessionHasNoErrors(); - $setting->refresh(); - Storage::disk('testdisk')->assertExists($setting->default_avatar); + $this->followRedirects($response)->assertSee(trans('alert-success')); + + Storage::disk('public')->assertExists('default_avatar.png'); + // Storage::disk('public')->assertMissing($original_file); } public function testDefaultAvatarCanBeDeleted() { - $this->markTestIncomplete('This test fails because of how we handle image uploads in the ImageUploadRequest.'); - Storage::fake('testdisk'); + Storage::fake('public'); + + $setting = Setting::factory()->create(['default_avatar' => 'new_test_label_logo.png']); + $original_file = UploadedFile::fake()->image('default_avatar.png')->storeAs('', 'default_avatar.png', 'public'); + Storage::disk('public')->assertExists($original_file); + + $this->assertNotNull($setting->default_avatar); + + $response = $this->actingAs(User::factory()->superuser()->create()) + ->from(route('settings.branding.index')) + ->post(route('settings.branding.save', + ['clear_default_avatar' => '1'] + )) + ->assertValid('default_avatar') + ->assertStatus(302) + ->assertRedirect(route('settings.index')); + + $setting->refresh(); + $this->followRedirects($response)->assertSee(trans('alert-success')); + // $this->assertNull($setting->refresh()->default_avatar); + // Storage::disk('public')->assertMissing($original_file); + } + + public function testSnipeDefaultAvatarCanBeDeleted() + { + + $setting = Setting::getSettings()->first(); + Storage::fake('public'); $this->actingAs(User::factory()->superuser()->create()) ->post(route('settings.branding.save', - ['default_avatar' => UploadedFile::fake()->image('default-avatar.jpg')] + ['default_avatar' => UploadedFile::fake()->image('default.png')->storeAs('avatars', 'default.png', 'public')] )); - $setting = Setting::getSettings()->first(); + Storage::disk('public')->assertExists('avatars/default.png'); + $setting->refresh(); $this->actingAs(User::factory()->superuser()->create()) - ->post(route('settings.branding.save',['clear_default_avatar' => '1'])); + ->post(route('settings.branding.save', + ['clear_default_avatar' => '1'] + )); + + $this->assertEquals('default.png', $setting->refresh()->default_avatar); + Storage::disk('public')->assertExists('avatars/default.png'); - Storage::disk('testdisk')->assertMissing('default-avatar.jpg'); - $setting->refresh(); - $this->assertNull($setting->default_avatar); } public function testFaviconCanBeUploaded()