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
1890b5bb
Unverified
Commit
1890b5bb
authored
Dec 25, 2017
by
Viral Solani
Committed by
GitHub
Dec 25, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #103 from bvipul/develop
Added Manage Page Tests
parents
c90fdf22
333f1a78
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
161 additions
and
3 deletions
+161
-3
PagesRepository.php
app/Repositories/Backend/Pages/PagesRepository.php
+1
-1
composer.json
composer.json
+3
-0
PageFactory.php
database/factories/PageFactory.php
+15
-0
phpunit.xml
phpunit.xml
+2
-2
ManagePageTest.php
tests/Feature/ManagePageTest.php
+130
-0
TestCase.php
tests/TestCase.php
+10
-0
No files found.
app/Repositories/Backend/Pages/PagesRepository.php
View file @
1890b5bb
...
...
@@ -50,7 +50,7 @@ class PagesRepository extends BaseRepository
//Making extra fields
$input
[
'page_slug'
]
=
str_slug
(
$input
[
'title'
]);
$input
[
'status'
]
=
isset
(
$input
[
'status'
])
?
1
:
0
;
$input
[
'created_by'
]
=
a
ccess
()
->
user
()
->
id
;
$input
[
'created_by'
]
=
a
uth
()
->
id
()
;
if
(
$page
=
Page
::
create
(
$input
))
{
event
(
new
PageCreated
(
$page
));
...
...
composer.json
View file @
1890b5bb
...
...
@@ -55,6 +55,9 @@
},
"classmap"
:
[
"tests/TestCase.php"
],
"files"
:
[
"tests/Utilities/helpers.php"
]
},
"scripts"
:
{
...
...
database/factories/PageFactory.php
0 → 100644
View file @
1890b5bb
<?php
use
App\Models\Page\Page
;
use
Faker\Generator
as
Faker
;
$factory
->
define
(
Page
::
class
,
function
(
Faker
$faker
)
{
$title
=
$faker
->
sentence
;
return
[
'title'
=>
$title
,
'page_slug'
=>
str_slug
(
$title
),
'description'
=>
$faker
->
paragraph
,
'created_by'
=>
1
];
});
phpunit.xml
View file @
1890b5bb
...
...
@@ -33,11 +33,11 @@
<env
name=
"SCOUT_DRIVER"
value=
"null"
/>
</php>
<testsuites>
<
!-- <
testsuites>
<testsuite name="Application Test Suite">
<directory suffix="Test.php">
./tests
</directory>
</testsuite>
</testsuites>
</testsuites>
-->
</phpunit>
tests/Feature/ManagePageTest.php
0 → 100644
View file @
1890b5bb
<?php
namespace
Tests\Feature
;
use
Tests\TestCase
;
use
App\Models\Page\Page
;
use
Illuminate\Foundation\Testing\WithFaker
;
use
Illuminate\Foundation\Testing\RefreshDatabase
;
class
ManagePageTest
extends
TestCase
{
/** @test */
public
function
test_pages_index_route
()
{
$this
->
actingAs
(
$this
->
admin
)
->
get
(
route
(
'admin.pages.index'
))
->
assertSee
(
trans
(
'labels.backend.pages.management'
))
->
assertSee
(
trans
(
'labels.backend.pages.table.title'
))
->
assertSee
(
trans
(
'labels.backend.pages.table.status'
))
->
assertSee
(
$this
->
admin
->
name
);
}
/** @test */
public
function
test_create_and_edit_page_has_all_fields
()
{
$this
->
actingAs
(
$this
->
admin
)
->
get
(
route
(
'admin.pages.create'
))
->
assertSee
(
trans
(
'validation.attributes.backend.pages.title'
))
->
assertSee
(
trans
(
'validation.attributes.backend.pages.description'
))
->
assertSee
(
trans
(
'validation.attributes.backend.pages.cannonical_link'
))
->
assertSee
(
trans
(
'validation.attributes.backend.pages.seo_title'
))
->
assertSee
(
trans
(
'validation.attributes.backend.pages.seo_keyword'
))
->
assertSee
(
trans
(
'validation.attributes.backend.pages.seo_description'
))
->
assertSee
(
trans
(
'validation.attributes.backend.pages.is_active'
));
$page
=
create
(
Page
::
class
);
$this
->
actingAs
(
$this
->
admin
)
->
get
(
route
(
'admin.pages.edit'
,
$page
))
->
assertSee
(
trans
(
'validation.attributes.backend.pages.title'
))
->
assertSee
(
trans
(
'validation.attributes.backend.pages.description'
))
->
assertSee
(
trans
(
'validation.attributes.backend.pages.cannonical_link'
))
->
assertSee
(
trans
(
'validation.attributes.backend.pages.seo_title'
))
->
assertSee
(
trans
(
'validation.attributes.backend.pages.seo_keyword'
))
->
assertSee
(
trans
(
'validation.attributes.backend.pages.seo_description'
))
->
assertSee
(
trans
(
'validation.attributes.backend.pages.is_active'
));
}
/** @test */
public
function
test_create_page_successfully
()
{
$page
=
make
(
Page
::
class
);
$this
->
actingAs
(
$this
->
admin
)
->
post
(
route
(
'admin.pages.store'
),
$page
->
toArray
())
->
assertRedirect
(
route
(
'admin.pages.index'
));
$this
->
assertDatabaseHas
(
'pages'
,
[
'title'
=>
$page
->
title
,
'description'
=>
$page
->
description
]);
}
/** @test */
public
function
it_fails_for_validation_on_create_page
()
{
$page
=
make
(
Page
::
class
,
[
'title'
=>
''
,
'description'
=>
''
]);
$this
->
withExceptionHandling
()
->
actingAs
(
$this
->
admin
)
->
post
(
route
(
'admin.pages.store'
),
$page
->
toArray
())
->
assertSessionHasErrors
([
'title'
,
'description'
]);
$page
=
make
(
Page
::
class
,
[
'title'
=>
''
]);
$this
->
withExceptionHandling
()
->
actingAs
(
$this
->
admin
)
->
post
(
route
(
'admin.pages.store'
),
$page
->
toArray
())
->
assertSessionHasErrors
(
'title'
);
$page
=
make
(
Page
::
class
,
[
'description'
=>
''
]);
$this
->
withExceptionHandling
()
->
actingAs
(
$this
->
admin
)
->
post
(
route
(
'admin.pages.store'
),
$page
->
toArray
())
->
assertSessionHasErrors
(
'description'
);
}
/** @test */
public
function
it_updates_successfully
()
{
$page
=
create
(
Page
::
class
);
$title
=
'Changed title'
;
$slug
=
str_slug
(
$title
);
$description
=
'Changed Description'
;
$this
->
actingAs
(
$this
->
admin
)
->
patch
(
route
(
'admin.pages.update'
,
$page
),
[
'title'
=>
$title
,
'description'
=>
$description
]);
$this
->
assertDatabaseHas
(
'pages'
,
[
'id'
=>
$page
->
id
,
'title'
=>
$title
,
'page_slug'
=>
$slug
,
'description'
=>
$description
]);
}
/** @test */
public
function
it_fails_for_validation_on_update
()
{
$page
=
create
(
Page
::
class
);
$page1
=
$page2
=
$page3
=
$page
->
toArray
();
$page1
[
'title'
]
=
''
;
$page1
[
'description'
]
=
''
;
$this
->
withExceptionHandling
()
->
actingAs
(
$this
->
admin
)
->
post
(
route
(
'admin.pages.store'
),
$page1
)
->
assertSessionHasErrors
([
'title'
,
'description'
]);
$page2
[
'title'
]
=
''
;
$this
->
withExceptionHandling
()
->
actingAs
(
$this
->
admin
)
->
post
(
route
(
'admin.pages.store'
),
$page2
)
->
assertSessionHasErrors
(
'title'
);
$page3
[
'description'
]
=
''
;
$this
->
withExceptionHandling
()
->
actingAs
(
$this
->
admin
)
->
post
(
route
(
'admin.pages.store'
),
$page3
)
->
assertSessionHasErrors
(
'description'
);
}
}
tests/TestCase.php
View file @
1890b5bb
...
...
@@ -6,6 +6,7 @@ use App\Models\Access\Role\Role;
use
App\Models\Access\User\User
;
use
Illuminate\Foundation\Testing\TestCase
as
BaseTestCase
;
use
Illuminate\Support\Facades\Artisan
;
use
Illuminate\Support\Facades\DB
;
abstract
class
TestCase
extends
BaseTestCase
{
...
...
@@ -73,4 +74,13 @@ abstract class TestCase extends BaseTestCase
$this
->
executiveRole
=
Role
::
find
(
2
);
$this
->
userRole
=
Role
::
find
(
3
);
}
public
function
tearDown
()
{
$this
->
beforeApplicationDestroyed
(
function
()
{
DB
::
disconnect
();
});
parent
::
tearDown
();
}
}
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