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
|
|
|
$order = new OrderTransaction(); |
18
|
|
|
$order->setFromAddress(new Address('9500 Gilman Drive', 'La Jolla', 'CA', '92093', 'US')); |
19
|
|
|
$order->setToAddress(new Address('1335 E 103rd St', 'Los Angeles', 'CA', '90002', 'US')); |
20
|
|
|
$order->addLineItem(new LineItem('1', 1, TaxCategory::CLOTHING, 15.00, 0.0)); |
21
|
|
|
$order->setAmount(15.0); |
22
|
|
|
$order->setShipping(1.5); |
23
|
|
|
|
24
|
|
|
return $order; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testTransactionData() |
28
|
|
|
{ |
29
|
|
|
$order = new OrderTransaction(); |
30
|
|
|
$order->setTransactionId('doge'); |
31
|
|
|
$this->assertEquals('doge', $order->getTransactionId()); |
32
|
|
|
$date = new \DateTime(); |
33
|
|
|
$order->setTransactionDate($date); |
34
|
|
|
$this->assertEquals($date, $order->getTransactionDate()); |
35
|
|
|
$order->setSalesTax(1.23); |
36
|
|
|
$this->assertEquals(1.23, $order->getSalesTax()); |
37
|
|
|
|
38
|
|
|
$this->assertEquals('doge', $order->toArray()['transaction_id']); |
39
|
|
|
$this->assertEquals($date->format(\DATE_ISO8601), $order->toArray()['transaction_date']); |
40
|
|
|
$this->assertEquals(1.23, $order->toArray()['sales_tax']); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testAddLineItem() |
44
|
|
|
{ |
45
|
|
|
$firstLineItem = new LineItem('1', 1, TaxCategory::CLOTHING, 15.00, 0.0); |
46
|
|
|
$firstLineItem->setDescription($expectedDescription = 'description_1'); |
47
|
|
|
$firstLineItem->setSalesTax($expectedSalesTax = 1.50); |
48
|
|
|
$firstLineItem->setProductIdentifier($expectedProductIdentifier = 'identifier_1'); |
49
|
|
|
|
50
|
|
|
$secondLineItem = new LineItem('2', 1, TaxCategory::CLOTHING, 16.00, 0.0); |
51
|
|
|
$secondLineItem->setDescription('description_2'); |
52
|
|
|
$secondLineItem->setSalesTax(1.60); |
53
|
|
|
$secondLineItem->setProductIdentifier('identifier_2'); |
54
|
|
|
$order = new OrderTransaction(); |
55
|
|
|
$order->addLineItem($firstLineItem); |
56
|
|
|
|
57
|
|
|
$this->assertCount(1, $order->getLineItems()); |
58
|
|
|
$this->assertContainsOnlyInstancesOf(LineItem::class, $order->getLineItems()); |
59
|
|
|
$this->assertEquals($expectedDescription, $order->getLineItems()[0]->getDescription()); |
60
|
|
|
$this->assertEquals($expectedSalesTax, $order->getLineItems()[0]->getSalesTax()); |
61
|
|
|
$this->assertEquals($expectedProductIdentifier, $order->getLineItems()[0]->getProductIdentifier()); |
62
|
|
|
|
63
|
|
|
$order->addLineItem($firstLineItem); |
64
|
|
|
$this->assertCount(2, $order->getLineItems()); |
65
|
|
|
$this->assertContainsOnlyInstancesOf(LineItem::class, $order->getLineItems()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testSetLineItem() |
69
|
|
|
{ |
70
|
|
|
$firstLineItem = new LineItem('1', 1, TaxCategory::CLOTHING, 15.00, 0.0); |
71
|
|
|
$firstLineItem->setDescription('description_1'); |
72
|
|
|
$firstLineItem->setSalesTax(1.50); |
73
|
|
|
$firstLineItem->setProductIdentifier('identifier_1'); |
74
|
|
|
|
75
|
|
|
$secondLineItem = new LineItem('2', 1, TaxCategory::CLOTHING, 16.00, 0.0); |
76
|
|
|
$secondLineItem->setDescription('description_2'); |
77
|
|
|
$secondLineItem->setSalesTax(1.60); |
78
|
|
|
$secondLineItem->setProductIdentifier('identifier_2'); |
79
|
|
|
|
80
|
|
|
$order = new OrderTransaction(); |
81
|
|
|
$order->setLineItems($expected = [$firstLineItem, $secondLineItem]); |
82
|
|
|
|
83
|
|
|
$this->assertCount(2, $order->getLineItems()); |
84
|
|
|
$this->assertContainsOnlyInstancesOf(LineItem::class, $order->getLineItems()); |
85
|
|
|
$this->assertEquals($expected, $order->getLineItems()); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|