From 571e266c15bd6c2aeb51245d87037bbc8467d51e Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Mon, 14 Jan 2019 14:46:18 +0530 Subject: [PATCH] Few more test cases related to customer authentication --- tests/Feature/Auth/AuthTest.php | 75 +++++++++++++++++++ .../{LoginTest.php => GeneralTest.php} | 26 ++++++- 2 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 tests/Feature/Auth/AuthTest.php rename tests/Feature/{LoginTest.php => GeneralTest.php} (79%) diff --git a/tests/Feature/Auth/AuthTest.php b/tests/Feature/Auth/AuthTest.php new file mode 100644 index 000000000..1996cedbc --- /dev/null +++ b/tests/Feature/Auth/AuthTest.php @@ -0,0 +1,75 @@ + 'http://127.0.0.1:8000']); + + $response = $this->get('/customer/login'); + + $response->assertSuccessful(); + + $response->assertViewIs('shop::customers.session.index'); + } + + public function testCustomerResgistrationPage() { + config(['app.url' => 'http://127.0.0.1:8000']); + + $response = $this->get('/customer/register'); + + $response->assertSuccessful(); + + $response->assertViewIs('shop::customers.signup.index'); + } + + public function testCustomerRegistration() { + $faker = \Faker\Factory::create(); + + $allCustomers = array(); + + $customers = app(Customer::class); + + $created = $customers->create([ + 'first_name' => explode(' ',$faker->name)[0], + 'last_name' => explode(' ',$faker->name)[0], + 'channel_id' => core()->getCurrentChannel()->id, + 'gender' => $faker->randomElement($array = array ('Male','Female', 'Other')), + 'date_of_birth' => $faker->date($format = 'Y-m-d', $max = 'now'), + 'email' => $faker->email, + 'password' => bcrypt('12345678'), + 'is_verified' => 1 + ]); + + $this->assertEquals($created->id, $created->id); + } + + public function testCustomerLogin() { + $customers = app(Customer::class); + + $customer = $customers->find(1); + + $user = ['email' => $customer->email, 'password' => $customer->password]; + + $this->assertAuthenticatedAs($user); + } +} diff --git a/tests/Feature/LoginTest.php b/tests/Feature/GeneralTest.php similarity index 79% rename from tests/Feature/LoginTest.php rename to tests/Feature/GeneralTest.php index 5adf1a910..b11a14949 100644 --- a/tests/Feature/LoginTest.php +++ b/tests/Feature/GeneralTest.php @@ -11,10 +11,10 @@ use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Foundation\Testing\RefreshDatabase; -class LoginTest extends TestCase +class GeneralTest extends TestCase { /** - * A basic test example. + * Test for home page * * @return void */ @@ -27,6 +27,11 @@ class LoginTest extends TestCase $response->assertStatus(200); } + /** + * Test for customer login + * + * @return void + */ public function testCustomerLoginPage() { config(['app.url' => 'http://127.0.0.1:8000']); @@ -36,6 +41,11 @@ class LoginTest extends TestCase $response->assertStatus(200); } + /** + * Test for categories page + * + * @return void + */ public function testCategoriesPage() { $categoryUrlSlug = 'marvel-figurines'; @@ -47,6 +57,11 @@ class LoginTest extends TestCase $response->assertStatus(200); } + /** + * Test for customer registration page + * + * @return void + */ public function testCustomerRegistrationPage() { config(['app.url' => 'http://127.0.0.1:8000']); @@ -56,6 +71,11 @@ class LoginTest extends TestCase $response->assertStatus(200); } + /** + * Test for checkout's cart page + * + * @return void + */ public function testCartPage() { config(['app.url' => 'http://127.0.0.1:8000']); @@ -64,4 +84,4 @@ class LoginTest extends TestCase $response->assertStatus(200); } -} +} \ No newline at end of file