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
6457696e
Unverified
Commit
6457696e
authored
Sep 21, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding a folder is creating hook
parent
e2f783e3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
2 deletions
+41
-2
FolderIsCreating.php
Modules/Media/Events/FolderIsCreating.php
+10
-0
EloquentFolderRepository.php
.../Media/Repositories/Eloquent/EloquentFolderRepository.php
+5
-2
EloquentFolderRepositoryTest.php
Modules/Media/Tests/EloquentFolderRepositoryTest.php
+26
-0
No files found.
Modules/Media/Events/FolderIsCreating.php
0 → 100644
View file @
6457696e
<?php
namespace
Modules\Media\Events
;
use
Modules\Core\Contracts\EntityIsChanging
;
use
Modules\Core\Events\AbstractEntityHook
;
class
FolderIsCreating
extends
AbstractEntityHook
implements
EntityIsChanging
{
}
Modules/Media/Repositories/Eloquent/EloquentFolderRepository.php
View file @
6457696e
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
Modules\Media\Repositories\Eloquent
;
namespace
Modules\Media\Repositories\Eloquent
;
use
Modules\Core\Repositories\Eloquent\EloquentBaseRepository
;
use
Modules\Core\Repositories\Eloquent\EloquentBaseRepository
;
use
Modules\Media\Events\FolderIsCreating
;
use
Modules\Media\Events\FolderWasCreated
;
use
Modules\Media\Events\FolderWasCreated
;
use
Modules\Media\Repositories\FolderRepository
;
use
Modules\Media\Repositories\FolderRepository
;
...
@@ -10,12 +11,14 @@ class EloquentFolderRepository extends EloquentBaseRepository implements FolderR
...
@@ -10,12 +11,14 @@ class EloquentFolderRepository extends EloquentBaseRepository implements FolderR
{
{
public
function
create
(
$data
)
public
function
create
(
$data
)
{
{
$
folder
=
$this
->
model
->
create
(
[
$
data
=
[
'filename'
=>
array_get
(
$data
,
'name'
),
'filename'
=>
array_get
(
$data
,
'name'
),
'path'
=>
config
(
'asgard.media.config.files-path'
)
.
str_slug
(
array_get
(
$data
,
'name'
)),
'path'
=>
config
(
'asgard.media.config.files-path'
)
.
str_slug
(
array_get
(
$data
,
'name'
)),
'is_folder'
=>
true
,
'is_folder'
=>
true
,
'folder_id'
=>
array_get
(
$data
,
'parent_id'
),
'folder_id'
=>
array_get
(
$data
,
'parent_id'
),
]);
];
event
(
$event
=
new
FolderIsCreating
(
$data
));
$folder
=
$this
->
model
->
create
(
$event
->
getAttributes
());
event
(
new
FolderWasCreated
(
$folder
,
$data
));
event
(
new
FolderWasCreated
(
$folder
,
$data
));
...
...
Modules/Media/Tests/EloquentFolderRepositoryTest.php
View file @
6457696e
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
Modules\Media\Tests
;
namespace
Modules\Media\Tests
;
use
Illuminate\Support\Facades\Event
;
use
Illuminate\Support\Facades\Event
;
use
Modules\Media\Events\FolderIsCreating
;
use
Modules\Media\Events\FolderWasCreated
;
use
Modules\Media\Events\FolderWasCreated
;
use
Modules\Media\Repositories\Eloquent\EloquentFolderRepository
;
use
Modules\Media\Repositories\Eloquent\EloquentFolderRepository
;
use
Modules\Media\Repositories\FolderRepository
;
use
Modules\Media\Repositories\FolderRepository
;
...
@@ -50,6 +51,31 @@ final class EloquentFolderRepositoryTest extends MediaTestCase
...
@@ -50,6 +51,31 @@ final class EloquentFolderRepositoryTest extends MediaTestCase
});
});
}
}
/** @test */
public
function
it_triggers_an_event_when_folder_is_creating
()
{
Event
::
fake
();
$folder
=
$this
->
folder
->
create
([
'name'
=>
'My Folder'
]);
Event
::
assertDispatched
(
FolderIsCreating
::
class
,
function
(
$e
)
use
(
$folder
)
{
return
$e
->
getAttribute
(
'filename'
)
===
$folder
->
filename
;
});
}
/** @test */
public
function
it_can_change_folder_data_before_creating_folder
()
{
Event
::
listen
(
FolderIsCreating
::
class
,
function
(
FolderIsCreating
$event
)
{
$filename
=
$event
->
getAttribute
(
'filename'
);
$event
->
setAttributes
([
'filename'
=>
strtoupper
(
$filename
)]);
});
$folder
=
$this
->
folder
->
create
([
'name'
=>
'My Folder'
]);
$this
->
assertEquals
(
'MY FOLDER'
,
$folder
->
filename
);
}
private
function
resetDatabase
()
private
function
resetDatabase
()
{
{
// Makes sure the migrations table is created
// Makes sure the migrations table is created
...
...
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