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
1b867e39
Unverified
Commit
1b867e39
authored
Jan 08, 2018
by
Viral Solani
Committed by
GitHub
Jan 08, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #139 from viralsolani/analysis-qyL1yb
Apply fixes from StyleCI
parents
55b49b3a
14fbfac5
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
53 additions
and
61 deletions
+53
-61
BlogsRepository.php
app/Repositories/Backend/Blogs/BlogsRepository.php
+14
-15
BlogFactory.php
database/factories/BlogFactory.php
+8
-10
FaqFactory.php
database/factories/FaqFactory.php
+2
-2
PageFactory.php
database/factories/PageFactory.php
+2
-2
ManageBlogsTest.php
tests/Feature/Backend/ManageBlogsTest.php
+17
-20
ManageFaqsTest.php
tests/Feature/Backend/ManageFaqsTest.php
+3
-4
BlogTest.php
tests/Unit/Models/BlogTest.php
+7
-8
No files found.
app/Repositories/Backend/Blogs/BlogsRepository.php
View file @
1b867e39
...
...
@@ -2,20 +2,19 @@
namespace
App\Repositories\Backend\Blogs
;
use
DB
;
use
Carbon\Carbon
;
use
App\Models\Blogs\Blog
;
use
App\Models\BlogTags\BlogTag
;
use
App\Http\Utilities\FileUploads
;
use
App\Exceptions\GeneralException
;
use
App\Repositories\BaseRepository
;
use
App\Models\BlogMapTags\BlogMapTag
;
use
Illuminate\Support\Facades\Storage
;
use
App\Events\Backend\Blogs\BlogCreated
;
use
App\Events\Backend\Blogs\BlogDeleted
;
use
App\Events\Backend\Blogs\BlogUpdated
;
use
App\E
vents\Backend\Blogs\BlogCreated
;
use
App\E
xceptions\GeneralException
;
use
App\Models\BlogCategories\BlogCategory
;
use
App\Models\BlogMapCategories\BlogMapCategory
;
use
App\Models\BlogMapTags\BlogMapTag
;
use
App\Models\Blogs\Blog
;
use
App\Models\BlogTags\BlogTag
;
use
App\Repositories\BaseRepository
;
use
Carbon\Carbon
;
use
DB
;
use
Illuminate\Support\Facades\Storage
;
/**
* Class BlogsRepository.
...
...
@@ -38,7 +37,7 @@ class BlogsRepository extends BaseRepository
public
function
__construct
()
{
$this
->
upload_path
=
'img'
.
DIRECTORY_SEPARATOR
.
'blog'
.
DIRECTORY_SEPARATOR
;
$this
->
upload_path
=
'img'
.
DIRECTORY_SEPARATOR
.
'blog'
.
DIRECTORY_SEPARATOR
;
$this
->
storage
=
Storage
::
disk
(
'public'
);
}
...
...
@@ -229,9 +228,9 @@ class BlogsRepository extends BaseRepository
$avatar
=
$input
[
'featured_image'
];
if
(
isset
(
$input
[
'featured_image'
])
&&
!
empty
(
$input
[
'featured_image'
]))
{
$fileName
=
time
()
.
$avatar
->
getClientOriginalName
();
$fileName
=
time
()
.
$avatar
->
getClientOriginalName
();
$this
->
storage
->
put
(
$this
->
upload_path
.
$fileName
,
file_get_contents
(
$avatar
->
getRealPath
()));
$this
->
storage
->
put
(
$this
->
upload_path
.
$fileName
,
file_get_contents
(
$avatar
->
getRealPath
()));
$input
=
array_merge
(
$input
,
[
'featured_image'
=>
$fileName
]);
...
...
@@ -247,7 +246,7 @@ class BlogsRepository extends BaseRepository
public
function
deleteOldFile
(
$model
)
{
$fileName
=
$model
->
featured_image
;
return
$this
->
storage
->
delete
(
$this
->
upload_path
.
$fileName
);
return
$this
->
storage
->
delete
(
$this
->
upload_path
.
$fileName
);
}
}
database/factories/BlogFactory.php
View file @
1b867e39
<?php
use
App\Models\Access\User\User
;
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'
'Scheduled'
,
];
return
[
'name'
=>
$faker
->
sentence
,
'name'
=>
$faker
->
sentence
,
'publish_datetime'
=>
$faker
->
dateTime
(),
'featured_image'
=>
'logo.png'
,
'content'
=>
$faker
->
paragraph
(
3
),
'status'
=>
$status
[
$faker
->
numberBetween
(
0
,
3
)],
'created_by'
=>
function
()
{
'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/FaqFactory.php
View file @
1b867e39
...
...
@@ -5,8 +5,8 @@ use Faker\Generator as Faker;
$factory
->
define
(
Faq
::
class
,
function
(
Faker
$faker
)
{
return
[
'question'
=>
rtrim
(
$faker
->
sentence
,
'.'
)
.
'?'
,
'question'
=>
rtrim
(
$faker
->
sentence
,
'.'
)
.
'?'
,
'answer'
=>
$faker
->
paragraph
,
'status'
=>
$faker
->
numberBetween
(
0
,
1
)
'status'
=>
$faker
->
numberBetween
(
0
,
1
),
];
});
database/factories/PageFactory.php
View file @
1b867e39
<?php
use
App\Models\Access\User\User
;
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
;
...
...
@@ -11,7 +11,7 @@ $factory->define(Page::class, function (Faker $faker) {
'title'
=>
$title
,
'page_slug'
=>
str_slug
(
$title
),
'description'
=>
$faker
->
paragraph
,
'created_by'
=>
function
()
{
'created_by'
=>
function
()
{
return
factory
(
User
::
class
)
->
create
()
->
id
;
},
];
...
...
tests/Feature/Backend/ManageBlogsTest.php
View file @
1b867e39
...
...
@@ -2,13 +2,11 @@
namespace
Tests\Feature\Backend
;
use
Tests\TestCase
;
use
App\Models\Blogs\Blog
;
use
App\Models\BlogTags\BlogTag
;
use
Illuminate\Foundation\Testing\WithFaker
;
use
Illuminate\Http\UploadedFile
;
use
Illuminate\Support\Facades\Storage
;
use
App\Models\BlogCategories\BlogCategory
;
use
Illuminate\Foundation\Testing\WithFaker
;
use
Tests\TestCase
;
class
ManageBlogsTest
extends
TestCase
{
...
...
@@ -27,7 +25,6 @@ class ManageBlogsTest extends TestCase
$this
->
blog
=
create
(
Blog
::
class
);
$this
->
categories
=
[
$this
->
faker
->
word
,
$this
->
faker
->
word
];
$this
->
tags
=
[
$this
->
faker
->
word
,
$this
->
faker
->
word
];
}
/** @test */
...
...
@@ -48,21 +45,21 @@ class ManageBlogsTest extends TestCase
/** @test */
public
function
a_user_can_create_a_blog
()
{
{
$blog
=
make
(
Blog
::
class
,
[
'featured_image'
=>
UploadedFile
::
fake
()
->
image
(
'logo.jpg'
),
'categories'
=>
$this
->
categories
,
'tags'
=>
$this
->
tags
'categories'
=>
$this
->
categories
,
'tags'
=>
$this
->
tags
,
]);
$this
->
post
(
route
(
'admin.blogs.store'
),
$blog
->
toArray
());
$this
->
assertDatabaseHas
(
config
(
'module.blogs.table'
),
[
'name'
=>
$blog
->
name
,
'status'
=>
$blog
->
status
]);
//Assert Tags have been saved
$this
->
assertDatabaseHas
(
config
(
'module.blog_tags.table'
),
[
'name'
=>
$this
->
tags
[
0
]]);
$this
->
assertDatabaseHas
(
config
(
'module.blog_tags.table'
),
[
'name'
=>
$this
->
tags
[
1
]]);
//Assert Categories have been saved
$this
->
assertDatabaseHas
(
config
(
'module.blog_categories.table'
),
[
'name'
=>
$this
->
categories
[
0
]]);
$this
->
assertDatabaseHas
(
config
(
'module.blog_categories.table'
),
[
'name'
=>
$this
->
categories
[
1
]]);
...
...
@@ -108,7 +105,7 @@ class ManageBlogsTest extends TestCase
public
function
it_requires_categories_while_creating
()
{
$blog
=
$this
->
makeBlog
([
'categories'
=>
''
]);
$this
->
post
(
route
(
'admin.blogs.store'
),
$blog
->
toArray
())
->
assertSessionHasErrors
(
'categories'
);
}
...
...
@@ -127,15 +124,15 @@ class ManageBlogsTest extends TestCase
{
$blog
=
make
(
Blog
::
class
,
[
'featured_image'
=>
UploadedFile
::
fake
()
->
image
(
'logo.jpg'
),
'categories'
=>
$this
->
categories
,
'tags'
=>
$this
->
tags
'categories'
=>
$this
->
categories
,
'tags'
=>
$this
->
tags
,
]);
$this
->
post
(
route
(
'admin.blogs.store'
),
$blog
->
toArray
());
$stored_blog
=
Blog
::
find
(
2
);
Storage
::
disk
(
'public'
)
->
assertExists
(
'img/blog/'
.
$stored_blog
->
featured_image
);
Storage
::
disk
(
'public'
)
->
assertExists
(
'img/blog/'
.
$stored_blog
->
featured_image
);
}
/** @test */
...
...
@@ -159,7 +156,7 @@ class ManageBlogsTest extends TestCase
$this
->
patch
(
route
(
'admin.blogs.update'
,
$this
->
blog
),
$this
->
blog
->
toArray
())
->
assertSessionHasErrors
(
'content'
);
}
/** @test */
public
function
it_requires_categories_while_updating
()
{
...
...
@@ -182,17 +179,17 @@ class ManageBlogsTest extends TestCase
public
function
a_user_can_update_blog
()
{
$blog
=
make
(
Blog
::
class
,
[
'featured_image'
=>
UploadedFile
::
fake
()
->
image
(
'logo.jpg'
),
'name'
=>
'Changed Name'
,
'categories'
=>
$this
->
categories
,
'tags'
=>
$this
->
tags
'featured_image'
=>
UploadedFile
::
fake
()
->
image
(
'logo.jpg'
),
'name'
=>
'Changed Name'
,
'categories'
=>
$this
->
categories
,
'tags'
=>
$this
->
tags
,
]);
$this
->
patch
(
route
(
'admin.blogs.update'
,
$this
->
blog
),
$blog
->
toArray
());
$this
->
assertDatabaseHas
(
config
(
'module.blogs.table'
),
[
'id'
=>
$this
->
blog
->
id
,
'name'
=>
'Changed Name'
]);
}
/** @test */
public
function
a_user_can_delete_a_blog
()
{
...
...
tests/Feature/Backend/ManageFaqsTest.php
View file @
1b867e39
...
...
@@ -2,8 +2,8 @@
namespace
Tests\Feature\Backend
;
use
Tests\TestCase
;
use
App\Models\Faqs\Faq
;
use
Tests\TestCase
;
class
ManageFaqsTest
extends
TestCase
{
...
...
@@ -43,7 +43,6 @@ class ManageFaqsTest extends TestCase
->
assertSessionHasErrors
(
'question'
);
}
/** @test */
public
function
it_requires_answer_while_creating
()
{
...
...
@@ -82,7 +81,7 @@ class ManageFaqsTest extends TestCase
{
$faq
=
create
(
Faq
::
class
);
$changed_question
=
"What is Life?"
;
$changed_question
=
'What is Life?'
;
$changed_answer
=
$faq
->
answer
;
$this
->
actingAs
(
$this
->
admin
)
->
patch
(
route
(
'admin.faqs.update'
,
$faq
),
[
'question'
=>
$changed_question
,
'answer'
=>
$changed_answer
]);
...
...
@@ -96,7 +95,7 @@ class ManageFaqsTest extends TestCase
$faq
=
create
(
Faq
::
class
);
$this
->
actingAs
(
$this
->
admin
)
->
delete
(
route
(
'admin.faqs.destroy'
,
$faq
));
->
delete
(
route
(
'admin.faqs.destroy'
,
$faq
));
$this
->
assertDatabaseMissing
(
config
(
'module.faqs.table'
),
[
'id'
=>
$faq
->
id
,
'deleted_at'
=>
null
]);
}
...
...
tests/Unit/Models/BlogTest.php
View file @
1b867e39
...
...
@@ -2,13 +2,12 @@
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
;
use
App\Models\Blogs\Blog
;
use
App\Models\BlogTags\BlogTag
;
use
Carbon\Carbon
;
use
Tests\TestCase
;
class
BlogTest
extends
TestCase
{
...
...
@@ -21,8 +20,8 @@ class BlogTest extends TestCase
$category
=
create
(
BlogCategory
::
class
);
$blog
->
categories
()
->
sync
(
array
(
$category
->
id
)
);
$blog
->
categories
()
->
sync
(
[
$category
->
id
]
);
$this
->
assertInstanceOf
(
BlogCategory
::
class
,
$blog
->
categories
->
first
());
$this
->
assertEquals
(
$category
->
id
,
$blog
->
categories
->
first
()
->
id
);
...
...
@@ -37,7 +36,7 @@ class BlogTest extends TestCase
$tag
=
create
(
BlogTag
::
class
);
$blog
->
tags
()
->
sync
(
array
(
$tag
->
id
)
);
$blog
->
tags
()
->
sync
(
[
$tag
->
id
]
);
$this
->
assertInstanceOf
(
BlogTag
::
class
,
$blog
->
tags
->
first
());
...
...
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