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

LineItemFactoryTest::testFindOrMake()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 19
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 25
rs 9.6333
1
<?php
2
3
namespace SilverCommerce\OrdersAdmin\Tests;
4
5
use SilverStripe\Dev\SapphireTest;
6
use SilverCommerce\OrdersAdmin\Model\Estimate;
7
use SilverCommerce\OrdersAdmin\Factory\OrderFactory;
8
use SilverCommerce\TaxAdmin\Tests\Model\TestProduct;
9
use SilverCommerce\OrdersAdmin\Model\Invoice;
10
11
/**
12
 * Simple factory for creating line items that can be added to orders
13
 * or checked against existing items.
14
 */
15
class LineItemFactoryTest extends SapphireTest
16
{
17
    /**
18
     * Add some scaffold order records
19
     *
20
     * @var string
21
     */
22
    protected static $fixture_file = 'OrdersScaffold.yml';
23
24
    /**
25
     * Setup test only objects
26
     *
27
     * @var array
28
     */
29
    protected static $extra_dataobjects = [
30
        TestProduct::class
31
    ];
32
33
    public function testFindOrMake()
34
    {
35
        $existing = $this->objFromFixture(Estimate::class, 'addressdetails');
36
        $new_estimate = OrderFactory::create();
37
        $new_invoice = OrderFactory::create(true);
38
        $id = OrderFactory::create(false, $existing->ID);
39
        $ref = OrderFactory::create(false, null, '1232');
40
41
        $this->assertNotEmpty($new_estimate->getOrder());
42
        $this->assertEquals(Estimate::class, $new_estimate->getOrder()->ClassName);
43
        $this->assertFalse($new_estimate->getOrder()->exists());
44
        $this->assertEquals(0, $new_estimate->getOrder()->ID);
45
46
        $this->assertNotEmpty($new_invoice->getOrder());
47
        $this->assertEquals(Invoice::class, $new_invoice->getOrder()->ClassName);
48
        $this->assertFalse($new_invoice->getOrder()->exists());
49
        $this->assertEquals(0, $new_invoice->getOrder()->ID);
50
51
        $this->assertNotEmpty($id->getOrder());
52
        $this->assertTrue($id->getOrder()->exists());
53
        $this->assertEquals($existing->ID, $id->getOrder()->ID);
54
55
        $this->assertNotEmpty($ref->getOrder());
56
        $this->assertTrue($ref->getOrder()->exists());
57
        $this->assertEquals('1232', $ref->getOrder()->Ref);
58
    }
59
}
60