Completed
Branch 1.3 (ca63b5)
by Morven
03:44
created

OrderFactoryTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 43
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A testFindOrMake() 0 25 1
1
<?php
2
3
namespace SilverCommerce\OrdersAdmin\Tests;
4
5
use SilverStripe\Dev\SapphireTest;
6
use SilverCommerce\OrdersAdmin\Model\Invoice;
7
use SilverCommerce\OrdersAdmin\Model\Estimate;
8
use SilverCommerce\OrdersAdmin\Factory\OrderFactory;
9
use SilverCommerce\TaxAdmin\Tests\Model\TestProduct;
10
11
class OrderFactoryTest extends SapphireTest
12
{
13
    /**
14
     * Add some scaffold order records
15
     *
16
     * @var string
17
     */
18
    protected static $fixture_file = 'OrdersScaffold.yml';
19
20
    /**
21
     * Setup test only objects
22
     *
23
     * @var array
24
     */
25
    protected static $extra_dataobjects = [
26
        TestProduct::class
27
    ];
28
29
    public function testFindOrMake()
30
    {
31
        $existing = $this->objFromFixture(Estimate::class, 'addressdetails');
32
        $new_estimate = OrderFactory::create();
33
        $new_invoice = OrderFactory::create(true);
34
        $id = OrderFactory::create(false, $existing->ID);
35
        $ref = OrderFactory::create(false, null, '1232');
36
37
        $this->assertNotEmpty($new_estimate->getOrder());
38
        $this->assertEquals(Estimate::class, $new_estimate->getOrder()->ClassName);
39
        $this->assertFalse($new_estimate->getOrder()->exists());
40
        $this->assertEquals(0, $new_estimate->getOrder()->ID);
41
42
        $this->assertNotEmpty($new_invoice->getOrder());
43
        $this->assertEquals(Invoice::class, $new_invoice->getOrder()->ClassName);
44
        $this->assertFalse($new_invoice->getOrder()->exists());
45
        $this->assertEquals(0, $new_invoice->getOrder()->ID);
46
47
        $this->assertNotEmpty($id->getOrder());
48
        $this->assertTrue($id->getOrder()->exists());
49
        $this->assertEquals($existing->ID, $id->getOrder()->ID);
50
51
        $this->assertNotEmpty($ref->getOrder());
52
        $this->assertTrue($ref->getOrder()->exists());
53
        $this->assertEquals('1232', $ref->getOrder()->Ref);
54
    }
55
}
56