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