fixed #452
This commit is contained in:
parent
c706f7c8b0
commit
17c52e1c5b
@ -4,7 +4,6 @@ namespace Database\Seeds;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Models\Setting\Tax;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class Taxes extends Seeder
|
||||
|
@ -10,8 +10,7 @@ class ItemsTest extends FeatureTestCase
|
||||
{
|
||||
public function testItShouldBeShowTheItemsPage()
|
||||
{
|
||||
$this
|
||||
->loginAs()
|
||||
$this->loginAs()
|
||||
->get(route('items.index'))
|
||||
->assertStatus(200)
|
||||
->assertSee('Items');
|
||||
@ -19,18 +18,50 @@ class ItemsTest extends FeatureTestCase
|
||||
|
||||
public function testItShouldBeShowCreateItemPage()
|
||||
{
|
||||
$this
|
||||
->loginAs()
|
||||
$this->loginAs()
|
||||
->get(route('items.create'))
|
||||
->assertStatus(200)
|
||||
->assertSee('New Item');
|
||||
}
|
||||
|
||||
public function testItShouldStoreAnItem()
|
||||
{
|
||||
$this->loginAs()
|
||||
->post(route('items.store'), $this->getItemRequest())
|
||||
->assertStatus(302)
|
||||
->assertRedirect(route('items.index'));
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
public function testItShouldEditItem()
|
||||
{
|
||||
$item = Item::create($this->getItemRequest());
|
||||
|
||||
$this->loginAs()
|
||||
->get(route('items.edit', ['item' => $item->id]))
|
||||
->assertStatus(200)
|
||||
->assertSee($item->name);
|
||||
}
|
||||
|
||||
public function testItShouldDeleteItem()
|
||||
{
|
||||
$item = factory(Item::class)->create();
|
||||
|
||||
$this->loginAs()
|
||||
->delete(route('items.destroy', ['item' => $item]))
|
||||
->assertStatus(302)
|
||||
->assertRedirect(route('items.index'));
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
private function getItemRequest()
|
||||
{
|
||||
$picture = UploadedFile::fake()->create('image.jpg');
|
||||
|
||||
$item = [
|
||||
return [
|
||||
'company_id' => $this->company->id,
|
||||
'name' => $this->faker->title,
|
||||
'sku' => $this->faker->languageCode,
|
||||
'picture' => $picture,
|
||||
@ -42,36 +73,5 @@ class ItemsTest extends FeatureTestCase
|
||||
'tax_id' => $this->company->taxes()->first()->id,
|
||||
'enabled' => $this->faker->boolean ? 1 : 0
|
||||
];
|
||||
|
||||
$this
|
||||
->loginAs()
|
||||
->post(route('items.store'), $item)
|
||||
->assertStatus(302)
|
||||
->assertRedirect(route('items.index'));
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
public function testItShouldEditItem()
|
||||
{
|
||||
$item = factory(Item::class)->create();
|
||||
|
||||
$this
|
||||
->loginAs()
|
||||
->get(route('items.edit', ['item' => $item]))
|
||||
->assertStatus(200)
|
||||
->assertSee($item->name);
|
||||
}
|
||||
|
||||
public function testItShouldDeleteItem()
|
||||
{
|
||||
$item = factory(Item::class)->create();
|
||||
|
||||
$this
|
||||
->loginAs()
|
||||
->delete(route('items.destroy', ['item' => $item]))
|
||||
->assertStatus(302)
|
||||
->assertRedirect(route('items.index'));
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
}
|
@ -1,14 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: bgure
|
||||
* Date: 13.07.2018
|
||||
* Time: 19:44
|
||||
*/
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\Common\Company;
|
||||
use Faker\Factory;
|
||||
@ -30,6 +23,7 @@ abstract class FeatureTestCase extends TestCase
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->faker = Factory::create();
|
||||
$this->user = User::first();
|
||||
$this->company = $this->user->first()->companies()->first();
|
||||
@ -44,18 +38,24 @@ abstract class FeatureTestCase extends TestCase
|
||||
*/
|
||||
public function loginAs(User $user = null, Company $company = null)
|
||||
{
|
||||
if(!$user) $user = $this->user;
|
||||
if(!$company) $company = $user->companies()->first();
|
||||
if (!$user) {
|
||||
$user = $this->user;
|
||||
}
|
||||
|
||||
if (!$company) {
|
||||
$company = $user->companies()->first();
|
||||
}
|
||||
|
||||
$this->startSession();
|
||||
return $this->actingAs($user)
|
||||
->withSession(['company_id' => $company->id]);
|
||||
|
||||
return $this->actingAs($user)->withSession(['company_id' => $company->id]);
|
||||
}
|
||||
|
||||
public function assertFlashLevel($excepted)
|
||||
{
|
||||
$flash["level"] = null;
|
||||
if($flashMessage = session('flash_notification'))
|
||||
{
|
||||
$flash['level'] = null;
|
||||
|
||||
if ($flashMessage = session('flash_notification')) {
|
||||
$flash = $flashMessage->first();
|
||||
}
|
||||
|
||||
|
@ -10,42 +10,46 @@ class CustomersTest extends FeatureTestCase
|
||||
{
|
||||
public function testItShouldCreateOnlyCustomerWithoutUser()
|
||||
{
|
||||
$customer = $this->getCustomerData();
|
||||
$this->loginAs()
|
||||
->post(route("customers.store"), $customer)
|
||||
->post(route('customers.store'), $this->getCustomerRequest())
|
||||
->assertStatus(302)
|
||||
->assertRedirect(route("customers.index"));
|
||||
$this->assertFlashLevel("success");
|
||||
->assertRedirect(route('customers.index'));
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
public function testItShouldCreateCustomerWithUser()
|
||||
{
|
||||
$customerWithUser = $this->getCustomerDataWithUser();
|
||||
$customer = $this->getCustomerRequestWithUser();
|
||||
|
||||
$this->loginAs()
|
||||
->post(route("customers.store"), $customerWithUser)
|
||||
->post(route('customers.store'), $customer)
|
||||
->assertStatus(302)
|
||||
->assertRedirect(route("customers.index"));
|
||||
$this->assertFlashLevel("success");
|
||||
->assertRedirect(route('customers.index'));
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
|
||||
$user = User::where('email', $customer['email'])->first();
|
||||
|
||||
$user = User::where("email", $customerWithUser["email"])->first();
|
||||
$this->assertNotNull($user);
|
||||
$this->assertEquals($customerWithUser["email"], $user->email);
|
||||
$this->assertEquals($customer['email'], $user->email);
|
||||
}
|
||||
|
||||
public function testItShouldNotCreateCustomerWithExistsUser()
|
||||
{
|
||||
$customerWithUser = $this->getCustomerDataWithUser();
|
||||
User::create($customerWithUser);
|
||||
$customer = $this->getCustomerRequestWithUser();
|
||||
|
||||
User::create($customer);
|
||||
|
||||
$this->loginAs()
|
||||
->post(route('customers.store'), $customerWithUser)
|
||||
->post(route('customers.store'), $customer)
|
||||
->assertSessionHasErrors(['email']);
|
||||
}
|
||||
|
||||
public function testItShouldBeSeeTheCustomersPage()
|
||||
{
|
||||
$customer = Customer::create($this->getCustomerData());
|
||||
$customer = Customer::create($this->getCustomerRequest());
|
||||
|
||||
$this
|
||||
->loginAs()
|
||||
->get(route('customers.index'))
|
||||
@ -55,7 +59,8 @@ class CustomersTest extends FeatureTestCase
|
||||
|
||||
public function testItShouldBeSeeTheEditCustomersPage()
|
||||
{
|
||||
$customer = Customer::create($this->getCustomerData());
|
||||
$customer = Customer::create($this->getCustomerRequest());
|
||||
|
||||
$this
|
||||
->loginAs()
|
||||
->get(route('customers.edit', ['customer' => $customer->id]))
|
||||
@ -66,21 +71,24 @@ class CustomersTest extends FeatureTestCase
|
||||
|
||||
public function testItShouldUpdateTheCustomer()
|
||||
{
|
||||
$customerData = $this->getCustomerData();
|
||||
$customer = Customer::create($customerData);
|
||||
$customerData["name"] = $this->faker->name;
|
||||
$request = $this->getCustomerRequest();
|
||||
|
||||
$customer = Customer::create($request);
|
||||
|
||||
$request['name'] = $this->faker->name;
|
||||
|
||||
$this
|
||||
->loginAs()
|
||||
->patch(route('customers.update', $customer->id), $customerData)
|
||||
->patch(route('customers.update', $customer->id), $request)
|
||||
->assertStatus(302)
|
||||
->assertRedirect(route('customers.index'));
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
public function testItShouldDeleteTheCustomer()
|
||||
{
|
||||
$customer = Customer::create($this->getCustomerData());
|
||||
$customer = Customer::create($this->getCustomerRequest());
|
||||
|
||||
$this->loginAs()
|
||||
->delete(route('customers.destroy', $customer->id))
|
||||
@ -97,8 +105,7 @@ class CustomersTest extends FeatureTestCase
|
||||
//TODO : This will write after done invoice and revenues tests.
|
||||
}
|
||||
|
||||
// Helpers
|
||||
private function getCustomerData()
|
||||
private function getCustomerRequest()
|
||||
{
|
||||
return [
|
||||
'company_id' => $this->company->id,
|
||||
@ -113,11 +120,11 @@ class CustomersTest extends FeatureTestCase
|
||||
];
|
||||
}
|
||||
|
||||
private function getCustomerDataWithUser()
|
||||
private function getCustomerRequestWithUser()
|
||||
{
|
||||
$password = $this->faker->password;
|
||||
|
||||
return $this->getCustomerData() + [
|
||||
return $this->getCustomerRequest() + [
|
||||
'create_user' => 1,
|
||||
'locale' => 'en-GB',
|
||||
'password' => $password,
|
||||
|
@ -2,19 +2,9 @@
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
use CreatesApplication, DatabaseMigrations;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Artisan::call('db:seed', ['--class' => '\Database\Seeds\TestCompany', '--force' => true]);
|
||||
Artisan::call('company:seed',['company' => 1]);
|
||||
}
|
||||
use CreatesApplication;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user