| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Tests\Module; |
| 6 |
|
| 7 |
use Packetery\Core\Entity\Order; |
| 8 |
use Packetery\Core\Entity\PickupPoint; |
| 9 |
use Packetery\Module\Email\EmailShortcodes; |
| 10 |
use Packetery\Module\Framework\WpAdapter; |
| 11 |
use Packetery\Module\Order\Repository; |
| 12 |
use PHPUnit\Framework\TestCase; |
| 13 |
use Tests\Core\DummyFactory; |
| 14 |
|
| 15 |
class EmailShortcodesTest extends TestCase { |
| 16 |
private const DUMMY_PROCESSED_CONTENT = 'processed_content'; |
| 17 |
private const DUMMY_CONTENT = 'content'; |
| 18 |
private const DUMMY_INVALID_VALUE = 'invalid'; |
| 19 |
|
| 20 |
private WpAdapter $wpAdapterMock; |
| 21 |
private Repository $orderRepositoryMock; |
| 22 |
private EmailShortcodes $shortcodes; |
| 23 |
|
| 24 |
private function createShortcodes(): EmailShortcodes { |
| 25 |
$this->wpAdapterMock = $this->createMock( WpAdapter::class ); |
| 26 |
$this->orderRepositoryMock = $this->createMock( Repository::class ); |
| 27 |
|
| 28 |
return new EmailShortcodes( $this->wpAdapterMock, $this->orderRepositoryMock ); |
| 29 |
} |
| 30 |
|
| 31 |
public static function providerIfPickupPoint(): array { |
| 32 |
return [ |
| 33 |
'no order' => [ |
| 34 |
'order' => null, |
| 35 |
'pickupPoint' => null, |
| 36 |
'expected' => '', |
| 37 |
], |
| 38 |
'no pickup point' => [ |
| 39 |
'order' => DummyFactory::createOrderCzHdIncomplete(), |
| 40 |
'pickupPoint' => null, |
| 41 |
'expected' => '', |
| 42 |
], |
| 43 |
'with pickup point' => [ |
| 44 |
'order' => DummyFactory::createOrderCzHdIncomplete(), |
| 45 |
'pickupPoint' => DummyFactory::createPickupPoint(), |
| 46 |
'expected' => self::DUMMY_PROCESSED_CONTENT, |
| 47 |
], |
| 48 |
]; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* @dataProvider providerIfPickupPoint |
| 53 |
*/ |
| 54 |
public function testIfPickupPoint( |
| 55 |
?Order $order, |
| 56 |
?PickupPoint $pickupPoint, |
| 57 |
string $expected |
| 58 |
): void { |
| 59 |
$this->shortcodes = $this->createShortcodes(); |
| 60 |
|
| 61 |
if ( $pickupPoint !== null && $order !== null ) { |
| 62 |
$order->setPickupPoint( $pickupPoint ); |
| 63 |
} |
| 64 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 65 |
$this->wpAdapterMock->method( 'doShortcode' )->willReturn( $expected ); |
| 66 |
|
| 67 |
$result = $this->shortcodes->ifPickupPoint( [ 'order_id' => 123 ], self::DUMMY_CONTENT ); |
| 68 |
$this->assertSame( $expected, $result ); |
| 69 |
} |
| 70 |
|
| 71 |
public function testIfExternalCarrierReturnsEmptyWhenNoOrder(): void { |
| 72 |
$this->shortcodes = $this->createShortcodes(); |
| 73 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( null ); |
| 74 |
$result = $this->shortcodes->ifExternalCarrier( [ 'order_id' => 123 ], self::DUMMY_CONTENT ); |
| 75 |
$this->assertSame( '', $result ); |
| 76 |
} |
| 77 |
|
| 78 |
public function testIfExternalCarrierReturnsEmptyWhenNotExternalCarrier(): void { |
| 79 |
$this->shortcodes = $this->createShortcodes(); |
| 80 |
$carrier = DummyFactory::createCarrierCzechPp(); |
| 81 |
$order = new Order( 'orderNumber', $carrier ); |
| 82 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 83 |
$result = $this->shortcodes->ifExternalCarrier( [ 'order_id' => 123 ], self::DUMMY_CONTENT ); |
| 84 |
$this->assertSame( '', $result ); |
| 85 |
} |
| 86 |
|
| 87 |
public function testIfExternalCarrierReturnsContentWhenExternalCarrier(): void { |
| 88 |
$this->shortcodes = $this->createShortcodes(); |
| 89 |
$carrier = DummyFactory::createCarDeliveryCarrier(); |
| 90 |
$order = new Order( 'orderNumber', $carrier ); |
| 91 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 92 |
$this->wpAdapterMock->method( 'doShortcode' )->willReturn( self::DUMMY_PROCESSED_CONTENT ); |
| 93 |
$result = $this->shortcodes->ifExternalCarrier( [ 'order_id' => 123 ], self::DUMMY_CONTENT ); |
| 94 |
$this->assertSame( self::DUMMY_PROCESSED_CONTENT, $result ); |
| 95 |
} |
| 96 |
|
| 97 |
public function testPickupPointAddressReturnsEmptyWhenNoOrder(): void { |
| 98 |
$this->shortcodes = $this->createShortcodes(); |
| 99 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( null ); |
| 100 |
$result = $this->shortcodes->pickupPointAddress( [ 'order_id' => 123 ] ); |
| 101 |
$this->assertSame( '', $result ); |
| 102 |
} |
| 103 |
|
| 104 |
public function testPickupPointAddressReturnsEmptyWhenNoPickupPoint(): void { |
| 105 |
$this->shortcodes = $this->createShortcodes(); |
| 106 |
$order = DummyFactory::createOrderCzHdIncomplete(); |
| 107 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 108 |
$result = $this->shortcodes->pickupPointAddress( [ 'order_id' => 123 ] ); |
| 109 |
$this->assertSame( '', $result ); |
| 110 |
} |
| 111 |
|
| 112 |
public static function providerPickupPointAddress(): array { |
| 113 |
return [ |
| 114 |
'no order' => [ |
| 115 |
'order' => null, |
| 116 |
'pickupPoint' => null, |
| 117 |
'expected' => '', |
| 118 |
], |
| 119 |
'no pickup point' => [ |
| 120 |
'order' => DummyFactory::createOrderCzHdIncomplete(), |
| 121 |
'pickupPoint' => null, |
| 122 |
'expected' => '', |
| 123 |
], |
| 124 |
'with pickup point' => [ |
| 125 |
'order' => DummyFactory::createOrderCzHdIncomplete(), |
| 126 |
'pickupPoint' => DummyFactory::createPickupPoint(), |
| 127 |
'expected' => DummyFactory::createPickupPoint()->getFullAddress(), |
| 128 |
], |
| 129 |
]; |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* @dataProvider providerPickupPointAddress |
| 134 |
*/ |
| 135 |
public function testPickupPointAddress( ?Order $order, ?PickupPoint $pickupPoint, string $expected ): void { |
| 136 |
$this->shortcodes = $this->createShortcodes(); |
| 137 |
if ( $pickupPoint !== null && $order !== null ) { |
| 138 |
$order->setPickupPoint( $pickupPoint ); |
| 139 |
} |
| 140 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 141 |
$result = $this->shortcodes->pickupPointAddress( [ 'order_id' => 123 ] ); |
| 142 |
$this->assertSame( $expected, $result ); |
| 143 |
} |
| 144 |
|
| 145 |
public function testPickupPointStreetReturnsEmptyWhenNoOrder(): void { |
| 146 |
$this->shortcodes = $this->createShortcodes(); |
| 147 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( null ); |
| 148 |
$result = $this->shortcodes->pickupPointStreet( [ 'order_id' => 123 ] ); |
| 149 |
$this->assertSame( '', $result ); |
| 150 |
} |
| 151 |
|
| 152 |
public function testPickupPointStreetReturnsEmptyWhenNoPickupPoint(): void { |
| 153 |
$this->shortcodes = $this->createShortcodes(); |
| 154 |
$order = DummyFactory::createOrderCzHdIncomplete(); |
| 155 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 156 |
$result = $this->shortcodes->pickupPointStreet( [ 'order_id' => 123 ] ); |
| 157 |
$this->assertSame( '', $result ); |
| 158 |
} |
| 159 |
|
| 160 |
public static function providerPickupPointStreet(): array { |
| 161 |
return [ |
| 162 |
'no order' => [ |
| 163 |
'order' => null, |
| 164 |
'pickupPoint' => null, |
| 165 |
'expected' => '', |
| 166 |
], |
| 167 |
'no pickup point' => [ |
| 168 |
'order' => DummyFactory::createOrderCzHdIncomplete(), |
| 169 |
'pickupPoint' => null, |
| 170 |
'expected' => '', |
| 171 |
], |
| 172 |
'with pickup point' => [ |
| 173 |
'order' => DummyFactory::createOrderCzHdIncomplete(), |
| 174 |
'pickupPoint' => DummyFactory::createPickupPoint(), |
| 175 |
'expected' => DummyFactory::createPickupPoint()->getStreet(), |
| 176 |
], |
| 177 |
]; |
| 178 |
} |
| 179 |
|
| 180 |
/** |
| 181 |
* @dataProvider providerPickupPointStreet |
| 182 |
*/ |
| 183 |
public function testPickupPointStreet( ?Order $order, ?PickupPoint $pickupPoint, string $expected ): void { |
| 184 |
$this->shortcodes = $this->createShortcodes(); |
| 185 |
if ( $pickupPoint !== null && $order !== null ) { |
| 186 |
$order->setPickupPoint( $pickupPoint ); |
| 187 |
} |
| 188 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 189 |
$result = $this->shortcodes->pickupPointStreet( [ 'order_id' => 123 ] ); |
| 190 |
$this->assertSame( $expected, $result ); |
| 191 |
} |
| 192 |
|
| 193 |
public function testPickupPointCountryReturnsEmptyWhenNoOrder(): void { |
| 194 |
$this->shortcodes = $this->createShortcodes(); |
| 195 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( null ); |
| 196 |
$result = $this->shortcodes->pickupPointCountry( [ 'order_id' => 123 ] ); |
| 197 |
$this->assertSame( '', $result ); |
| 198 |
} |
| 199 |
|
| 200 |
public function testPickupPointCountryReturnsEmptyWhenNoPickupPoint(): void { |
| 201 |
$this->shortcodes = $this->createShortcodes(); |
| 202 |
$order = DummyFactory::createOrderCzHdIncomplete(); |
| 203 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 204 |
$result = $this->shortcodes->pickupPointCountry( [ 'order_id' => 123 ] ); |
| 205 |
$this->assertSame( '', $result ); |
| 206 |
} |
| 207 |
|
| 208 |
public function testPickupPointCountryReturnsCountryWhenPickupPointExists(): void { |
| 209 |
$this->shortcodes = $this->createShortcodes(); |
| 210 |
$order = DummyFactory::createOrderCzHdIncomplete(); |
| 211 |
$pickupPoint = DummyFactory::createPickupPoint(); |
| 212 |
$order->setPickupPoint( $pickupPoint ); |
| 213 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 214 |
$result = $this->shortcodes->pickupPointCountry( [ 'order_id' => 123 ] ); |
| 215 |
$this->assertSame( $order->getShippingCountry() ?? '', $result ); |
| 216 |
} |
| 217 |
|
| 218 |
public function testTrackingNumberReturnsEmptyWhenNoOrder(): void { |
| 219 |
$this->shortcodes = $this->createShortcodes(); |
| 220 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( null ); |
| 221 |
$result = $this->shortcodes->trackingNumber( [ 'order_id' => 123 ] ); |
| 222 |
$this->assertSame( '', $result ); |
| 223 |
} |
| 224 |
|
| 225 |
public function testTrackingNumberReturnsEmptyWhenNoBarcode(): void { |
| 226 |
$this->shortcodes = $this->createShortcodes(); |
| 227 |
$order = DummyFactory::createOrderCzHdIncomplete(); |
| 228 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 229 |
$result = $this->shortcodes->trackingNumber( [ 'order_id' => 123 ] ); |
| 230 |
$this->assertSame( '', $result ); |
| 231 |
} |
| 232 |
|
| 233 |
public function testTrackingNumberReturnsBarcodeWhenAvailable(): void { |
| 234 |
$this->shortcodes = $this->createShortcodes(); |
| 235 |
$order = DummyFactory::createOrderCzHdIncomplete(); |
| 236 |
$order->setPacketId( 'TRACK123456' ); |
| 237 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 238 |
$result = $this->shortcodes->trackingNumber( [ 'order_id' => 123 ] ); |
| 239 |
$this->assertSame( 'ZTRACK123456', $result ); |
| 240 |
} |
| 241 |
|
| 242 |
public function testTrackingUrlReturnsEmptyWhenNoOrder(): void { |
| 243 |
$this->shortcodes = $this->createShortcodes(); |
| 244 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( null ); |
| 245 |
$result = $this->shortcodes->trackingUrl( [ 'order_id' => 123 ] ); |
| 246 |
$this->assertSame( '', $result ); |
| 247 |
} |
| 248 |
|
| 249 |
public function testTrackingUrlReturnsEmptyWhenNoUrl(): void { |
| 250 |
$this->shortcodes = $this->createShortcodes(); |
| 251 |
$order = DummyFactory::createOrderCzHdIncomplete(); |
| 252 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 253 |
$result = $this->shortcodes->trackingUrl( [ 'order_id' => 123 ] ); |
| 254 |
$this->assertSame( '', $result ); |
| 255 |
} |
| 256 |
|
| 257 |
public function testTrackingUrlReturnsUrlWhenAvailable(): void { |
| 258 |
$this->shortcodes = $this->createShortcodes(); |
| 259 |
$order = DummyFactory::createOrderCzHdIncomplete(); |
| 260 |
$order->setPacketTrackingUrl( 'https://tracking.example.com/TRACK123456' ); |
| 261 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 262 |
$result = $this->shortcodes->trackingUrl( [ 'order_id' => 123 ] ); |
| 263 |
$this->assertSame( 'https://tracking.example.com/TRACK123456', $result ); |
| 264 |
} |
| 265 |
|
| 266 |
public function testPickupPointIdReturnsEmptyWhenNoOrder(): void { |
| 267 |
$this->shortcodes = $this->createShortcodes(); |
| 268 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( null ); |
| 269 |
$result = $this->shortcodes->pickupPointId( [ 'order_id' => 123 ] ); |
| 270 |
$this->assertSame( '', $result ); |
| 271 |
} |
| 272 |
|
| 273 |
public function testPickupPointIdReturnsEmptyWhenNoPickupPoint(): void { |
| 274 |
$this->shortcodes = $this->createShortcodes(); |
| 275 |
$order = DummyFactory::createOrderCzHdIncomplete(); |
| 276 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 277 |
$result = $this->shortcodes->pickupPointId( [ 'order_id' => 123 ] ); |
| 278 |
$this->assertSame( '', $result ); |
| 279 |
} |
| 280 |
|
| 281 |
public function testPickupPointIdReturnsIdWhenPickupPointExists(): void { |
| 282 |
$this->shortcodes = $this->createShortcodes(); |
| 283 |
$order = DummyFactory::createOrderCzHdIncomplete(); |
| 284 |
$pickupPoint = DummyFactory::createPickupPoint(); |
| 285 |
$order->setPickupPoint( $pickupPoint ); |
| 286 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 287 |
$result = $this->shortcodes->pickupPointId( [ 'order_id' => 123 ] ); |
| 288 |
$this->assertSame( $pickupPoint->getId(), $result ); |
| 289 |
} |
| 290 |
|
| 291 |
public function testPickupPointNameReturnsEmptyWhenNoOrder(): void { |
| 292 |
$this->shortcodes = $this->createShortcodes(); |
| 293 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( null ); |
| 294 |
$result = $this->shortcodes->pickupPointName( [ 'order_id' => 123 ] ); |
| 295 |
$this->assertSame( '', $result ); |
| 296 |
} |
| 297 |
|
| 298 |
public function testPickupPointNameReturnsEmptyWhenNoPickupPoint(): void { |
| 299 |
$this->shortcodes = $this->createShortcodes(); |
| 300 |
$order = DummyFactory::createOrderCzHdIncomplete(); |
| 301 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 302 |
$result = $this->shortcodes->pickupPointName( [ 'order_id' => 123 ] ); |
| 303 |
$this->assertSame( '', $result ); |
| 304 |
} |
| 305 |
|
| 306 |
public function testPickupPointNameReturnsNameWhenPickupPointExists(): void { |
| 307 |
$this->shortcodes = $this->createShortcodes(); |
| 308 |
$order = DummyFactory::createOrderCzHdIncomplete(); |
| 309 |
$pickupPoint = DummyFactory::createPickupPoint(); |
| 310 |
$order->setPickupPoint( $pickupPoint ); |
| 311 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 312 |
$result = $this->shortcodes->pickupPointName( [ 'order_id' => 123 ] ); |
| 313 |
$this->assertSame( $pickupPoint->getName(), $result ); |
| 314 |
} |
| 315 |
|
| 316 |
public function testPickupPointCityReturnsEmptyWhenNoOrder(): void { |
| 317 |
$this->shortcodes = $this->createShortcodes(); |
| 318 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( null ); |
| 319 |
$result = $this->shortcodes->pickupPointCity( [ 'order_id' => 123 ] ); |
| 320 |
$this->assertSame( '', $result ); |
| 321 |
} |
| 322 |
|
| 323 |
public function testPickupPointCityReturnsEmptyWhenNoPickupPoint(): void { |
| 324 |
$this->shortcodes = $this->createShortcodes(); |
| 325 |
$order = DummyFactory::createOrderCzHdIncomplete(); |
| 326 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 327 |
$result = $this->shortcodes->pickupPointCity( [ 'order_id' => 123 ] ); |
| 328 |
$this->assertSame( '', $result ); |
| 329 |
} |
| 330 |
|
| 331 |
public function testPickupPointCityReturnsCityWhenPickupPointExists(): void { |
| 332 |
$this->shortcodes = $this->createShortcodes(); |
| 333 |
$order = DummyFactory::createOrderCzHdIncomplete(); |
| 334 |
$pickupPoint = DummyFactory::createPickupPoint(); |
| 335 |
$order->setPickupPoint( $pickupPoint ); |
| 336 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 337 |
$result = $this->shortcodes->pickupPointCity( [ 'order_id' => 123 ] ); |
| 338 |
$this->assertSame( $pickupPoint->getCity(), $result ); |
| 339 |
} |
| 340 |
|
| 341 |
public function testPickupPointZipReturnsEmptyWhenNoOrder(): void { |
| 342 |
$this->shortcodes = $this->createShortcodes(); |
| 343 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( null ); |
| 344 |
$result = $this->shortcodes->pickupPointZip( [ 'order_id' => 123 ] ); |
| 345 |
$this->assertSame( '', $result ); |
| 346 |
} |
| 347 |
|
| 348 |
public function testPickupPointZipReturnsEmptyWhenNoPickupPoint(): void { |
| 349 |
$this->shortcodes = $this->createShortcodes(); |
| 350 |
$order = DummyFactory::createOrderCzHdIncomplete(); |
| 351 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 352 |
$result = $this->shortcodes->pickupPointZip( [ 'order_id' => 123 ] ); |
| 353 |
$this->assertSame( '', $result ); |
| 354 |
} |
| 355 |
|
| 356 |
public function testPickupPointZipReturnsZipWhenPickupPointExists(): void { |
| 357 |
$this->shortcodes = $this->createShortcodes(); |
| 358 |
$order = DummyFactory::createOrderCzHdIncomplete(); |
| 359 |
$pickupPoint = DummyFactory::createPickupPoint(); |
| 360 |
$order->setPickupPoint( $pickupPoint ); |
| 361 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 362 |
$result = $this->shortcodes->pickupPointZip( [ 'order_id' => 123 ] ); |
| 363 |
$this->assertSame( $pickupPoint->getZip(), $result ); |
| 364 |
} |
| 365 |
|
| 366 |
public function testCarrierNameReturnsEmptyWhenNoOrder(): void { |
| 367 |
$this->shortcodes = $this->createShortcodes(); |
| 368 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( null ); |
| 369 |
$result = $this->shortcodes->carrierName( [ 'order_id' => 123 ] ); |
| 370 |
$this->assertSame( '', $result ); |
| 371 |
} |
| 372 |
|
| 373 |
public function testCarrierNameReturnsCarrierNameWhenOrderExists(): void { |
| 374 |
$this->shortcodes = $this->createShortcodes(); |
| 375 |
$carrier = DummyFactory::createCarrierCzechPp(); |
| 376 |
$order = new Order( 'orderNumber', $carrier ); |
| 377 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 378 |
$result = $this->shortcodes->carrierName( [ 'order_id' => 123 ] ); |
| 379 |
$this->assertSame( $carrier->getName(), $result ); |
| 380 |
} |
| 381 |
|
| 382 |
public function testIfPacketSubmittedReturnsEmptyWhenNoOrder(): void { |
| 383 |
$this->shortcodes = $this->createShortcodes(); |
| 384 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( null ); |
| 385 |
$result = $this->shortcodes->ifPacketSubmitted( [ 'order_id' => 123 ], self::DUMMY_CONTENT ); |
| 386 |
$this->assertSame( '', $result ); |
| 387 |
} |
| 388 |
|
| 389 |
public function testIfPacketSubmittedReturnsEmptyWhenNoPacketId(): void { |
| 390 |
$this->shortcodes = $this->createShortcodes(); |
| 391 |
$order = DummyFactory::createOrderCzHdIncomplete(); |
| 392 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 393 |
$result = $this->shortcodes->ifPacketSubmitted( [ 'order_id' => 123 ], self::DUMMY_CONTENT ); |
| 394 |
$this->assertSame( '', $result ); |
| 395 |
} |
| 396 |
|
| 397 |
public function testIfPacketSubmittedReturnsContentWhenPacketIdExists(): void { |
| 398 |
$this->shortcodes = $this->createShortcodes(); |
| 399 |
$order = DummyFactory::createOrderCzHdIncomplete(); |
| 400 |
$order->setPacketId( 'PACKET123' ); |
| 401 |
$this->orderRepositoryMock->method( 'findById' )->willReturn( $order ); |
| 402 |
$this->wpAdapterMock->method( 'doShortcode' )->willReturn( self::DUMMY_PROCESSED_CONTENT ); |
| 403 |
$result = $this->shortcodes->ifPacketSubmitted( [ 'order_id' => 123 ], self::DUMMY_CONTENT ); |
| 404 |
$this->assertSame( self::DUMMY_PROCESSED_CONTENT, $result ); |
| 405 |
} |
| 406 |
|
| 407 |
public function testMethodsReturnEmptyWhenOrderIdIsMissing(): void { |
| 408 |
$this->shortcodes = $this->createShortcodes(); |
| 409 |
$result = $this->shortcodes->trackingNumber( [] ); |
| 410 |
$this->assertSame( '', $result ); |
| 411 |
} |
| 412 |
|
| 413 |
public function testMethodsReturnEmptyWhenOrderIdIsNotNumeric(): void { |
| 414 |
$this->shortcodes = $this->createShortcodes(); |
| 415 |
$result = $this->shortcodes->trackingNumber( [ 'order_id' => self::DUMMY_INVALID_VALUE ] ); |
| 416 |
$this->assertSame( '', $result ); |
| 417 |
} |
| 418 |
|
| 419 |
public function testMethodsReturnEmptyWhenOrderIdIsNull(): void { |
| 420 |
$this->shortcodes = $this->createShortcodes(); |
| 421 |
$result = $this->shortcodes->trackingNumber( [ 'order_id' => null ] ); |
| 422 |
$this->assertSame( '', $result ); |
| 423 |
} |
| 424 |
} |
| 425 |
|