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
ef6948a0
Unverified
Commit
ef6948a0
authored
Jul 12, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create and trigger events when tags are created and updated
parent
ebefec72
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
0 deletions
+97
-0
TagWasCreated.php
Modules/Tag/Events/TagWasCreated.php
+18
-0
TagWasUpdated.php
Modules/Tag/Events/TagWasUpdated.php
+18
-0
EloquentTagRepository.php
Modules/Tag/Repositories/Eloquent/EloquentTagRepository.php
+21
-0
EloquentTagRepositoryTest.php
Modules/Tag/Tests/Integration/EloquentTagRepositoryTest.php
+40
-0
No files found.
Modules/Tag/Events/TagWasCreated.php
0 → 100644
View file @
ef6948a0
<?php
namespace
Modules\Tag\Events
;
use
Modules\Tag\Entities\Tag
;
class
TagWasCreated
{
/**
* @var Tag
*/
public
$tag
;
public
function
__construct
(
Tag
$tag
)
{
$this
->
tag
=
$tag
;
}
}
Modules/Tag/Events/TagWasUpdated.php
0 → 100644
View file @
ef6948a0
<?php
namespace
Modules\Tag\Events
;
use
Modules\Tag\Entities\Tag
;
class
TagWasUpdated
{
/**
* @var Tag
*/
public
$tag
;
public
function
__construct
(
Tag
$tag
)
{
$this
->
tag
=
$tag
;
}
}
Modules/Tag/Repositories/Eloquent/EloquentTagRepository.php
View file @
ef6948a0
...
...
@@ -3,6 +3,8 @@
namespace
Modules\Tag\Repositories\Eloquent
;
use
Modules\Core\Repositories\Eloquent\EloquentBaseRepository
;
use
Modules\Tag\Events\TagWasCreated
;
use
Modules\Tag\Events\TagWasUpdated
;
use
Modules\Tag\Repositories\TagRepository
;
class
EloquentTagRepository
extends
EloquentBaseRepository
implements
TagRepository
...
...
@@ -16,4 +18,23 @@ class EloquentTagRepository extends EloquentBaseRepository implements TagReposit
{
return
$this
->
model
->
with
(
'translations'
)
->
where
(
'namespace'
,
$namespace
)
->
get
();
}
public
function
create
(
$data
)
{
$tag
=
$this
->
model
->
create
(
$data
);
event
(
new
TagWasCreated
(
$tag
));
return
$tag
;
}
public
function
update
(
$tag
,
$data
)
{
$tag
->
update
(
$data
);
event
(
new
TagWasUpdated
(
$tag
));
return
$tag
;
}
}
Modules/Tag/Tests/Integration/EloquentTagRepositoryTest.php
View file @
ef6948a0
...
...
@@ -2,6 +2,9 @@
namespace
Modules\Tag\Tests\Integration
;
use
Illuminate\Support\Facades\Event
;
use
Modules\Tag\Events\TagWasCreated
;
use
Modules\Tag\Events\TagWasUpdated
;
use
Modules\Tag\Repositories\TagRepository
;
use
Modules\Tag\Tests\BaseTestCase
;
...
...
@@ -46,4 +49,41 @@ class EloquentTagRepositoryTest extends BaseTestCase
$this
->
assertCount
(
1
,
$this
->
tag
->
allForNamespace
(
'asgardcms/blog'
));
}
/** @test */
public
function
it_triggers_event_when_tag_was_created
()
{
Event
::
fake
();
$tag
=
$this
->
tag
->
create
([
'namespace'
=>
'asgardcms/media'
,
'en'
=>
[
'slug'
=>
'media-tag'
,
'name'
=>
'media tag'
,
],
]);
Event
::
assertDispatched
(
TagWasCreated
::
class
,
function
(
$e
)
use
(
$tag
)
{
return
$e
->
tag
->
id
===
$tag
->
id
;
});
}
/** @test */
public
function
it_triggers_event_when_tag_was_updated
()
{
Event
::
fake
();
$tag
=
$this
->
tag
->
create
([
'namespace'
=>
'asgardcms/media'
,
'en'
=>
[
'slug'
=>
'media-tag'
,
'name'
=>
'media tag'
,
],
]);
$this
->
tag
->
update
(
$tag
,
[]);
Event
::
assertDispatched
(
TagWasUpdated
::
class
,
function
(
$e
)
use
(
$tag
)
{
return
$e
->
tag
->
id
===
$tag
->
id
;
});
}
}
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