Skip to content
This repository was archived by the owner on Sep 28, 2019. It is now read-only.

Commit fb0d2f2

Browse files
committed
added few unit test
1 parent 58a5bc5 commit fb0d2f2

File tree

6 files changed

+143
-30
lines changed

6 files changed

+143
-30
lines changed

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
"AvoRed\\Ecommerce\\": "src/"
3737
}
3838
},
39+
"autoload-dev" : {
40+
"psr-4" : {
41+
"AvoRed\\Ecommerce\\Tests\\" : "tests/"
42+
}
43+
},
3944
"extra": {
4045
"laravel": {
4146
"providers": [

database/migrations/2017_03_29_000001_avored_ecommerce_schema.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,27 @@ public function up()
2828
$table->timestamp('created_at');
2929
});
3030

31+
Schema::create('roles', function (Blueprint $table) {
32+
$table->increments('id');
33+
$table->string('name')->nullable()->default(null);
34+
$table->text('description')->nullable()->default(null);
35+
$table->timestamps();
36+
});
37+
3138
Schema::create('admin_users', function (Blueprint $table) {
3239
$table->increments('id');
3340
$table->tinyInteger('is_super_admin')->nullable();
34-
$table->integer('role_id');
35-
$table->string('first_name');
36-
$table->string('last_name');
41+
$table->integer('role_id')->unsigned()->default(null);
42+
$table->string('first_name')->nullable();
43+
$table->string('last_name')->nullable();
3744
$table->string('email')->unique();
3845
$table->string('password');
3946
$table->string('language')->nullable()->default('en');
4047
$table->string('image_path')->nullable()->default(null);
4148
$table->rememberToken();
4249
$table->timestamps();
50+
51+
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
4352
});
4453

4554
Schema::create('users', function (Blueprint $table) {
@@ -130,9 +139,9 @@ public function up()
130139

131140
Schema::create('pages', function (Blueprint $table) {
132141
$table->increments('id');
133-
$table->string('name');
134-
$table->string('slug');
135-
$table->text('content');
142+
$table->string('name')->nullable()->default(null);
143+
$table->string('slug')->nullable()->default(null);
144+
$table->text('content')->nullable()->default(null);
136145
$table->string('meta_title')->nullable();
137146
$table->string('meta_description')->nullable();
138147
$table->timestamps();
@@ -148,13 +157,6 @@ public function up()
148157
$table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
149158
});
150159

151-
Schema::create('roles', function (Blueprint $table) {
152-
$table->increments('id');
153-
$table->string('name');
154-
$table->text('description');
155-
$table->timestamps();
156-
});
157-
158160
Schema::create('permissions', function (Blueprint $table) {
159161
$table->increments('id');
160162
$table->string('name')->unique();
@@ -184,9 +186,9 @@ public function up()
184186
});
185187

186188
Schema::table('orders', function (Blueprint $table) {
187-
$table->integer('user_id')->unsigned();
188-
$table->integer('shipping_address_id')->unsigned();
189-
$table->integer('billing_address_id')->unsigned();
189+
$table->integer('user_id')->unsigned()->nullable();
190+
$table->integer('shipping_address_id')->unsigned()->nullable();
191+
$table->integer('billing_address_id')->unsigned()->nullable();
190192

191193
$table->foreign('user_id')->references('id')->on('users');
192194
$table->foreign('shipping_address_id')->references('id')->on('addresses');

src/Http/Controllers/DashboardController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public function __construct(OrderInterface $repository)
2525
*/
2626
public function index()
2727
{
28+
29+
2830
$value = Configuration::getConfiguration('avored_user_total');
2931
$totalRegisteredUser = (null === $value) ? 0 : $value;
3032

src/Http/Controllers/OrderController.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616

1717
class OrderController extends Controller
1818
{
19-
20-
/**
21-
*
22-
* @var \AvoRed\Framework\Models\Repository\OrderRepository
23-
*/
19+
/**
20+
*
21+
* @var \AvoRed\Framework\Models\Repository\OrderRepository
22+
*/
2423
protected $repository;
2524

2625
public function __construct(OrderInterface $repository)
@@ -41,9 +40,9 @@ public function index()
4140
}
4241

4342
/**
44-
* View an Order Details
43+
* View an Order Details
4544
* @param \AvoRed\Ecommerce\Models\Database\Order $order
46-
*
45+
*
4746
* @return \Illuminate\Http\Response
4847
*/
4948
public function view(Model $order)
@@ -54,19 +53,19 @@ public function view(Model $order)
5453
/**
5554
* Send an Order Invioced PDF to User
5655
* @param \AvoRed\Ecommerce\Models\Database\Order $order
57-
*
56+
*
5857
* @return \Illuminate\Http\RedirectResponse
5958
*/
6059
public function sendEmailInvoice(Model $order)
6160
{
62-
$user = $order->user;
61+
$user = $order->user;
6362
$view = view('avored-ecommerce::mail.order-pdf')->with('order', $order);
6463

6564
$folderPath = public_path('uploads/order/invoice');
66-
if (! File::exists($folderPath)) {
65+
if (!File::exists($folderPath)) {
6766
File::makeDirectory($folderPath, '0775', true, true);
6867
}
69-
$path = $folderPath.DIRECTORY_SEPARATOR.$order->id.'.pdf';
68+
$path = $folderPath . DIRECTORY_SEPARATOR . $order->id . '.pdf';
7069
PDF::loadHTML($view->render())->save($path);
7170

7271
Mail::to($user->email)->send(new OrderInvoicedMail($order, $path));
@@ -77,7 +76,7 @@ public function sendEmailInvoice(Model $order)
7776
/**
7877
* Edit the Order Status View
7978
* @param \AvoRed\Ecommerce\Models\Database\Order $order
80-
*
79+
*
8180
* @return \Illuminate\Http\Response
8281
*/
8382
public function editStatus(Model $order)
@@ -92,10 +91,10 @@ public function editStatus(Model $order)
9291
return $view;
9392
}
9493

95-
/**
94+
/**
9695
* Change the Order Status
9796
* @param \AvoRed\Ecommerce\Models\Database\Order $order
98-
*
97+
*
9998
* @return \Illuminate\Http\RedirectResponse
10099
*/
101100
public function updateStatus(Model $order, UpdateOrderStatusRequest $request)

tests/BaseTestCase.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace AvoRed\Ecommerce\Tests;
4+
5+
use AvoRed\Ecommerce\Provider;
6+
use AvoRed\Framework\Provider as FrameworkProvider;
7+
use Orchestra\Testbench\TestCase as OrchestraTestCase;
8+
9+
abstract class BaseTestCase extends OrchestraTestCase
10+
{
11+
public function setUp()
12+
{
13+
parent::setUp();
14+
$this->app['config']->set('app.key', 'base64:UTyp33UhGolgzCK5CJmT+hNHcA+dJyp3+oINtX+VoPI=');
15+
$this->app['config']->set('app.url', 'http://localhost:8000/admin');
16+
17+
$this->setUpDatabase();
18+
$this->resetDatabase();
19+
}
20+
21+
private function resetDatabase()
22+
{
23+
$this->artisan('migrate', [
24+
'--database' => 'sqlite',
25+
]);
26+
}
27+
28+
protected function getPackageProviders($app)
29+
{
30+
return [
31+
FrameworkProvider::class,
32+
Provider::class,
33+
];
34+
}
35+
36+
protected function getPackageAliases($app)
37+
{
38+
return [
39+
'Widget' => 'AvoRed\Framework\Widget\Facade'
40+
];
41+
}
42+
43+
/**
44+
* Set up the environment.
45+
*
46+
* @param \Illuminate\Foundation\Application $app
47+
*/
48+
protected function getEnvironmentSetUp($app)
49+
{
50+
$app['config']->set('database.default', 'sqlite');
51+
$app['config']->set('database.connections.sqlite', [
52+
'driver' => 'sqlite',
53+
'database' => ':memory:',
54+
'prefix' => '',
55+
]);
56+
}
57+
58+
protected function setUpDatabase()
59+
{
60+
$this->resetDatabase();
61+
}
62+
}

tests/Controller/LoginTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace AvoRed\Ecommerce\Tests\Controller;
4+
5+
use AvoRed\Ecommerce\Tests\BaseTestCase;
6+
use AvoRed\Ecommerce\Models\Database\AdminUser;
7+
use AvoRed\Ecommerce\Models\Database\Role;
8+
9+
class LoginTest extends BaseTestCase
10+
{
11+
/**
12+
* Test to check if admin login get controller is working
13+
*
14+
* @return void
15+
*/
16+
public function testLoginGetTest()
17+
{
18+
$response = $this->get('login');
19+
$response->assertStatus(200);
20+
$response->assertSee('AvoRed Admin Login');
21+
}
22+
23+
/**
24+
* Test to check if admin login get controller is working
25+
*
26+
* @return void
27+
*/
28+
public function testLoginPostTest()
29+
{
30+
$role = Role::create(['name' => 'Administrator','description' => 'Administrator']);
31+
$user = AdminUser::create(['role_id' => $role->id,
32+
'is_super_admin' => 1,
33+
'first_name' => 'Purvesh',
34+
'last_name' => 'Patel',
35+
'email' => '[email protected]',
36+
'password' => bcrypt('admin123')
37+
]);
38+
39+
$response = $this->post('login', ['email' => '[email protected]', 'password' => 'admin123']);
40+
$response->assertRedirect('admin');
41+
42+
}
43+
}

0 commit comments

Comments
 (0)