|
1 | 1 | <?php |
2 | 2 |
|
3 | 3 | use AlexWestergaard\PhpGa4\Analytics; |
| 4 | +use AlexWestergaard\PhpGa4\Event\Refund; |
4 | 5 | use AlexWestergaard\PhpGa4\Item; |
5 | 6 | use AlexWestergaard\PhpGa4\UserProperty; |
6 | 7 | use AlexWestergaard\PhpGa4\GA4Exception; |
@@ -104,6 +105,45 @@ public function testUserProperty() |
104 | 105 | $this->assertTrue($this->analytics->post()); |
105 | 106 | } |
106 | 107 |
|
| 108 | + public function testFullRefundNoItems() |
| 109 | + { |
| 110 | + $this->prepareSituation(); |
| 111 | + |
| 112 | + $refund = Refund::new()->setTransactionId(1)->isFullRefund(true); |
| 113 | + |
| 114 | + $this->analytics->addEvent($refund); |
| 115 | + |
| 116 | + $this->assertTrue($this->analytics->post()); |
| 117 | + } |
| 118 | + |
| 119 | + public function testPartialRefundWithItems() |
| 120 | + { |
| 121 | + $this->prepareSituation(); |
| 122 | + |
| 123 | + $refund = Refund::new()->setTransactionId(1)->addItem($this->item); |
| 124 | + |
| 125 | + $this->analytics->addEvent($refund); |
| 126 | + |
| 127 | + $arr = $this->analytics->toArray(); |
| 128 | + $this->assertTrue(is_array($arr)); |
| 129 | + |
| 130 | + $arr = $refund->toArray(); |
| 131 | + $this->assertArrayHasKey('params', $arr); |
| 132 | + $arr = $arr['params']; |
| 133 | + $this->assertArrayHasKey('items', $arr); |
| 134 | + } |
| 135 | + |
| 136 | + public function testPartialRefundNoItemsThrows() |
| 137 | + { |
| 138 | + $this->prepareSituation(); |
| 139 | + |
| 140 | + $refund = Refund::new()->setTransactionId(1); |
| 141 | + |
| 142 | + $this->expectException(GA4Exception::class); |
| 143 | + |
| 144 | + $this->analytics->addEvent($refund); |
| 145 | + } |
| 146 | + |
107 | 147 | public function testPrebuildEvents() |
108 | 148 | { |
109 | 149 | $this->prepareSituation(); |
|
0 commit comments