2019-01-14 09:16:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
|
|
use Auth;
|
2019-02-23 10:43:24 +00:00
|
|
|
use Crypt;
|
2019-01-14 09:16:18 +00:00
|
|
|
|
|
|
|
|
use App;
|
|
|
|
|
use Faker\Generator as Faker;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
|
use Webkul\Customer\Repositories\CustomerRepository as Customer;
|
|
|
|
|
|
|
|
|
|
class AuthTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
protected $customer;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* To check if the customer can view the login page or not
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function testCustomerLoginPage()
|
|
|
|
|
{
|
|
|
|
|
config(['app.url' => '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([
|
2019-02-23 10:43:24 +00:00
|
|
|
'first_name' => explode(' ', $faker->name)[0],
|
|
|
|
|
'last_name' => explode(' ', $faker->name)[0],
|
2019-01-14 09:16:18 +00:00
|
|
|
'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() {
|
2019-02-23 10:43:24 +00:00
|
|
|
config(['app.url' => 'http://127.0.0.1:8000']);
|
|
|
|
|
|
2019-01-14 09:16:18 +00:00
|
|
|
$customers = app(Customer::class);
|
|
|
|
|
|
2019-02-23 10:43:24 +00:00
|
|
|
$customer = $customers->findOneByField('email', 'prashant@webkul.com');
|
|
|
|
|
|
|
|
|
|
$response = $this->post('/customer/login', [
|
|
|
|
|
'email' => $customer->email,
|
|
|
|
|
'password' => '12345678'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertRedirect('/customer/account/profile');
|
2019-01-14 09:16:18 +00:00
|
|
|
|
2019-02-23 10:43:24 +00:00
|
|
|
$this->assertEquals(count([auth()->guard('customer')->user()]), 1);
|
2019-01-14 09:16:18 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|