2019-04-26 12:51:02 +02:00
|
|
|
<?php
|
2020-09-14 13:11:46 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2019-04-26 12:51:02 +02:00
|
|
|
namespace Tests\Unit;
|
|
|
|
|
2019-04-26 13:02:52 +02:00
|
|
|
use App\Factory\ClientContactFactory;
|
|
|
|
use App\Factory\ClientFactory;
|
2019-04-26 13:18:23 +02:00
|
|
|
use App\Factory\CloneInvoiceFactory;
|
|
|
|
use App\Factory\InvoiceFactory;
|
|
|
|
use App\Factory\ProductFactory;
|
2019-04-26 12:51:02 +02:00
|
|
|
use App\Factory\UserFactory;
|
2019-04-26 13:02:52 +02:00
|
|
|
use App\Models\Client;
|
2019-11-20 06:41:49 +01:00
|
|
|
use App\Models\User;
|
2019-04-26 12:51:02 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2019-04-26 13:02:52 +02:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2019-04-26 12:51:02 +02:00
|
|
|
use Illuminate\Support\Facades\Session;
|
2019-11-20 06:41:49 +01:00
|
|
|
use Tests\MockAccountData;
|
2019-04-26 12:51:02 +02:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
class FactoryCreationTest extends TestCase
|
|
|
|
{
|
|
|
|
use MakesHash;
|
2019-04-26 13:02:52 +02:00
|
|
|
use DatabaseTransactions;
|
2019-11-20 06:41:49 +01:00
|
|
|
use MockAccountData;
|
2019-04-26 12:51:02 +02:00
|
|
|
|
|
|
|
public function setUp() :void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-04-26 12:51:02 +02:00
|
|
|
Session::start();
|
|
|
|
|
|
|
|
$this->faker = \Faker\Factory::create();
|
|
|
|
|
|
|
|
Model::reguard();
|
|
|
|
|
2019-11-20 06:41:49 +01:00
|
|
|
$this->makeTestData();
|
2019-04-26 13:02:52 +02:00
|
|
|
}
|
|
|
|
|
2019-04-26 13:18:23 +02:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @covers App\Factory\ProductFactory
|
|
|
|
*/
|
|
|
|
public function testProductionCreation()
|
|
|
|
{
|
|
|
|
$product = ProductFactory::create($this->company->id, $this->user->id);
|
|
|
|
$product->save();
|
|
|
|
|
|
|
|
$this->assertNotNull($product);
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->assertIsInt($product->id);
|
2019-04-26 13:18:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @covers App\Factory\InvoiceFactory
|
|
|
|
*/
|
|
|
|
public function testInvoiceCreation()
|
|
|
|
{
|
|
|
|
$client = ClientFactory::create($this->company->id, $this->user->id);
|
|
|
|
|
|
|
|
$client->save();
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
|
2019-04-26 13:18:23 +02:00
|
|
|
$invoice->client_id = $client->id;
|
|
|
|
$invoice->save();
|
|
|
|
|
|
|
|
$this->assertNotNull($invoice);
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->assertIsInt($invoice->id);
|
2019-04-26 13:18:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
2019-05-03 10:34:27 +02:00
|
|
|
* @covers App\Factory\CloneInvoiceFactory
|
2019-04-26 13:18:23 +02:00
|
|
|
*/
|
|
|
|
public function testCloneInvoiceCreation()
|
|
|
|
{
|
|
|
|
$client = ClientFactory::create($this->company->id, $this->user->id);
|
|
|
|
|
|
|
|
$client->save();
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
|
2019-04-26 13:18:23 +02:00
|
|
|
$invoice->client_id = $client->id;
|
|
|
|
$invoice->save();
|
|
|
|
|
|
|
|
$this->assertNotNull($invoice);
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->assertIsInt($invoice->id);
|
2019-04-26 13:18:23 +02:00
|
|
|
|
|
|
|
$clone = CloneInvoiceFactory::create($invoice, $this->user->id);
|
|
|
|
$clone->save();
|
|
|
|
|
|
|
|
$this->assertNotNull($clone);
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->assertIsInt($clone->id);
|
2019-04-26 13:18:23 +02:00
|
|
|
}
|
|
|
|
|
2019-04-26 13:02:52 +02:00
|
|
|
/**
|
|
|
|
* @test
|
2019-05-03 10:34:27 +02:00
|
|
|
* @covers App\Factory\ClientFactory
|
2019-04-26 13:02:52 +02:00
|
|
|
*/
|
|
|
|
public function testClientCreate()
|
|
|
|
{
|
2019-11-20 06:41:49 +01:00
|
|
|
$cliz = ClientFactory::create($this->company->id, $this->user->id);
|
2019-04-26 13:02:52 +02:00
|
|
|
|
2019-11-20 06:41:49 +01:00
|
|
|
$cliz->save();
|
2019-04-26 13:02:52 +02:00
|
|
|
|
2019-11-20 06:41:49 +01:00
|
|
|
$this->assertNotNull($cliz);
|
2019-04-26 13:02:52 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->assertIsInt($cliz->id);
|
2019-04-26 13:02:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
2019-05-03 10:34:27 +02:00
|
|
|
* @covers App\Factory\ClientContactFactory
|
2019-04-26 13:02:52 +02:00
|
|
|
*/
|
|
|
|
public function testClientContactCreate()
|
|
|
|
{
|
2019-11-20 06:41:49 +01:00
|
|
|
$cliz = ClientFactory::create($this->company->id, $this->user->id);
|
2019-04-26 13:02:52 +02:00
|
|
|
|
2019-11-20 06:41:49 +01:00
|
|
|
$cliz->save();
|
2019-04-26 13:02:52 +02:00
|
|
|
|
2019-11-20 06:41:49 +01:00
|
|
|
$this->assertNotNull($cliz->contacts);
|
2020-07-28 10:28:29 +02:00
|
|
|
$this->assertEquals(0, $cliz->contacts->count());
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->assertIsInt($cliz->id);
|
2019-04-26 12:51:02 +02:00
|
|
|
}
|
|
|
|
|
2019-04-26 13:02:52 +02:00
|
|
|
/**
|
|
|
|
* @test
|
2019-05-03 10:34:27 +02:00
|
|
|
* @covers App\Factory\UserFactory
|
2019-04-26 13:02:52 +02:00
|
|
|
*/
|
2019-04-26 12:51:02 +02:00
|
|
|
public function testUserCreate()
|
|
|
|
{
|
2020-03-24 10:15:30 +01:00
|
|
|
$new_user = UserFactory::create($this->account->id);
|
2020-10-12 23:27:42 +02:00
|
|
|
$new_user->email = $this->faker->freeEmail;
|
2019-04-26 12:51:02 +02:00
|
|
|
$new_user->save();
|
|
|
|
|
|
|
|
$this->assertNotNull($new_user);
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->assertIsInt($new_user->id);
|
2019-04-26 12:51:02 +02:00
|
|
|
}
|
|
|
|
}
|