Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
45f07bb8
Unverified
Commit
45f07bb8
authored
Sep 26, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding method to get all folders only. Testing deletion of a folder in database.
parent
d3e639cb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
0 deletions
+43
-0
EloquentFolderRepository.php
.../Media/Repositories/Eloquent/EloquentFolderRepository.php
+10
-0
EloquentFolderRepositoryTest.php
Modules/Media/Tests/EloquentFolderRepositoryTest.php
+33
-0
No files found.
Modules/Media/Repositories/Eloquent/EloquentFolderRepository.php
View file @
45f07bb8
...
@@ -12,6 +12,11 @@ use Modules\Media\Repositories\FolderRepository;
...
@@ -12,6 +12,11 @@ use Modules\Media\Repositories\FolderRepository;
class
EloquentFolderRepository
extends
EloquentBaseRepository
implements
FolderRepository
class
EloquentFolderRepository
extends
EloquentBaseRepository
implements
FolderRepository
{
{
public
function
all
()
{
return
$this
->
model
->
with
(
'translations'
)
->
where
(
'is_folder'
,
1
)
->
orderBy
(
'created_at'
,
'DESC'
)
->
get
();
}
/**
/**
* Find a folder by its ID
* Find a folder by its ID
* @param int $folderId
* @param int $folderId
...
@@ -58,6 +63,11 @@ class EloquentFolderRepository extends EloquentBaseRepository implements FolderR
...
@@ -58,6 +63,11 @@ class EloquentFolderRepository extends EloquentBaseRepository implements FolderR
return
$model
;
return
$model
;
}
}
public
function
destroy
(
$folder
)
{
return
$folder
->
delete
();
}
/**
/**
* @param array $data
* @param array $data
* @return string
* @return string
...
...
Modules/Media/Tests/EloquentFolderRepositoryTest.php
View file @
45f07bb8
...
@@ -226,4 +226,37 @@ final class EloquentFolderRepositoryTest extends MediaTestCase
...
@@ -226,4 +226,37 @@ final class EloquentFolderRepositoryTest extends MediaTestCase
$this
->
assertEquals
(
'/assets/media/new-name/my-second-file.jpg'
,
$fileTwo
->
path
->
getRelativeUrl
());
$this
->
assertEquals
(
'/assets/media/new-name/my-second-file.jpg'
,
$fileTwo
->
path
->
getRelativeUrl
());
$this
->
assertEquals
(
'/assets/media/new-name/child-folder/my-third-file.jpg'
,
$fileThree
->
path
->
getRelativeUrl
());
$this
->
assertEquals
(
'/assets/media/new-name/child-folder/my-third-file.jpg'
,
$fileThree
->
path
->
getRelativeUrl
());
}
}
/** @test */
public
function
it_can_find_all_folders
()
{
$parentFolder
=
$this
->
folder
->
create
([
'name'
=>
'My Folder'
]);
$this
->
folder
->
create
([
'name'
=>
'Child folder'
,
'parent_id'
=>
$parentFolder
->
id
]);
$this
->
createFile
();
$this
->
createFile
(
'second-file.jpg'
);
$this
->
assertCount
(
2
,
$this
->
folder
->
all
());
}
/** @test */
public
function
it_can_delete_a_folder_from_database
()
{
$folder
=
$this
->
folder
->
create
([
'name'
=>
'My Folder'
]);
$this
->
assertCount
(
1
,
$this
->
folder
->
all
());
$this
->
folder
->
destroy
(
$folder
);
$this
->
assertCount
(
0
,
$this
->
folder
->
all
());
}
private
function
createFile
(
$fileName
=
'random/name.jpg'
)
{
return
File
::
create
([
'filename'
=>
$fileName
,
'path'
=>
config
(
'asgard.media.config.files-path'
)
.
$fileName
,
'extension'
=>
substr
(
strrchr
(
$fileName
,
"."
),
1
),
'mimetype'
=>
'image/jpg'
,
'filesize'
=>
'1024'
,
'folder_id'
=>
0
,
]);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment