Bubka vor 1 Jahr
Ursprung
Commit
f43fc97523

+ 8 - 0
app/Observers/UserObserver.php

@@ -13,6 +13,8 @@ class UserObserver
 {
 {
     /**
     /**
      * Handle the User "created" event.
      * Handle the User "created" event.
+     *
+     * @codeCoverageIgnore
      */
      */
     public function created(User $user) : void
     public function created(User $user) : void
     {
     {
@@ -21,6 +23,8 @@ class UserObserver
 
 
     /**
     /**
      * Handle the User "updated" event.
      * Handle the User "updated" event.
+     *
+     * @codeCoverageIgnore
      */
      */
     public function updated(User $user) : void
     public function updated(User $user) : void
     {
     {
@@ -81,6 +85,8 @@ class UserObserver
 
 
     /**
     /**
      * Handle the User "restored" event.
      * Handle the User "restored" event.
+     *
+     * @codeCoverageIgnore
      */
      */
     public function restored(User $user) : void
     public function restored(User $user) : void
     {
     {
@@ -89,6 +95,8 @@ class UserObserver
 
 
     /**
     /**
      * Handle the User "force deleted" event.
      * Handle the User "force deleted" event.
+     *
+     * @codeCoverageIgnore
      */
      */
     public function forceDeleted(User $user) : void
     public function forceDeleted(User $user) : void
     {
     {

+ 103 - 0
tests/Feature/Console/InstallTest.php

@@ -0,0 +1,103 @@
+<?php
+
+namespace Tests\Feature\Console;
+
+use App\Console\Commands\Install;
+use Jackiedo\DotenvEditor\DotenvEditor;
+use PHPUnit\Framework\Attributes\CoversClass;
+use Tests\FeatureTestCase;
+
+/**
+ * InstallTest test class
+ */
+#[CoversClass(Install::class)]
+class InstallTest extends FeatureTestCase
+{
+    /**
+     * @test
+     */
+    public function test_install_completes()
+    {
+        $this->artisan('2fauth:install')
+            ->expectsConfirmation('Existing .env file found. Do you wish to review its vars?', 'no')
+            ->assertSuccessful();
+    }
+
+    /**
+     * @test
+     */
+    public function test_install_informs_about_no_interaction()
+    {
+        $this->artisan('2fauth:install', ['--no-interaction' => true])
+            ->expectsOutput('(Running in no-interaction mode)')
+            ->expectsConfirmation('Existing .env file found. Do you wish to review its vars?', 'no')
+            ->assertSuccessful();
+    }
+
+    /**
+     * @test
+     */
+    public function test_install_generates_an_app_key()
+    {
+        config(['app.key' => '']);
+
+        $this->assertEquals('', config('app.key'));
+
+        $this->artisan('2fauth:install')
+            ->expectsConfirmation('Existing .env file found. Do you wish to review its vars?', 'no')
+            ->assertSuccessful();
+
+        $this->assertNotEquals('', config('app.key'));
+    }
+
+    /**
+     * @test
+     */
+    public function test_install_gives_2fauth_address()
+    {
+        $this->artisan('2fauth:install')
+            ->expectsConfirmation('Existing .env file found. Do you wish to review its vars?', 'no')
+            ->expectsOutputToContain(config('app.url'))
+            ->assertSuccessful();
+    }
+
+    /**
+     * @test
+     */
+    public function test_install_informs_about_sponsoring()
+    {
+        $this->artisan('2fauth:install')
+            ->expectsConfirmation('Existing .env file found. Do you wish to review its vars?', 'no')
+            ->expectsOutputToContain('https://ko-fi.com/bubka')
+            ->expectsOutputToContain('https://github.com/sponsors/Bubka')
+            ->assertSuccessful();
+    }
+
+    /**
+     * @test
+     */
+    public function test_install_fails_with_exception_message()
+    {
+        $mock = $this->mock(DotenvEditor::class);
+        $mock->shouldReceive('load')
+            ->andThrow(new \Exception('exception message'));
+
+        $this->artisan('2fauth:install')
+            ->expectsOutputToContain('exception message')
+            ->assertFailed();
+    }
+
+    /**
+     * @test
+     */
+    public function test_install_fails_with_link_to_online_help()
+    {
+        $mock = $this->mock(DotenvEditor::class);
+        $mock->shouldReceive('load')
+            ->andThrow(new \Exception());
+
+        $this->artisan('2fauth:install')
+            ->expectsOutputToContain(config('2fauth.installDocUrl'))
+            ->assertFailed();
+    }
+}

+ 2 - 0
tests/Feature/Http/Auth/RegisterControllerTest.php

@@ -6,6 +6,7 @@ use App\Facades\Settings;
 use App\Http\Controllers\Auth\RegisterController;
 use App\Http\Controllers\Auth\RegisterController;
 use App\Http\Requests\UserStoreRequest;
 use App\Http\Requests\UserStoreRequest;
 use App\Models\User;
 use App\Models\User;
+use App\Rules\ComplyWithEmailRestrictionPolicy;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\DB;
 use PHPUnit\Framework\Attributes\CoversClass;
 use PHPUnit\Framework\Attributes\CoversClass;
 use Tests\FeatureTestCase;
 use Tests\FeatureTestCase;
@@ -15,6 +16,7 @@ use Tests\FeatureTestCase;
  */
  */
 #[CoversClass(RegisterController::class)]
 #[CoversClass(RegisterController::class)]
 #[CoversClass(UserStoreRequest::class)]
 #[CoversClass(UserStoreRequest::class)]
+#[CoversClass(ComplyWithEmailRestrictionPolicy::class)]
 class RegisterControllerTest extends FeatureTestCase
 class RegisterControllerTest extends FeatureTestCase
 {
 {
     private const USERNAME = 'john doe';
     private const USERNAME = 'john doe';

+ 16 - 0
tests/Feature/Http/SystemControllerTest.php

@@ -6,6 +6,7 @@ use App\Http\Controllers\SystemController;
 use App\Models\User;
 use App\Models\User;
 use App\Notifications\TestEmailSettingNotification;
 use App\Notifications\TestEmailSettingNotification;
 use App\Services\ReleaseRadarService;
 use App\Services\ReleaseRadarService;
+use Illuminate\Support\Facades\Lang;
 use Illuminate\Support\Facades\Notification;
 use Illuminate\Support\Facades\Notification;
 use PHPUnit\Framework\Attributes\CoversClass;
 use PHPUnit\Framework\Attributes\CoversClass;
 use Tests\FeatureTestCase;
 use Tests\FeatureTestCase;
@@ -14,6 +15,8 @@ use Tests\FeatureTestCase;
  * SystemControllerTest test class
  * SystemControllerTest test class
  */
  */
 #[CoversClass(SystemController::class)]
 #[CoversClass(SystemController::class)]
+#[CoversClass(TestEmailSettingNotification::class)]
+
 class SystemControllerTest extends FeatureTestCase
 class SystemControllerTest extends FeatureTestCase
 {
 {
     /**
     /**
@@ -133,6 +136,19 @@ class SystemControllerTest extends FeatureTestCase
         Notification::assertSentTo($this->admin, TestEmailSettingNotification::class);
         Notification::assertSentTo($this->admin, TestEmailSettingNotification::class);
     }
     }
 
 
+    /**
+     * @test
+     */
+    public function test_testEmail_renders_to_email()
+    {
+        $mail = (new TestEmailSettingNotification('test_token'))->toMail($this->user)->render();
+
+        $this->assertStringContainsString(
+            Lang::get('notifications.test_email_settings.reason'),
+            $mail
+        );
+    }
+
     /**
     /**
      * @test
      * @test
      */
      */

+ 89 - 0
tests/Unit/Rules/IsValidEmailListTest.php

@@ -0,0 +1,89 @@
+<?php
+
+namespace Tests\Unit\Rules;
+
+use App\Rules\IsValidEmailList;
+use Illuminate\Foundation\Testing\WithoutMiddleware;
+use Illuminate\Support\Facades\Validator;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
+use Tests\TestCase;
+
+/**
+ * IsValidEmailListTest test class
+ */
+#[CoversClass(IsValidEmailList::class)]
+class IsValidEmailListTest extends TestCase
+{
+    use WithoutMiddleware;
+
+    /**
+     * @test
+     */
+    #[DataProvider('provideValidData')]
+    public function test_valid_data(array $data) : void
+    {
+        $validator = Validator::make($data, ['value' => [new IsValidEmailList]]);
+
+        $this->assertFalse($validator->fails());
+    }
+
+    /**
+     * Provide Valid data for validation test
+     */
+    public static function provideValidData() : array
+    {
+        return [
+            [[
+                'value' => 'johndoe@example.com',
+            ]],
+            [[
+                'value' => 'johndoe@example.com|janedoe@example.com',
+            ]],
+            [[
+                'value' => '|johndoe@example.com|janedoe@example.com',
+            ]],
+            [[
+                'value' => 'johndoe@example.com|janedoe@example.com|',
+            ]],
+        ];
+    }
+
+    /**
+     * @test
+     */
+    #[DataProvider('provideInvalidData')]
+    public function test_invalid_data(array $data) : void
+    {
+        $validator = Validator::make($data, ['value' => [new IsValidEmailList]]);
+
+        $this->assertTrue($validator->fails());
+    }
+
+    /**
+     * Provide Valid data for validation test
+     */
+    public static function provideInvalidData() : array
+    {
+        return [
+            [[
+                'value' => 'johndoeexamplecom',
+            ]],
+            [[
+                'value' => 'johndoe@example.com|janedoeexamplecom',
+            ]],
+            [[
+                'value' => 'johndoe@example.com,janedoe@example.com',
+            ]],
+            [[
+                'value' => 'johndoe@example.com;janedoe@example.com|',
+            ]],
+            [[
+                'value' => 'johndoe@example.com janedoe@example.com',
+            ]],
+            [[
+                'value' => 'johndoe@example.com | janedoe@example.com',
+            ]],
+        ];
+    }
+}