Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-adminpanel
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
laravel-adminpanel
Commits
d16f91bd
Commit
d16f91bd
authored
Jan 02, 2018
by
bvipul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Blog Unit test
parent
4b3a1cd8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
118 additions
and
3 deletions
+118
-3
BlogRelationship.php
app/Models/Blogs/Traits/Relationship/BlogRelationship.php
+2
-2
BlogFactory.php
database/factories/BlogFactory.php
+26
-0
PageFactory.php
database/factories/PageFactory.php
+4
-1
ManageBlogsTest.php
tests/Feature/Backend/ManageBlogsTest.php
+20
-0
BlogTest.php
tests/Unit/Models/BlogTest.php
+66
-0
No files found.
app/Models/Blogs/Traits/Relationship/BlogRelationship.php
View file @
d16f91bd
...
...
@@ -30,8 +30,8 @@ trait BlogRelationship
/**
* Blogs belongsTo with User.
*/
public
function
createdBy
()
public
function
owner
()
{
return
$this
->
belongsTo
(
User
::
class
,
'created_by'
,
'id'
);
return
$this
->
belongsTo
(
User
::
class
,
'created_by'
);
}
}
database/factories/BlogFactory.php
0 → 100644
View file @
d16f91bd
<?php
use
App\Models\Blogs\Blog
;
use
Faker\Generator
as
Faker
;
use
App\Models\Access\User\User
;
$factory
->
define
(
Blog
::
class
,
function
(
Faker
$faker
)
{
$status
=
[
'Published'
,
'Draft'
,
'InActive'
,
'Scheduled'
];
return
[
'name'
=>
$faker
->
sentence
,
'publish_datetime'
=>
$faker
->
dateTime
(),
'featured_image'
=>
'logo.png'
,
'content'
=>
$faker
->
paragraph
(
3
),
'status'
=>
$status
[
$faker
->
numberBetween
(
0
,
3
)],
'created_by'
=>
function
()
{
return
factory
(
User
::
class
)
->
create
()
->
id
;
},
];
});
database/factories/PageFactory.php
View file @
d16f91bd
...
...
@@ -2,6 +2,7 @@
use
App\Models\Page\Page
;
use
Faker\Generator
as
Faker
;
use
App\Models\Access\User\User
;
$factory
->
define
(
Page
::
class
,
function
(
Faker
$faker
)
{
$title
=
$faker
->
sentence
;
...
...
@@ -10,6 +11,8 @@ $factory->define(Page::class, function (Faker $faker) {
'title'
=>
$title
,
'page_slug'
=>
str_slug
(
$title
),
'description'
=>
$faker
->
paragraph
,
'created_by'
=>
1
,
'created_by'
=>
function
()
{
return
factory
(
User
::
class
)
->
create
()
->
id
;
},
];
});
tests/Feature/Backend/ManageBlogsTest.php
0 → 100644
View file @
d16f91bd
<?php
namespace
Tests\Feature\Backend
;
use
Tests\TestCase
;
use
Illuminate\Foundation\Testing\WithFaker
;
use
Illuminate\Foundation\Testing\RefreshDatabase
;
class
ManageBlogsTest
extends
TestCase
{
/**
* A basic test example.
*
* @return void
*/
public
function
testExample
()
{
$this
->
assertTrue
(
true
);
}
}
tests/Unit/Models/BlogTest.php
0 → 100644
View file @
d16f91bd
<?php
namespace
Tests\Unit\Models
;
use
Carbon\Carbon
;
use
Tests\TestCase
;
use
App\Models\Blogs\Blog
;
use
App\Models\BlogTags\BlogTag
;
use
App\Models\Access\User\User
;
use
App\Models\BlogCategories\BlogCategory
;
use
Illuminate\Foundation\Testing\WithFaker
;
class
BlogTest
extends
TestCase
{
/** @test */
public
function
it_has_categories
()
{
$this
->
actingAs
(
$this
->
admin
);
$blog
=
create
(
Blog
::
class
,
[
'created_by'
=>
access
()
->
id
()]);
$category
=
create
(
BlogCategory
::
class
);
$blog
->
categories
()
->
sync
(
array
(
$category
->
id
));
$this
->
assertInstanceOf
(
BlogCategory
::
class
,
$blog
->
categories
->
first
());
$this
->
assertEquals
(
$category
->
id
,
$blog
->
categories
->
first
()
->
id
);
}
/** @test */
public
function
it_has_tags
()
{
$this
->
actingAs
(
$this
->
admin
);
$blog
=
create
(
Blog
::
class
,
[
'created_by'
=>
access
()
->
id
()]);
$tag
=
create
(
BlogTag
::
class
);
$blog
->
tags
()
->
sync
(
array
(
$tag
->
id
));
$this
->
assertInstanceOf
(
BlogTag
::
class
,
$blog
->
tags
->
first
());
$this
->
assertEquals
(
$tag
->
id
,
$blog
->
tags
->
first
()
->
id
);
}
/** @test */
public
function
it_has_an_owner
()
{
$this
->
actingAs
(
$this
->
admin
);
$blog
=
create
(
Blog
::
class
);
$this
->
assertInstanceOf
(
User
::
class
,
$blog
->
owner
);
}
/** @test */
public
function
it_has_a_date_field_for_publish_datetime
()
{
$this
->
actingAs
(
$this
->
admin
);
$blog
=
create
(
Blog
::
class
);
$this
->
assertInstanceOf
(
Carbon
::
class
,
$blog
->
publish_datetime
);
}
}
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