diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4d11fda..194285f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -19,4 +19,9 @@ src/ + + + + + diff --git a/src/Handlers/DeleteAttachments.php b/src/Handlers/DeleteAttachments.php index 01cf377..bc26b3e 100644 --- a/src/Handlers/DeleteAttachments.php +++ b/src/Handlers/DeleteAttachments.php @@ -34,7 +34,7 @@ public function __construct($field) */ public function __invoke(Request $request, $model) { - Attachment::where('attachable_type', get_class($model)) + Attachment::where('attachable_type', $model->getMorphClass()) ->where('attachable_id', $model->getKey()) ->get() ->each diff --git a/src/Models/PendingAttachment.php b/src/Models/PendingAttachment.php index b7928a6..ba9f04d 100644 --- a/src/Models/PendingAttachment.php +++ b/src/Models/PendingAttachment.php @@ -46,7 +46,7 @@ public static function persistDraft($draftId, Froala $field, $model) public function persist(Froala $field, $model) { Attachment::create([ - 'attachable_type' => get_class($model), + 'attachable_type' => $model->getMorphClass(), 'attachable_id' => $model->getKey(), 'attachment' => $this->attachment, 'disk' => $field->disk, diff --git a/tests/Fixtures/TestServiceProvider.php b/tests/Fixtures/TestServiceProvider.php index 126c2ca..025c97e 100644 --- a/tests/Fixtures/TestServiceProvider.php +++ b/tests/Fixtures/TestServiceProvider.php @@ -2,16 +2,15 @@ namespace Froala\NovaFroalaField\Tests\Fixtures; +use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\ServiceProvider; class TestServiceProvider extends ServiceProvider { public function boot() { - } - - public function register() - { - $this->app['config']->set('nova.froala-field.attachments_driver', 'trix'); + Relation::morphMap([ + 'article' => Article::class, + ]); } } diff --git a/tests/FroalaUploadControllerTest.php b/tests/FroalaUploadControllerTest.php index f901193..9e110b1 100644 --- a/tests/FroalaUploadControllerTest.php +++ b/tests/FroalaUploadControllerTest.php @@ -5,7 +5,6 @@ use Froala\NovaFroalaField\Models\Attachment; use Froala\NovaFroalaField\Models\PendingAttachment; use function Froala\NovaFroalaField\nova_version_at_least; -use Froala\NovaFroalaField\Tests\Fixtures\Article; use Illuminate\Support\Facades\Storage; class FroalaUploadControllerTest extends TestCase @@ -58,7 +57,7 @@ public function store_attachment() 'attachment' => $this->getAttachmentLocation(), 'url' => Storage::disk(static::DISK)->url($this->getAttachmentLocation()), 'attachable_id' => $response->json('id'), - 'attachable_type' => Article::class, + 'attachable_type' => 'article', ]); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 1ae048a..d5aaf3e 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,6 +4,7 @@ use Froala\NovaFroalaField\FroalaFieldServiceProvider; use Froala\NovaFroalaField\Tests\Fixtures\TestResource; +use Froala\NovaFroalaField\Tests\Fixtures\TestServiceProvider; use Froala\NovaFroalaField\Tests\Fixtures\User; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Route; @@ -49,26 +50,10 @@ protected function getPackageProviders($app) NovaServiceProvider::class, NovaApplicationServiceProvider::class, FroalaFieldServiceProvider::class, + TestServiceProvider::class, ]; } - /** - * Define environment setup. - * - * @param \Illuminate\Foundation\Application $app - * @return void - */ - protected function getEnvironmentSetUp($app) - { - // Setup default database to use sqlite :memory: - $app['config']->set('database.default', 'testbench'); - $app['config']->set('database.connections.testbench', [ - 'driver' => 'sqlite', - 'database' => ':memory:', - 'prefix' => '', - ]); - } - /** * Set up the database. * diff --git a/tests/TrixDriverUploadTest.php b/tests/TrixDriverUploadTest.php index 7f4d7eb..7faa4a1 100644 --- a/tests/TrixDriverUploadTest.php +++ b/tests/TrixDriverUploadTest.php @@ -4,7 +4,6 @@ use function Froala\NovaFroalaField\nova_version_at_least; use Froala\NovaFroalaField\Tests\Fixtures\Article; -use Froala\NovaFroalaField\Tests\Fixtures\TestServiceProvider; use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Storage; use Laravel\Nova\Trix\Attachment; @@ -26,11 +25,9 @@ public function setUp(): void protected function getPackageProviders($app) { - $providers = parent::getPackageProviders($app); + $app['config']->set('nova.froala-field.attachments_driver', 'trix'); - array_unshift($providers, TestServiceProvider::class); - - return $providers; + return parent::getPackageProviders($app); } /** @test */ diff --git a/tests/UploadsHelper.php b/tests/UploadsHelper.php index fa720f4..475f7f8 100644 --- a/tests/UploadsHelper.php +++ b/tests/UploadsHelper.php @@ -32,7 +32,7 @@ protected function regenerateUpload() protected function uploadPendingFile(): TestResponse { - $url = config('nova.froala-field.attachments_driver') === 'trix' + $url = $this->app['config']->get('nova.froala-field.attachments_driver') === 'trix' ? '/nova-api/articles/trix-attachment/content' : 'nova-vendor/froala-field/articles/attachments/content';