1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LAShowroom\TaxJarBundle\Tests\Model\Transaction; |
4
|
|
|
|
5
|
|
|
use LAShowroom\TaxJarBundle\Model\Address; |
6
|
|
|
use LAShowroom\TaxJarBundle\Model\TaxCategory; |
7
|
|
|
use LAShowroom\TaxJarBundle\Model\Transaction\LineItem; |
8
|
|
|
use LAShowroom\TaxJarBundle\Model\Transaction\OrderTransaction; |
9
|
|
|
|
10
|
|
|
class OrderTransactionTest extends \PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @return OrderTransaction |
14
|
|
|
*/ |
15
|
|
|
public static function getTestOrderTransaction() |
16
|
|
|
{ |
17
|
|
|
$lineItem1 = new LineItem('1', 1, TaxCategory::CLOTHING, 15.00, 0.0); |
18
|
|
|
$lineItem1->setDescription('Description 1'); |
19
|
|
|
$lineItem1->setProductIdentifier('Identifier 1'); |
20
|
|
|
$lineItem1->setSalesTax(1.20); |
21
|
|
|
|
22
|
|
|
$order = new OrderTransaction(); |
23
|
|
|
$order->setFromAddress(new Address('9500 Gilman Drive', 'La Jolla', 'CA', '92093', 'US')); |
24
|
|
|
$order->setToAddress(new Address('1335 E 103rd St', 'Los Angeles', 'CA', '90002', 'US')); |
25
|
|
|
$order->addLineItem($lineItem1); |
26
|
|
|
$order->setAmount(15.0); |
27
|
|
|
$order->setShipping(1.5); |
28
|
|
|
|
29
|
|
|
return $order; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testTransactionData() |
33
|
|
|
{ |
34
|
|
|
$order = new OrderTransaction(); |
35
|
|
|
$order->setTransactionId('doge'); |
36
|
|
|
$this->assertEquals('doge', $order->getTransactionId()); |
37
|
|
|
$date = new \DateTime(); |
38
|
|
|
$order->setTransactionDate($date); |
39
|
|
|
$this->assertEquals($date, $order->getTransactionDate()); |
40
|
|
|
$order->setSalesTax(1.23); |
41
|
|
|
$this->assertEquals(1.23, $order->getSalesTax()); |
42
|
|
|
|
43
|
|
|
$this->assertEquals('doge', $order->toArray()['transaction_id']); |
44
|
|
|
$this->assertEquals($date->format(\DATE_ISO8601), $order->toArray()['transaction_date']); |
45
|
|
|
$this->assertEquals(1.23, $order->toArray()['sales_tax']); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testAddLineItem() |
49
|
|
|
{ |
50
|
|
|
$firstLineItem = new LineItem('1', 1, TaxCategory::CLOTHING, 15.00, 0.0); |
51
|
|
|
$firstLineItem->setDescription($expectedDescription = 'description_1'); |
52
|
|
|
$firstLineItem->setSalesTax($expectedSalesTax = 1.50); |
53
|
|
|
$firstLineItem->setProductIdentifier($expectedProductIdentifier = 'identifier_1'); |
54
|
|
|
|
55
|
|
|
$secondLineItem = new LineItem('2', 1, TaxCategory::CLOTHING, 16.00, 0.0); |
56
|
|
|
$secondLineItem->setDescription('description_2'); |
57
|
|
|
$secondLineItem->setSalesTax(1.60); |
58
|
|
|
$secondLineItem->setProductIdentifier('identifier_2'); |
59
|
|
|
$order = new OrderTransaction(); |
60
|
|
|
$order->addLineItem($firstLineItem); |
61
|
|
|
|
62
|
|
|
$this->assertCount(1, $order->getLineItems()); |
63
|
|
|
$this->assertContainsOnlyInstancesOf(LineItem::class, $order->getLineItems()); |
64
|
|
|
$this->assertEquals($expectedDescription, $order->getLineItems()[0]->getDescription()); |
65
|
|
|
$this->assertEquals($expectedSalesTax, $order->getLineItems()[0]->getSalesTax()); |
66
|
|
|
$this->assertEquals($expectedProductIdentifier, $order->getLineItems()[0]->getProductIdentifier()); |
67
|
|
|
|
68
|
|
|
$order->addLineItem($firstLineItem); |
69
|
|
|
$this->assertCount(2, $order->getLineItems()); |
70
|
|
|
$this->assertContainsOnlyInstancesOf(LineItem::class, $order->getLineItems()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testSetLineItem() |
74
|
|
|
{ |
75
|
|
|
$firstLineItem = new LineItem('1', 1, TaxCategory::CLOTHING, 15.00, 0.0); |
76
|
|
|
$firstLineItem->setDescription('description_1'); |
77
|
|
|
$firstLineItem->setSalesTax(1.50); |
78
|
|
|
$firstLineItem->setProductIdentifier('identifier_1'); |
79
|
|
|
|
80
|
|
|
$secondLineItem = new LineItem('2', 1, TaxCategory::CLOTHING, 16.00, 0.0); |
81
|
|
|
$secondLineItem->setDescription('description_2'); |
82
|
|
|
$secondLineItem->setSalesTax(1.60); |
83
|
|
|
$secondLineItem->setProductIdentifier('identifier_2'); |
84
|
|
|
|
85
|
|
|
$order = new OrderTransaction(); |
86
|
|
|
$order->setLineItems($expected = [$firstLineItem, $secondLineItem]); |
87
|
|
|
|
88
|
|
|
$this->assertCount(2, $order->getLineItems()); |
89
|
|
|
$this->assertContainsOnlyInstancesOf(LineItem::class, $order->getLineItems()); |
90
|
|
|
$this->assertEquals($expected, $order->getLineItems()); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|