diff --git a/app/Http/Requests/Users/GetUserProfileRequest.php b/app/Http/Requests/Users/GetUserProfileRequest.php index 7d1b3a2..68c2d9b 100755 --- a/app/Http/Requests/Users/GetUserProfileRequest.php +++ b/app/Http/Requests/Users/GetUserProfileRequest.php @@ -20,8 +20,6 @@ protected function getAvailableRelations(): array { return [ 'role', - 'media', - 'media.owner', ]; } } diff --git a/app/Http/Requests/Users/GetUserRequest.php b/app/Http/Requests/Users/GetUserRequest.php index dde64e6..e4822d8 100755 --- a/app/Http/Requests/Users/GetUserRequest.php +++ b/app/Http/Requests/Users/GetUserRequest.php @@ -33,8 +33,6 @@ protected function getAvailableRelations(): array { return [ 'role', - 'media', - 'media.owner', ]; } } diff --git a/app/Http/Requests/Users/SearchUserRequest.php b/app/Http/Requests/Users/SearchUserRequest.php index 3959f2e..e9657de 100755 --- a/app/Http/Requests/Users/SearchUserRequest.php +++ b/app/Http/Requests/Users/SearchUserRequest.php @@ -32,8 +32,6 @@ protected function getAvailableRelations(): array { return [ 'role', - 'media', - 'media.owner', ]; } } diff --git a/app/Http/Resources/Media/MediaCollectionResource.php b/app/Http/Resources/Media/MediaCollectionResource.php deleted file mode 100644 index 9d400f3..0000000 --- a/app/Http/Resources/Media/MediaCollectionResource.php +++ /dev/null @@ -1,11 +0,0 @@ - $this->resource->email, 'role_id' => $this->resource->role_id, 'role' => RoleResource::make($this->whenLoaded('role')), - 'media' => MediaCollectionResource::make($this->whenLoaded('media')), ]; } } diff --git a/app/Models/User.php b/app/Models/User.php index 67c0df9..c00fcfc 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,10 +2,8 @@ namespace App\Models; -use App\Modules\Media\Models\Media; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; -use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use PHPOpenSourceSaver\JWTAuth\Contracts\JWTSubject; @@ -55,11 +53,6 @@ public function role(): BelongsTo return $this->belongsTo(Role::class); } - public function media(): HasMany - { - return $this->hasMany(Media::class, 'owner_id'); - } - public function isAdmin(): bool { return $this->role_id === Role::ADMIN; diff --git a/app/Modules/Media/Contracts/Requests/BulkCreateMediaRequestContract.php b/app/Modules/Media/Contracts/Requests/BulkCreateMediaRequestContract.php deleted file mode 100644 index 69027d9..0000000 --- a/app/Modules/Media/Contracts/Requests/BulkCreateMediaRequestContract.php +++ /dev/null @@ -1,7 +0,0 @@ -file('file'); - $data = $request->onlyValidated(); - - $content = file_get_contents($file->getPathname()); - - $media = $mediaService->create($content, $file->getClientOriginalName(), $data); - - return MediaResource::make($media); - } - - public function delete(DeleteMediaRequestContract $request, MediaServiceContract $mediaService, int $id): Response - { - $mediaService->delete($id); - - return response('', Response::HTTP_NO_CONTENT); - } - - public function search( - SearchMediaRequestContract $request, - MediaServiceContract $mediaService - ): MediaCollectionContract { - $result = $mediaService->search($request->onlyValidated()); - - return MediaCollection::make($result); - } - - public function bulkCreate( - BulkCreateMediaRequestContract $request, - MediaServiceContract $mediaService - ): MediaListResourceContract { - $result = $mediaService->bulkCreate($request->onlyValidated('media')); - - return MediaCollection::make($result); - } -} diff --git a/app/Modules/Media/Http/Requests/BulkCreateMediaRequest.php b/app/Modules/Media/Http/Requests/BulkCreateMediaRequest.php deleted file mode 100644 index c1db066..0000000 --- a/app/Modules/Media/Http/Requests/BulkCreateMediaRequest.php +++ /dev/null @@ -1,22 +0,0 @@ - 'required|array', - 'media.*' => 'array', - 'media.*.file' => "file|required|max:5120|mimes:{$types}", - 'media.*.meta' => 'array', - 'media.*.is_public' => 'boolean', - ]; - } -} diff --git a/app/Modules/Media/Http/Requests/CreateMediaRequest.php b/app/Modules/Media/Http/Requests/CreateMediaRequest.php deleted file mode 100644 index 5929426..0000000 --- a/app/Modules/Media/Http/Requests/CreateMediaRequest.php +++ /dev/null @@ -1,20 +0,0 @@ - "file|required|max:5120|mimes:{$types}", - 'meta' => 'array', - 'is_public' => 'boolean', - ]; - } -} diff --git a/app/Modules/Media/Http/Requests/DeleteMediaRequest.php b/app/Modules/Media/Http/Requests/DeleteMediaRequest.php deleted file mode 100644 index b56bbcb..0000000 --- a/app/Modules/Media/Http/Requests/DeleteMediaRequest.php +++ /dev/null @@ -1,27 +0,0 @@ -user()->isAdmin(); - } - - public function validateResolved(): void - { - parent::validateResolved(); - - $service = app(MediaServiceContract::class); - - if (!$service->exists($this->route('id'))) { - throw new NotFoundHttpException(__('validation.exceptions.not_found', ['entity' => 'Media'])); - } - } -} diff --git a/app/Modules/Media/Http/Requests/SearchMediaRequest.php b/app/Modules/Media/Http/Requests/SearchMediaRequest.php deleted file mode 100644 index afd7768..0000000 --- a/app/Modules/Media/Http/Requests/SearchMediaRequest.php +++ /dev/null @@ -1,22 +0,0 @@ - 'integer', - 'per_page' => 'integer', - 'all' => 'integer', - 'query' => 'string', - 'order_by' => 'string', - 'desc' => 'boolean', - 'name' => 'string', - ]; - } -} diff --git a/app/Modules/Media/Http/Resources/BaseResource.php b/app/Modules/Media/Http/Resources/BaseResource.php deleted file mode 100644 index 1f2861b..0000000 --- a/app/Modules/Media/Http/Resources/BaseResource.php +++ /dev/null @@ -1,10 +0,0 @@ - $this->resource->id, - 'link' => $this->resource->link, - 'name' => $this->resource->name, - 'is_public' => $this->when($request->user() && $request->user()->isAdmin(), $this->resource->is_public), - 'owner_id' => $this->when($request->user() && $request->user()->isAdmin(), $this->resource->owner_id), - 'meta' => $this->resource->meta, - ]; - } -} diff --git a/app/Modules/Media/Models/Media.php b/app/Modules/Media/Models/Media.php deleted file mode 100644 index 413cf7e..0000000 --- a/app/Modules/Media/Models/Media.php +++ /dev/null @@ -1,59 +0,0 @@ - 'boolean', - 'deleted_at' => 'date', - 'meta' => 'array', - ]; - - protected $hidden = ['pivot']; - - public function scopeApplyMediaPermissionRestrictions(Builder $query): void - { - if (!Auth::check()) { - $query->where('is_public', true); - - return; - } - - $user = Auth::user(); - - if (!$user->isAdmin()) { - $query->where(function ($subQuery) use ($user) { - $subQuery - ->where('is_public', true) - ->orWhere('owner_id', $user->id); - }); - } - } - - public function owner(): BelongsTo - { - return $this->belongsTo(User::class); - } -} diff --git a/app/Modules/Media/Providers/MediaServiceProvider.php b/app/Modules/Media/Providers/MediaServiceProvider.php deleted file mode 100644 index 2ba64d2..0000000 --- a/app/Modules/Media/Providers/MediaServiceProvider.php +++ /dev/null @@ -1,36 +0,0 @@ -loadMigrationsFrom(__DIR__ . '/../database/migrations'); - $this->loadRoutesFrom(__DIR__ . '/../routes/api.php'); - $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'media'); - $this->mergeConfigFrom(__DIR__ . '/../config/media.php', 'media'); - } - - public function register(): void - { - $this->app->bind(CreateMediaRequestContract::class, CreateMediaRequest::class); - $this->app->bind(BulkCreateMediaRequestContract::class, BulkCreateMediaRequest::class); - $this->app->bind(SearchMediaRequestContract::class, SearchMediaRequest::class); - $this->app->bind(DeleteMediaRequestContract::class, DeleteMediaRequest::class); - - $this->app->bind(MediaServiceContract::class, MediaService::class); - } -} diff --git a/app/Modules/Media/Readme.md b/app/Modules/Media/Readme.md deleted file mode 100644 index 9c9b20d..0000000 --- a/app/Modules/Media/Readme.md +++ /dev/null @@ -1,5 +0,0 @@ -#Installation - -1. Copy Media folder to your App/Modules directory -2. Add MediaServiceProvider to the providers array of app config -3. Copy all data from the "tests" directory to the "tests/Modules/Media" diff --git a/app/Modules/Media/Repositories/MediaRepository.php b/app/Modules/Media/Repositories/MediaRepository.php deleted file mode 100644 index 5d81e07..0000000 --- a/app/Modules/Media/Repositories/MediaRepository.php +++ /dev/null @@ -1,25 +0,0 @@ -setModel(Media::class); - } - - public function getSearchResults(): LengthAwarePaginator - { - $this->query->applyMediaPermissionRestrictions(); - - return parent::getSearchResults(); - } -} diff --git a/app/Modules/Media/Services/MediaService.php b/app/Modules/Media/Services/MediaService.php deleted file mode 100644 index c957bad..0000000 --- a/app/Modules/Media/Services/MediaService.php +++ /dev/null @@ -1,59 +0,0 @@ -setRepository(MediaRepository::class); - } - - public function search(array $filters): LengthAwarePaginator - { - return $this - ->searchQuery($filters) - ->filterByQuery(['name']) - ->getSearchResults(); - } - - public function create($content, string $fileName, array $data = []): Model - { - $fileName = $this->saveFile($fileName, $content); - $data['name'] = $fileName; - $data['link'] = Storage::url($data['name']); - $data['owner_id'] = Auth::user()->id; - - return $this->repository->create($data); - } - - public function bulkCreate(array $data): array - { - return array_map(function ($media) { - $file = $media['file']; - $content = file_get_contents($file->getPathname()); - - return $this->create($content, $file->getClientOriginalName(), $media); - }, $data); - } - - public function delete($where): int - { - return $this->repository->delete($where); - } -} diff --git a/app/Modules/Media/config/media.php b/app/Modules/Media/config/media.php deleted file mode 100644 index 5246291..0000000 --- a/app/Modules/Media/config/media.php +++ /dev/null @@ -1,3 +0,0 @@ - ['jpg', 'jpeg', 'bmp', 'png']]; diff --git a/app/Modules/Media/database/migrations/2018_03_31_104532_create_media_table.php b/app/Modules/Media/database/migrations/2018_03_31_104532_create_media_table.php deleted file mode 100644 index 6403c6f..0000000 --- a/app/Modules/Media/database/migrations/2018_03_31_104532_create_media_table.php +++ /dev/null @@ -1,38 +0,0 @@ -increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->string('link'); - $table->string('name')->nullable(); - $table->boolean('is_public')->default(false); - $table->integer('owner_id')->nullable(); - - if (config('database.default') == 'mysql') { - $table->jsonb('meta')->nullable(); - } else { - $table->jsonb('meta')->default('{}'); - } - - $table - ->foreign('owner_id') - ->references('id') - ->on('users') - ->onDelete('cascade'); - }); - } - - public function down() - { - Schema::dropIfExists('media'); - } -} diff --git a/app/Modules/Media/routes/api.php b/app/Modules/Media/routes/api.php deleted file mode 100644 index 69c2b8d..0000000 --- a/app/Modules/Media/routes/api.php +++ /dev/null @@ -1,13 +0,0 @@ - 'auth_group'], function () { - Route::post('media', [MediaController::class, 'create']); - Route::delete('media/{id}', [MediaController::class, 'delete']); - Route::post('media/bulk', [MediaController::class, 'bulkCreate']); -}); - -Route::group(['middleware' => 'guest_group'], function () { - Route::get('media', [MediaController::class, 'search']); -}); diff --git a/app/Modules/Media/tests/MediaTest.php b/app/Modules/Media/tests/MediaTest.php deleted file mode 100644 index 0050f93..0000000 --- a/app/Modules/Media/tests/MediaTest.php +++ /dev/null @@ -1,332 +0,0 @@ -admin = User::find(1); - $this->user = User::find(2); - $this->file = UploadedFile::fake()->image('file.png', 600, 600); - } - - public function testCreate(): void - { - $this->mockGenerateFilename(); - - $response = $this->actingAs($this->admin)->json('post', '/media', ['file' => $this->file]); - - $response->assertCreated(); - - $this->assertDatabaseHas('media', [ - 'id' => 6, - 'name' => 'file.png', - 'owner_id' => $this->admin->id, - 'is_public' => false, - 'link' => '/storage/file.png', - ]); - } - - public function testCreatePublic(): void - { - $this->mockGenerateFilename(); - - $response = $this->actingAs($this->user)->json('post', '/media', [ - 'file' => $this->file, - 'is_public' => true, - ]); - - $response->assertCreated(); - - $this->assertDatabaseHas('media', [ - 'id' => 6, - 'name' => 'file.png', - 'owner_id' => $this->user->id, - 'is_public' => true, - ]); - } - - public function testCreateCheckUrls(): void - { - $this->mockGenerateFilename(); - - $this->actingAs($this->admin)->json('post', '/media', ['file' => $this->file]); - - $this->assertEquals(1, Media::where('link', 'like', '/%')->count()); - } - - public function testCreateCheckResponse(): void - { - $this->mockGenerateFilename(); - - $response = $this->actingAs($this->admin)->json('post', '/media', ['file' => $this->file]); - - $response->assertCreated(); - - $this->assertDatabaseHas('media', [ - 'id' => 6, - 'link' => '/storage/file.png', - ]); - - Storage::disk('local')->assertExists($this->getFilePathFromUrl('file.png')); - - $this->clearUploadedFilesFolder(); - } - - public function testCreateNoAuth(): void - { - $response = $this->json('post', '/media', ['file' => $this->file]); - - $response->assertUnauthorized(); - } - - public function testBulkCreate(): void - { - $this->mockGenerateFilename(2); - - $response = $this->actingAs($this->admin)->json('post', '/media/bulk', [ - 'media' => [ - [ - 'file' => $this->file, - 'meta' => ['test1'], - ], - [ - 'file' => $this->file, - 'meta' => ['test2'], - ], - ], - ]); - - $response->assertOk(); - - $this->assertDatabaseHas('media', [ - 'id' => 6, - 'name' => 'file.png', - 'owner_id' => $this->admin->id, - 'meta' => "[\"test1\"]", - 'is_public' => false, - ]); - - $this->assertDatabaseHas('media', [ - 'id' => 7, - 'name' => 'file.png', - 'owner_id' => $this->admin->id, - 'meta' => "[\"test2\"]", - 'is_public' => false, - ]); - } - - public function testDelete(): void - { - $response = $this->actingAs($this->admin)->json('delete', '/media/1'); - - $response->assertNoContent(); - - $this->assertSoftDeleted('media', [ - 'id' => 1, - ]); - } - - public function testDeleteNotExists(): void - { - $response = $this->actingAs($this->admin)->json('delete', '/media/0'); - - $response->assertNotFound(); - } - - public function testDeleteNoPermission(): void - { - $response = $this->actingAs($this->user)->json('delete', '/media/1'); - - $response->assertForbidden(); - - $this->assertDatabaseHas('media', [ - 'id' => 1, - ]); - } - - public function testDeleteNoAuth(): void - { - $response = $this->json('delete', '/media/1'); - - $response->assertUnauthorized(); - - $this->assertDatabaseHas('media', [ - 'id' => 1, - ]); - } - - public function getSearchFilters(): array - { - return [ - [ - 'filter' => ['all' => true], - 'result' => 'get_by_all.json', - ], - ]; - } - - public function getAdminSearchFilters(): array - { - return [ - [ - 'filter' => ['query' => 'product'], - 'result' => 'get_by_query_as_admin.json', - ], - [ - 'filter' => [ - 'query' => 'photo', - 'order_by' => 'name', - 'desc' => false, - 'per_page' => 3, - ], - 'result' => 'get_complex_as_admin.json', - ], - ]; - } - - public function getUserSearchFilters(): array - { - return [ - [ - 'filter' => ['query' => 'product'], - 'result' => 'get_by_query_as_user.json', - ], - [ - 'filter' => [ - 'query' => 'photo', - 'order_by' => 'name', - 'desc' => false, - 'per_page' => 3, - ], - 'result' => 'get_complex_as_user.json', - ], - ]; - } - - /** - * @dataProvider getSearchFilters - * - * @param array $filter - * @param string $fixture - */ - public function testSearch(array $filter, string $fixture): void - { - $response = $this->json('get', '/media', $filter); - - $response->assertOk(); - - $this->assertEqualsFixture($fixture, $response->json()); - } - - /** - * @dataProvider getAdminSearchFilters - * - * @param array $filter - * @param string $fixture - */ - public function testSearchByAdmin(array $filter, string $fixture): void - { - $response = $this->actingAs($this->admin)->json('get', '/media', $filter); - - $response->assertOk(); - - $this->assertEqualsFixture($fixture, $response->json()); - } - - /** - * @dataProvider getUserSearchFilters - * - * @param array $filter - * @param string $fixture - */ - public function testSearchByUser(array $filter, string $fixture): void - { - $response = $this->actingAs($this->user)->json('get', '/media', $filter); - - $response->assertOk(); - - $this->assertEqualsFixture($fixture, $response->json()); - } - - public function getBadFiles(): array - { - return [ - [ - 'filter' => ['fileName' => 'notAVirus.exe'], - ], - [ - 'filter' => ['fileName' => 'notAVirus.psd'], - ], - ]; - } - - /** - * @dataProvider getBadFiles - * - * @param array $filter - */ - public function testUploadingBadFiles(array $filter): void - { - $this->file = UploadedFile::fake()->create($filter['fileName'], 1024); - - $response = $this->actingAs($this->user)->json('post', '/media', ['file' => $this->file]); - - $response->assertUnprocessable(); - - $response->assertJson([ - 'errors' => [ - 'file' => ['The file must be a file of type: jpg, jpeg, bmp, png.'], - ], - ]); - } - - public function getGoodFiles(): array - { - return [ - [ - 'filter' => ['fileName' => 'image.jpg'], - ], - [ - 'filter' => ['fileName' => 'image.png'], - ], - [ - 'filter' => ['fileName' => 'image.bmp'], - ], - ]; - } - - /** - * @dataProvider getGoodFiles - * - * @param array $filter - */ - public function testUploadingGoodFiles(array $filter): void - { - $this->file = UploadedFile::fake()->image($filter['fileName'], 600, 600); - - $response = $this->actingAs($this->user)->json('post', '/media', ['file' => $this->file]); - - $response->assertCreated(); - - $this->assertDatabaseHas('media', ['id' => 6]); - } -} diff --git a/app/Modules/Media/tests/ModuleTestCase.php b/app/Modules/Media/tests/ModuleTestCase.php deleted file mode 100644 index 9ef1ba1..0000000 --- a/app/Modules/Media/tests/ModuleTestCase.php +++ /dev/null @@ -1,41 +0,0 @@ -loadEnvironmentFrom('.env.testing'); - $app->make(Kernel::class)->bootstrap(); - - $this->truncateExceptTables = ['migrations', 'password_resets', 'roles']; - $this->prepareSequencesExceptTables = ['migrations', 'password_resets', 'settings', 'roles']; - - return $app; - } - - public function getFixturePath($fixtureName): string - { - $class = get_class($this); - $explodedClass = explode('\\', $class); - $className = Arr::last($explodedClass); - - return base_path("app/Modules/Media/tests/fixtures/{$className}/{$fixtureName}"); - } -} diff --git a/app/Modules/Media/tests/fixtures/MediaTest/dump.sql b/app/Modules/Media/tests/fixtures/MediaTest/dump.sql deleted file mode 100644 index 4c3da13..0000000 --- a/app/Modules/Media/tests/fixtures/MediaTest/dump.sql +++ /dev/null @@ -1,10 +0,0 @@ -INSERT INTO users(id, name, email, password, remember_token, set_password_hash, role_id, created_at, updated_at) VALUES - (1, 'Gerhard Feest', 'fidel.kutch@example.com', '$2y$10$X4receiTrF24bXrEbAiChOZ8TMNPqoXuhuThgynvBdWIHZeu5HzsS', null, null, 1, '2016-10-20 11:05:00', '2016-10-20 11:05:00'), - (2, 'Alien West', 'alien.west@example.com', 'old_password', null, 'restore_token', 2, '2016-10-20 11:05:00', '2016-10-20 11:05:00'); - -INSERT INTO media(id, name, owner_id, is_public, link, meta, created_at, updated_at, deleted_at) VALUES - (1, 'Product main photo', 1 , true, 'http://localhost/test.jpg', '{}', '2016-10-20 11:05:00', '2016-10-20 11:05:00', null), - (2, 'Category Photo photo', 1, false, 'http://localhost/test1.jpg', '{}', '2016-10-20 11:05:00', '2016-10-20 11:05:00', null), - (3, 'Deleted photo', 2, true, 'http://localhost/test3.jpg', '{}', '2016-10-20 11:05:00', '2016-10-20 11:05:00', '2016-10-20 11:05:00'), - (4, 'Photo', 2, true, 'http://localhost/test4.jpg', '{}', '2016-10-20 11:05:00', '2016-10-20 11:05:00', null), - (5, 'Private photo', 2, false, 'http://localhost/test5.jpg', '{}', '2016-10-20 11:05:00', '2016-10-20 11:05:00', null); \ No newline at end of file diff --git a/app/Modules/Media/tests/fixtures/MediaTest/get_by_all.json b/app/Modules/Media/tests/fixtures/MediaTest/get_by_all.json deleted file mode 100644 index 1dc9fc4..0000000 --- a/app/Modules/Media/tests/fixtures/MediaTest/get_by_all.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "data": [ - { - "id": 1, - "link": "http:\/\/localhost\/test.jpg", - "name": "Product main photo", - "meta": [] - }, - { - "id": 4, - "link": "http:\/\/localhost\/test4.jpg", - "name": "Photo", - "meta": [] - } - ], - "links": { - "first": "http:\/\/localhost\/media?page=1", - "last": "http:\/\/localhost\/media?page=1", - "prev": null, - "next": null - }, - "meta": { - "current_page": 1, - "from": 1, - "last_page": 1, - "links": [ - { - "url": null, - "label": "« Previous", - "active": false - }, - { - "url": "http:\/\/localhost\/media?page=1", - "label": "1", - "active": true - }, - { - "url": null, - "label": "Next »", - "active": false - } - ], - "path": "http:\/\/localhost\/media", - "per_page": 2, - "to": 2, - "total": 2 - } -} \ No newline at end of file diff --git a/app/Modules/Media/tests/fixtures/MediaTest/get_by_query_as_admin.json b/app/Modules/Media/tests/fixtures/MediaTest/get_by_query_as_admin.json deleted file mode 100644 index 87fb1f0..0000000 --- a/app/Modules/Media/tests/fixtures/MediaTest/get_by_query_as_admin.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "data": [ - { - "id": 1, - "link": "http:\/\/localhost\/test.jpg", - "name": "Product main photo", - "is_public": true, - "owner_id": 1, - "meta": [] - } - ], - "links": { - "first": "http:\/\/localhost\/media?page=1", - "last": "http:\/\/localhost\/media?page=1", - "prev": null, - "next": null - }, - "meta": { - "current_page": 1, - "from": 1, - "last_page": 1, - "links": [ - { - "url": null, - "label": "« Previous", - "active": false - }, - { - "url": "http:\/\/localhost\/media?page=1", - "label": "1", - "active": true - }, - { - "url": null, - "label": "Next »", - "active": false - } - ], - "path": "http:\/\/localhost\/media", - "per_page": 10, - "to": 1, - "total": 1 - } -} \ No newline at end of file diff --git a/app/Modules/Media/tests/fixtures/MediaTest/get_by_query_as_user.json b/app/Modules/Media/tests/fixtures/MediaTest/get_by_query_as_user.json deleted file mode 100644 index 7107071..0000000 --- a/app/Modules/Media/tests/fixtures/MediaTest/get_by_query_as_user.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "data": [ - { - "id": 1, - "link": "http:\/\/localhost\/test.jpg", - "name": "Product main photo", - "meta": [] - } - ], - "links": { - "first": "http:\/\/localhost\/media?page=1", - "last": "http:\/\/localhost\/media?page=1", - "prev": null, - "next": null - }, - "meta": { - "current_page": 1, - "from": 1, - "last_page": 1, - "links": [ - { - "url": null, - "label": "« Previous", - "active": false - }, - { - "url": "http:\/\/localhost\/media?page=1", - "label": "1", - "active": true - }, - { - "url": null, - "label": "Next »", - "active": false - } - ], - "path": "http:\/\/localhost\/media", - "per_page": 10, - "to": 1, - "total": 1 - } -} \ No newline at end of file diff --git a/app/Modules/Media/tests/fixtures/MediaTest/get_complex_as_admin.json b/app/Modules/Media/tests/fixtures/MediaTest/get_complex_as_admin.json deleted file mode 100644 index 56d7baf..0000000 --- a/app/Modules/Media/tests/fixtures/MediaTest/get_complex_as_admin.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "data": [ - { - "id": 2, - "link": "http:\/\/localhost\/test1.jpg", - "name": "Category Photo photo", - "is_public": false, - "owner_id": 1, - "meta": [] - }, - { - "id": 4, - "link": "http:\/\/localhost\/test4.jpg", - "name": "Photo", - "is_public": true, - "owner_id": 2, - "meta": [] - }, - { - "id": 5, - "link": "http:\/\/localhost\/test5.jpg", - "name": "Private photo", - "is_public": false, - "owner_id": 2, - "meta": [] - } - ], - "links": { - "first": "http:\/\/localhost\/media?page=1", - "last": "http:\/\/localhost\/media?page=2", - "prev": null, - "next": "http:\/\/localhost\/media?page=2" - }, - "meta": { - "current_page": 1, - "from": 1, - "last_page": 2, - "links": [ - { - "url": null, - "label": "« Previous", - "active": false - }, - { - "url": "http:\/\/localhost\/media?page=1", - "label": "1", - "active": true - }, - { - "url": "http:\/\/localhost\/media?page=2", - "label": "2", - "active": false - }, - { - "url": "http:\/\/localhost\/media?page=2", - "label": "Next »", - "active": false - } - ], - "path": "http:\/\/localhost\/media", - "per_page": 3, - "to": 3, - "total": 4 - } -} \ No newline at end of file diff --git a/app/Modules/Media/tests/fixtures/MediaTest/get_complex_as_user.json b/app/Modules/Media/tests/fixtures/MediaTest/get_complex_as_user.json deleted file mode 100644 index b577b71..0000000 --- a/app/Modules/Media/tests/fixtures/MediaTest/get_complex_as_user.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "data": [ - { - "id": 4, - "link": "http:\/\/localhost\/test4.jpg", - "name": "Photo", - "meta": [] - }, - { - "id": 5, - "link": "http:\/\/localhost\/test5.jpg", - "name": "Private photo", - "meta": [] - }, - { - "id": 1, - "link": "http:\/\/localhost\/test.jpg", - "name": "Product main photo", - "meta": [] - } - ], - "links": { - "first": "http:\/\/localhost\/media?page=1", - "last": "http:\/\/localhost\/media?page=1", - "prev": null, - "next": null - }, - "meta": { - "current_page": 1, - "from": 1, - "last_page": 1, - "links": [ - { - "url": null, - "label": "« Previous", - "active": false - }, - { - "url": "http:\/\/localhost\/media?page=1", - "label": "1", - "active": true - }, - { - "url": null, - "label": "Next »", - "active": false - } - ], - "path": "http:\/\/localhost\/media", - "per_page": 3, - "to": 3, - "total": 3 - } -} \ No newline at end of file diff --git a/app/Modules/Media/tests/fixtures/MediaTest/media.json b/app/Modules/Media/tests/fixtures/MediaTest/media.json deleted file mode 100644 index 323ec85..0000000 --- a/app/Modules/Media/tests/fixtures/MediaTest/media.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "id": "1", - "link": "vero", - "name": "aut" -} diff --git a/composer.json b/composer.json index 1409889..ef97405 100644 --- a/composer.json +++ b/composer.json @@ -52,8 +52,7 @@ }, "autoload-dev": { "psr-4": { - "App\\Tests\\": "tests/", - "App\\Modules\\Media\\Tests\\": "app/Modules/Media/tests/" + "App\\Tests\\": "tests/" } }, "scripts": { diff --git a/config/app.php b/config/app.php index 2171978..7f4bce9 100644 --- a/config/app.php +++ b/config/app.php @@ -204,11 +204,6 @@ RonasIT\Support\AutoDoc\AutoDocServiceProvider::class, PHPOpenSourceSaver\JWTAuth\Providers\LaravelServiceProvider::class, - /* - * Module Service Providers... - */ - App\Modules\Media\Providers\MediaServiceProvider::class, - /* * Application Service Providers... */ diff --git a/phpunit.xml b/phpunit.xml index 560aad0..59bb3ff 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -4,10 +4,6 @@ ./app - - ./app/Modules/Media/tests - ./app/Modules/Media/database - @@ -15,7 +11,6 @@ ./tests - ./app/Modules/Media/tests diff --git a/tests/Modules/Media/MediaTest.php b/tests/Modules/Media/MediaTest.php deleted file mode 100644 index ee24d90..0000000 --- a/tests/Modules/Media/MediaTest.php +++ /dev/null @@ -1,333 +0,0 @@ -admin = User::find(1); - $this->user = User::find(2); - $this->file = UploadedFile::fake()->image('file.png', 600, 600); - } - - public function testCreate(): void - { - $this->mockGenerateFilename(); - - $response = $this->actingAs($this->admin)->json('post', '/media', ['file' => $this->file]); - - $response->assertCreated(); - - $this->assertDatabaseHas('media', [ - 'id' => 6, - 'name' => 'file.png', - 'owner_id' => $this->admin->id, - 'is_public' => false, - 'link' => '/storage/file.png', - ]); - } - - public function testCreatePublic(): void - { - $this->mockGenerateFilename(); - - $response = $this->actingAs($this->user)->json('post', '/media', [ - 'file' => $this->file, - 'is_public' => true, - ]); - - $response->assertCreated(); - - $this->assertDatabaseHas('media', [ - 'id' => 6, - 'name' => 'file.png', - 'owner_id' => $this->user->id, - 'is_public' => true, - 'link' => '/storage/file.png', - ]); - } - - public function testCreateCheckUrls(): void - { - $this->mockGenerateFilename(); - - $this->actingAs($this->admin)->json('post', '/media', ['file' => $this->file]); - - $this->assertEquals(1, Media::where('link', 'like', '/%')->count()); - } - - public function testCreateCheckResponse(): void - { - $this->mockGenerateFilename(); - - $response = $this->actingAs($this->admin)->json('post', '/media', ['file' => $this->file]); - - $response->assertCreated(); - - $this->assertDatabaseHas('media', [ - 'id' => 6, - 'link' => '/storage/file.png', - ]); - - Storage::disk('local')->assertExists($this->getFilePathFromUrl('file.png')); - - $this->clearUploadedFilesFolder(); - } - - public function testCreateNoAuth(): void - { - $response = $this->json('post', '/media', ['file' => $this->file]); - - $response->assertUnauthorized(); - } - - public function testBulkCreate(): void - { - $this->mockGenerateFilename(2); - - $response = $this->actingAs($this->admin)->json('post', '/media/bulk', [ - 'media' => [ - [ - 'file' => $this->file, - 'meta' => ['test1'], - ], - [ - 'file' => $this->file, - 'meta' => ['test2'], - ], - ], - ]); - - $response->assertOk(); - - $this->assertDatabaseHas('media', [ - 'id' => 6, - 'name' => 'file.png', - 'owner_id' => $this->admin->id, - 'meta' => "[\"test1\"]", - 'is_public' => false, - ]); - - $this->assertDatabaseHas('media', [ - 'id' => 7, - 'name' => 'file.png', - 'owner_id' => $this->admin->id, - 'meta' => "[\"test2\"]", - 'is_public' => false, - ]); - } - - public function testDelete(): void - { - $response = $this->actingAs($this->admin)->json('delete', '/media/1'); - - $response->assertNoContent(); - - $this->assertSoftDeleted('media', [ - 'id' => 1, - ]); - } - - public function testDeleteNotExists(): void - { - $response = $this->actingAs($this->admin)->json('delete', '/media/0'); - - $response->assertNotFound(); - } - - public function testDeleteNoPermission(): void - { - $response = $this->actingAs($this->user)->json('delete', '/media/1'); - - $response->assertForbidden(); - - $this->assertDatabaseHas('media', [ - 'id' => 1, - ]); - } - - public function testDeleteNoAuth(): void - { - $response = $this->json('delete', '/media/1'); - - $response->assertUnauthorized(); - - $this->assertDatabaseHas('media', [ - 'id' => 1, - ]); - } - - public function getSearchFilters(): array - { - return [ - [ - 'filter' => ['all' => true], - 'result' => 'get_by_all.json', - ], - ]; - } - - public function getAdminSearchFilters(): array - { - return [ - [ - 'filter' => ['query' => 'product'], - 'result' => 'get_by_query_as_admin.json', - ], - [ - 'filter' => [ - 'query' => 'photo', - 'order_by' => 'name', - 'desc' => false, - 'per_page' => 3, - ], - 'result' => 'get_complex_as_admin.json', - ], - ]; - } - - public function getUserSearchFilters(): array - { - return [ - [ - 'filter' => ['query' => 'product'], - 'result' => 'get_by_query_as_user.json', - ], - [ - 'filter' => [ - 'query' => 'photo', - 'order_by' => 'name', - 'desc' => false, - 'per_page' => 3, - ], - 'result' => 'get_complex_as_user.json', - ], - ]; - } - - /** - * @dataProvider getSearchFilters - * - * @param array $filter - * @param string $fixture - */ - public function testSearch(array $filter, string $fixture): void - { - $response = $this->json('get', '/media', $filter); - - $response->assertOk(); - - $this->assertEqualsFixture($fixture, $response->json()); - } - - /** - * @dataProvider getAdminSearchFilters - * - * @param array $filter - * @param string $fixture - */ - public function testSearchByAdmin($filter, $fixture) - { - $response = $this->actingAs($this->admin)->json('get', '/media', $filter); - - $response->assertOk(); - - $this->assertEqualsFixture($fixture, $response->json()); - } - - /** - * @dataProvider getUserSearchFilters - * - * @param array $filter - * @param string $fixture - */ - public function testSearchByUser(array $filter, string $fixture): void - { - $response = $this->actingAs($this->user)->json('get', '/media', $filter); - - $response->assertOk(); - - $this->assertEqualsFixture($fixture, $response->json()); - } - - public function getBadFiles(): array - { - return [ - [ - 'filter' => ['fileName' => 'notAVirus.exe'], - ], - [ - 'filter' => ['fileName' => 'notAVirus.psd'], - ], - ]; - } - - /** - * @dataProvider getBadFiles - * - * @param array $filter - */ - public function testUploadingBadFiles(array $filter): void - { - $this->file = UploadedFile::fake()->create($filter['fileName'], 1024); - - $response = $this->actingAs($this->user)->json('post', '/media', ['file' => $this->file]); - - $response->assertUnprocessable(); - - $response->assertJson([ - 'errors' => [ - 'file' => ['The file must be a file of type: jpg, jpeg, bmp, png.'], - ], - ]); - } - - public function getGoodFiles(): array - { - return [ - [ - 'filter' => ['fileName' => 'image.jpg'], - ], - [ - 'filter' => ['fileName' => 'image.png'], - ], - [ - 'filter' => ['fileName' => 'image.bmp'], - ], - ]; - } - - /** - * @dataProvider getGoodFiles - * - * @param array $filter - */ - public function testUploadingGoodFiles(array $filter): void - { - $this->file = UploadedFile::fake()->image($filter['fileName'], 600, 600); - - $response = $this->actingAs($this->user)->json('post', '/media', ['file' => $this->file]); - - $response->assertCreated(); - - $this->assertDatabaseHas('media', ['id' => 6]); - } -} diff --git a/tests/Modules/Media/ModuleTestCase.php b/tests/Modules/Media/ModuleTestCase.php deleted file mode 100644 index 83205bc..0000000 --- a/tests/Modules/Media/ModuleTestCase.php +++ /dev/null @@ -1,41 +0,0 @@ -loadEnvironmentFrom('.env.testing'); - $app->make(Kernel::class)->bootstrap(); - - $this->truncateExceptTables = ['migrations', 'password_resets', 'roles']; - $this->prepareSequencesExceptTables = ['migrations', 'password_resets', 'settings', 'roles']; - - return $app; - } - - public function getFixturePath($fixtureName): string - { - $class = get_class($this); - $explodedClass = explode('\\', $class); - $className = Arr::last($explodedClass); - - return base_path("tests/Modules/Media/fixtures/{$className}/{$fixtureName}"); - } -} diff --git a/tests/Modules/Media/fixtures/MediaTest/dump.sql b/tests/Modules/Media/fixtures/MediaTest/dump.sql deleted file mode 100644 index 4c3da13..0000000 --- a/tests/Modules/Media/fixtures/MediaTest/dump.sql +++ /dev/null @@ -1,10 +0,0 @@ -INSERT INTO users(id, name, email, password, remember_token, set_password_hash, role_id, created_at, updated_at) VALUES - (1, 'Gerhard Feest', 'fidel.kutch@example.com', '$2y$10$X4receiTrF24bXrEbAiChOZ8TMNPqoXuhuThgynvBdWIHZeu5HzsS', null, null, 1, '2016-10-20 11:05:00', '2016-10-20 11:05:00'), - (2, 'Alien West', 'alien.west@example.com', 'old_password', null, 'restore_token', 2, '2016-10-20 11:05:00', '2016-10-20 11:05:00'); - -INSERT INTO media(id, name, owner_id, is_public, link, meta, created_at, updated_at, deleted_at) VALUES - (1, 'Product main photo', 1 , true, 'http://localhost/test.jpg', '{}', '2016-10-20 11:05:00', '2016-10-20 11:05:00', null), - (2, 'Category Photo photo', 1, false, 'http://localhost/test1.jpg', '{}', '2016-10-20 11:05:00', '2016-10-20 11:05:00', null), - (3, 'Deleted photo', 2, true, 'http://localhost/test3.jpg', '{}', '2016-10-20 11:05:00', '2016-10-20 11:05:00', '2016-10-20 11:05:00'), - (4, 'Photo', 2, true, 'http://localhost/test4.jpg', '{}', '2016-10-20 11:05:00', '2016-10-20 11:05:00', null), - (5, 'Private photo', 2, false, 'http://localhost/test5.jpg', '{}', '2016-10-20 11:05:00', '2016-10-20 11:05:00', null); \ No newline at end of file diff --git a/tests/Modules/Media/fixtures/MediaTest/get_by_all.json b/tests/Modules/Media/fixtures/MediaTest/get_by_all.json deleted file mode 100644 index 1dc9fc4..0000000 --- a/tests/Modules/Media/fixtures/MediaTest/get_by_all.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "data": [ - { - "id": 1, - "link": "http:\/\/localhost\/test.jpg", - "name": "Product main photo", - "meta": [] - }, - { - "id": 4, - "link": "http:\/\/localhost\/test4.jpg", - "name": "Photo", - "meta": [] - } - ], - "links": { - "first": "http:\/\/localhost\/media?page=1", - "last": "http:\/\/localhost\/media?page=1", - "prev": null, - "next": null - }, - "meta": { - "current_page": 1, - "from": 1, - "last_page": 1, - "links": [ - { - "url": null, - "label": "« Previous", - "active": false - }, - { - "url": "http:\/\/localhost\/media?page=1", - "label": "1", - "active": true - }, - { - "url": null, - "label": "Next »", - "active": false - } - ], - "path": "http:\/\/localhost\/media", - "per_page": 2, - "to": 2, - "total": 2 - } -} \ No newline at end of file diff --git a/tests/Modules/Media/fixtures/MediaTest/get_by_query_as_admin.json b/tests/Modules/Media/fixtures/MediaTest/get_by_query_as_admin.json deleted file mode 100644 index 87fb1f0..0000000 --- a/tests/Modules/Media/fixtures/MediaTest/get_by_query_as_admin.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "data": [ - { - "id": 1, - "link": "http:\/\/localhost\/test.jpg", - "name": "Product main photo", - "is_public": true, - "owner_id": 1, - "meta": [] - } - ], - "links": { - "first": "http:\/\/localhost\/media?page=1", - "last": "http:\/\/localhost\/media?page=1", - "prev": null, - "next": null - }, - "meta": { - "current_page": 1, - "from": 1, - "last_page": 1, - "links": [ - { - "url": null, - "label": "« Previous", - "active": false - }, - { - "url": "http:\/\/localhost\/media?page=1", - "label": "1", - "active": true - }, - { - "url": null, - "label": "Next »", - "active": false - } - ], - "path": "http:\/\/localhost\/media", - "per_page": 10, - "to": 1, - "total": 1 - } -} \ No newline at end of file diff --git a/tests/Modules/Media/fixtures/MediaTest/get_by_query_as_user.json b/tests/Modules/Media/fixtures/MediaTest/get_by_query_as_user.json deleted file mode 100644 index 7107071..0000000 --- a/tests/Modules/Media/fixtures/MediaTest/get_by_query_as_user.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "data": [ - { - "id": 1, - "link": "http:\/\/localhost\/test.jpg", - "name": "Product main photo", - "meta": [] - } - ], - "links": { - "first": "http:\/\/localhost\/media?page=1", - "last": "http:\/\/localhost\/media?page=1", - "prev": null, - "next": null - }, - "meta": { - "current_page": 1, - "from": 1, - "last_page": 1, - "links": [ - { - "url": null, - "label": "« Previous", - "active": false - }, - { - "url": "http:\/\/localhost\/media?page=1", - "label": "1", - "active": true - }, - { - "url": null, - "label": "Next »", - "active": false - } - ], - "path": "http:\/\/localhost\/media", - "per_page": 10, - "to": 1, - "total": 1 - } -} \ No newline at end of file diff --git a/tests/Modules/Media/fixtures/MediaTest/get_complex_as_admin.json b/tests/Modules/Media/fixtures/MediaTest/get_complex_as_admin.json deleted file mode 100644 index 56d7baf..0000000 --- a/tests/Modules/Media/fixtures/MediaTest/get_complex_as_admin.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "data": [ - { - "id": 2, - "link": "http:\/\/localhost\/test1.jpg", - "name": "Category Photo photo", - "is_public": false, - "owner_id": 1, - "meta": [] - }, - { - "id": 4, - "link": "http:\/\/localhost\/test4.jpg", - "name": "Photo", - "is_public": true, - "owner_id": 2, - "meta": [] - }, - { - "id": 5, - "link": "http:\/\/localhost\/test5.jpg", - "name": "Private photo", - "is_public": false, - "owner_id": 2, - "meta": [] - } - ], - "links": { - "first": "http:\/\/localhost\/media?page=1", - "last": "http:\/\/localhost\/media?page=2", - "prev": null, - "next": "http:\/\/localhost\/media?page=2" - }, - "meta": { - "current_page": 1, - "from": 1, - "last_page": 2, - "links": [ - { - "url": null, - "label": "« Previous", - "active": false - }, - { - "url": "http:\/\/localhost\/media?page=1", - "label": "1", - "active": true - }, - { - "url": "http:\/\/localhost\/media?page=2", - "label": "2", - "active": false - }, - { - "url": "http:\/\/localhost\/media?page=2", - "label": "Next »", - "active": false - } - ], - "path": "http:\/\/localhost\/media", - "per_page": 3, - "to": 3, - "total": 4 - } -} \ No newline at end of file diff --git a/tests/Modules/Media/fixtures/MediaTest/get_complex_as_user.json b/tests/Modules/Media/fixtures/MediaTest/get_complex_as_user.json deleted file mode 100644 index b577b71..0000000 --- a/tests/Modules/Media/fixtures/MediaTest/get_complex_as_user.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "data": [ - { - "id": 4, - "link": "http:\/\/localhost\/test4.jpg", - "name": "Photo", - "meta": [] - }, - { - "id": 5, - "link": "http:\/\/localhost\/test5.jpg", - "name": "Private photo", - "meta": [] - }, - { - "id": 1, - "link": "http:\/\/localhost\/test.jpg", - "name": "Product main photo", - "meta": [] - } - ], - "links": { - "first": "http:\/\/localhost\/media?page=1", - "last": "http:\/\/localhost\/media?page=1", - "prev": null, - "next": null - }, - "meta": { - "current_page": 1, - "from": 1, - "last_page": 1, - "links": [ - { - "url": null, - "label": "« Previous", - "active": false - }, - { - "url": "http:\/\/localhost\/media?page=1", - "label": "1", - "active": true - }, - { - "url": null, - "label": "Next »", - "active": false - } - ], - "path": "http:\/\/localhost\/media", - "per_page": 3, - "to": 3, - "total": 3 - } -} \ No newline at end of file diff --git a/tests/Modules/Media/fixtures/MediaTest/get_media.json b/tests/Modules/Media/fixtures/MediaTest/get_media.json deleted file mode 100644 index ba5c912..0000000 --- a/tests/Modules/Media/fixtures/MediaTest/get_media.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "id": 1, - "link": "http:\/\/localhost\/test.jpg", - "name": "Product main photo" -} diff --git a/tests/Modules/Media/fixtures/MediaTest/media.json b/tests/Modules/Media/fixtures/MediaTest/media.json deleted file mode 100644 index 323ec85..0000000 --- a/tests/Modules/Media/fixtures/MediaTest/media.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "id": "1", - "link": "vero", - "name": "aut" -} diff --git a/tests/Support/AuthTestTrait.php b/tests/Support/AuthTestTrait.php index d44cd14..32fbce7 100644 --- a/tests/Support/AuthTestTrait.php +++ b/tests/Support/AuthTestTrait.php @@ -11,7 +11,7 @@ trait AuthTestTrait public function mockOpensslRandomPseudoBytes(): void { $this->mockNativeFunction('App\Services', [ - $this->functionCall('openssl_random_pseudo_bytes', [], '5qw6rdsyd4sa65d4zxfc65ds4fc') + $this->functionCall('openssl_random_pseudo_bytes', [], '5qw6rdsyd4sa65d4zxfc65ds4fc'), ]); } diff --git a/tests/Support/InitCommandMockTrait.php b/tests/Support/InitCommandMockTrait.php index 06d9cc2..f92f927 100644 --- a/tests/Support/InitCommandMockTrait.php +++ b/tests/Support/InitCommandMockTrait.php @@ -32,7 +32,7 @@ public function mockShellExec(): void name: 'shell_exec', arguments: ['git ls-remote --get-url origin'], result: 'https://github.com/ronasit/laravel-helpers.git' - ) + ), ]); } } diff --git a/tests/Support/MediaTestTrait.php b/tests/Support/MediaTestTrait.php deleted file mode 100644 index 908d760..0000000 --- a/tests/Support/MediaTestTrait.php +++ /dev/null @@ -1,19 +0,0 @@ -mockClass( - class: MediaService::class, - callChain: array_fill(0, $callsCount, $this->functionCall('generateName', [], 'file.png')) - ); - } -} diff --git a/tests/UserTest.php b/tests/UserTest.php index 2213abe..837e17a 100644 --- a/tests/UserTest.php +++ b/tests/UserTest.php @@ -174,10 +174,6 @@ public function testDeleteProfile() $this->assertDatabaseMissing('users', [ 'id' => 2, ]); - - $this->assertDatabaseMissing('media', [ - 'owner_id' => 2, - ]); } public function testDeleteProfileWithoutBlacklist() @@ -242,7 +238,7 @@ public function testDeleteNoAuth() public function testGetProfile() { $response = $this->actingAs($this->admin)->json('get', '/profile', [ - 'with' => ['role', 'media.owner'], + 'with' => ['role'], ]); $response->assertOk(); @@ -253,7 +249,7 @@ public function testGetProfile() public function testGet() { $response = $this->actingAs($this->admin)->json('get', '/users/1', [ - 'with' => ['role', 'media.owner'], + 'with' => ['role'], ]); $response->assertOk(); diff --git a/tests/fixtures/UserTest/dump.sql b/tests/fixtures/UserTest/dump.sql index b52daf1..28b134f 100755 --- a/tests/fixtures/UserTest/dump.sql +++ b/tests/fixtures/UserTest/dump.sql @@ -1,9 +1,3 @@ INSERT INTO users(id, name, email, password, role_id, created_at, updated_at) VALUES (1, 'Mr Admin', 'admin@example.com', '$2y$10$X4receiTrF24bXrEbAiChOZ8TMNPqoXuhuThgynvBdWIHZeu5HzsS', 1, '2016-10-20 11:05:00', '2016-10-20 11:05:00'), - (2, 'Another User', 'user@example.com', '$2y$10$ywtTizICfzWDTU2Cp3s.8.HIvJpGUsvi66Y.x6ByBib8O.D2fxbSK', 2, '2016-10-20 11:05:00', '2016-10-20 11:05:00'); - -INSERT INTO media(id, name, owner_id, is_public, link, meta, created_at, updated_at, deleted_at) VALUES - (1, 'Product main photo', 1 , true, 'http://localhost/test.jpg', '{}', '2016-10-20 11:05:00', '2016-10-20 11:05:00', null), - (2, 'Category Photo photo', 1, false, 'http://localhost/test1.jpg', '{}', '2016-10-20 11:05:00', '2016-10-20 11:05:00', null), - (3, 'Deleted photo', 2, true, 'http://localhost/test3.jpg', '{}', '2016-10-20 11:05:00', '2016-10-20 11:05:00', '2016-10-20 11:05:00'), - (4, 'Photo', 2, true, 'http://localhost/test4.jpg', '{}', '2016-10-20 11:05:00', '2016-10-20 11:05:00', null); \ No newline at end of file + (2, 'Another User', 'user@example.com', '$2y$10$ywtTizICfzWDTU2Cp3s.8.HIvJpGUsvi66Y.x6ByBib8O.D2fxbSK', 2, '2016-10-20 11:05:00', '2016-10-20 11:05:00'); \ No newline at end of file diff --git a/tests/fixtures/UserTest/get_user.json b/tests/fixtures/UserTest/get_user.json index 6818d52..d1786ad 100644 --- a/tests/fixtures/UserTest/get_user.json +++ b/tests/fixtures/UserTest/get_user.json @@ -6,23 +6,5 @@ "role": { "id": 1, "name": "administrator" - }, - "media": [ - { - "id": 1, - "link": "http:\/\/localhost\/test.jpg", - "name": "Product main photo", - "is_public": true, - "owner_id": 1, - "meta": [] - }, - { - "id": 2, - "link": "http:\/\/localhost\/test1.jpg", - "name": "Category Photo photo", - "is_public": false, - "owner_id": 1, - "meta": [] - } - ] + } } \ No newline at end of file