| 1 |
<?php |
| 2 |
|
| 3 |
declare( strict_types=1 ); |
| 4 |
|
| 5 |
namespace Module\Order; |
| 6 |
|
| 7 |
use Packetery\Core\Entity\PickupPoint; |
| 8 |
use Packetery\Module\ContextResolver; |
| 9 |
use Packetery\Module\Framework\WcAdapter; |
| 10 |
use Packetery\Module\Options\OptionsProvider; |
| 11 |
use Packetery\Module\Order\DetailCommonLogic; |
| 12 |
use Packetery\Module\Order\Repository; |
| 13 |
use Packetery\Nette\Http\Request; |
| 14 |
use PHPUnit\Framework\MockObject\MockObject; |
| 15 |
use PHPUnit\Framework\TestCase; |
| 16 |
use Tests\Core\DummyFactory; |
| 17 |
|
| 18 |
class DetailCommonLogicTest extends TestCase { |
| 19 |
|
| 20 |
private WcAdapter|MockObject $wcAdapter; |
| 21 |
private OptionsProvider|MockObject $optionsProvider; |
| 22 |
|
| 23 |
public function createDetailCommonLogic(): DetailCommonLogic { |
| 24 |
|
| 25 |
$this->wcAdapter = $this->createMock( WcAdapter::class ); |
| 26 |
$this->optionsProvider = $this->createMock( OptionsProvider::class ); |
| 27 |
|
| 28 |
return new DetailCommonLogic( |
| 29 |
$this->createMock( ContextResolver::class ), |
| 30 |
$this->createMock( Request::class ), |
| 31 |
$this->createMock( Repository::class ), |
| 32 |
$this->optionsProvider, |
| 33 |
$this->wcAdapter, |
| 34 |
); |
| 35 |
} |
| 36 |
|
| 37 |
public static function shouldDisplayPickupPointInfoProvider(): array { |
| 38 |
return [ |
| 39 |
[ |
| 40 |
'expected' => true, |
| 41 |
'replaceShippingAddressWithPickupPointAddress' => true, |
| 42 |
'shipToBillingAddressOnly' => true, |
| 43 |
], |
| 44 |
[ |
| 45 |
'expected' => false, |
| 46 |
'replaceShippingAddressWithPickupPointAddress' => true, |
| 47 |
'shipToBillingAddressOnly' => false, |
| 48 |
], |
| 49 |
[ |
| 50 |
'expected' => true, |
| 51 |
'replaceShippingAddressWithPickupPointAddress' => false, |
| 52 |
'shipToBillingAddressOnly' => true, |
| 53 |
], |
| 54 |
[ |
| 55 |
'expected' => true, |
| 56 |
'replaceShippingAddressWithPickupPointAddress' => false, |
| 57 |
'shipToBillingAddressOnly' => false, |
| 58 |
], |
| 59 |
]; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* @dataProvider shouldDisplayPickupPointInfoProvider |
| 64 |
*/ |
| 65 |
public function testShouldDisplayPickupPointInfo( |
| 66 |
bool $expected, |
| 67 |
bool $replaceShippingAddressWithPickupPointAddress, |
| 68 |
bool $shipToBillingAddressOnly, |
| 69 |
): void { |
| 70 |
$detailCommonLogic = $this->createDetailCommonLogic(); |
| 71 |
$this->optionsProvider->method( 'replaceShippingAddressWithPickupPointAddress' )->willReturn( $replaceShippingAddressWithPickupPointAddress ); |
| 72 |
$this->wcAdapter->method( 'shipToBillingAddressOnly' )->willReturn( $shipToBillingAddressOnly ); |
| 73 |
|
| 74 |
$this->assertSame( $expected, $detailCommonLogic->shouldDisplayPickupPointInfo() ); |
| 75 |
} |
| 76 |
|
| 77 |
public static function shouldHidePacketaInfoProvider(): array { |
| 78 |
return [ |
| 79 |
[ |
| 80 |
'expected' => true, |
| 81 |
'replaceShippingAddressWithPickupPointAddress' => true, |
| 82 |
'shipToBillingAddressOnly' => true, |
| 83 |
'orderPickupPoint' => null, |
| 84 |
'orderExported' => false, |
| 85 |
], |
| 86 |
[ |
| 87 |
'expected' => true, |
| 88 |
'replaceShippingAddressWithPickupPointAddress' => true, |
| 89 |
'shipToBillingAddressOnly' => false, |
| 90 |
'orderPickupPoint' => null, |
| 91 |
'orderExported' => false, |
| 92 |
], |
| 93 |
[ |
| 94 |
'expected' => true, |
| 95 |
'replaceShippingAddressWithPickupPointAddress' => false, |
| 96 |
'shipToBillingAddressOnly' => true, |
| 97 |
'orderPickupPoint' => null, |
| 98 |
'orderExported' => false, |
| 99 |
], |
| 100 |
[ |
| 101 |
'expected' => true, |
| 102 |
'replaceShippingAddressWithPickupPointAddress' => false, |
| 103 |
'shipToBillingAddressOnly' => false, |
| 104 |
'orderPickupPoint' => null, |
| 105 |
'orderExported' => false, |
| 106 |
], |
| 107 |
[ |
| 108 |
'expected' => false, |
| 109 |
'replaceShippingAddressWithPickupPointAddress' => true, |
| 110 |
'shipToBillingAddressOnly' => true, |
| 111 |
'orderPickupPoint' => null, |
| 112 |
'orderExported' => true, |
| 113 |
], |
| 114 |
[ |
| 115 |
'expected' => false, |
| 116 |
'replaceShippingAddressWithPickupPointAddress' => true, |
| 117 |
'shipToBillingAddressOnly' => false, |
| 118 |
'orderPickupPoint' => null, |
| 119 |
'orderExported' => true, |
| 120 |
], |
| 121 |
[ |
| 122 |
'expected' => false, |
| 123 |
'replaceShippingAddressWithPickupPointAddress' => false, |
| 124 |
'shipToBillingAddressOnly' => true, |
| 125 |
'orderPickupPoint' => null, |
| 126 |
'orderExported' => true, |
| 127 |
], |
| 128 |
[ |
| 129 |
'expected' => false, |
| 130 |
'replaceShippingAddressWithPickupPointAddress' => false, |
| 131 |
'shipToBillingAddressOnly' => false, |
| 132 |
'orderPickupPoint' => null, |
| 133 |
'orderExported' => true, |
| 134 |
], |
| 135 |
[ |
| 136 |
'expected' => false, |
| 137 |
'replaceShippingAddressWithPickupPointAddress' => true, |
| 138 |
'shipToBillingAddressOnly' => true, |
| 139 |
'orderPickupPoint' => new PickupPoint(), |
| 140 |
'orderExported' => false, |
| 141 |
], |
| 142 |
[ |
| 143 |
'expected' => true, |
| 144 |
'replaceShippingAddressWithPickupPointAddress' => true, |
| 145 |
'shipToBillingAddressOnly' => false, |
| 146 |
'orderPickupPoint' => new PickupPoint(), |
| 147 |
'orderExported' => false, |
| 148 |
], |
| 149 |
[ |
| 150 |
'expected' => false, |
| 151 |
'replaceShippingAddressWithPickupPointAddress' => false, |
| 152 |
'shipToBillingAddressOnly' => true, |
| 153 |
'orderPickupPoint' => new PickupPoint(), |
| 154 |
'orderExported' => false, |
| 155 |
], |
| 156 |
[ |
| 157 |
'expected' => false, |
| 158 |
'replaceShippingAddressWithPickupPointAddress' => false, |
| 159 |
'shipToBillingAddressOnly' => false, |
| 160 |
'orderPickupPoint' => new PickupPoint(), |
| 161 |
'orderExported' => false, |
| 162 |
], |
| 163 |
[ |
| 164 |
'expected' => false, |
| 165 |
'replaceShippingAddressWithPickupPointAddress' => true, |
| 166 |
'shipToBillingAddressOnly' => true, |
| 167 |
'orderPickupPoint' => new PickupPoint(), |
| 168 |
'orderExported' => true, |
| 169 |
], |
| 170 |
[ |
| 171 |
'expected' => false, |
| 172 |
'replaceShippingAddressWithPickupPointAddress' => true, |
| 173 |
'shipToBillingAddressOnly' => false, |
| 174 |
'orderPickupPoint' => new PickupPoint(), |
| 175 |
'orderExported' => true, |
| 176 |
], |
| 177 |
[ |
| 178 |
'expected' => false, |
| 179 |
'replaceShippingAddressWithPickupPointAddress' => false, |
| 180 |
'shipToBillingAddressOnly' => true, |
| 181 |
'orderPickupPoint' => new PickupPoint(), |
| 182 |
'orderExported' => true, |
| 183 |
], |
| 184 |
[ |
| 185 |
'expected' => false, |
| 186 |
'replaceShippingAddressWithPickupPointAddress' => false, |
| 187 |
'shipToBillingAddressOnly' => false, |
| 188 |
'orderPickupPoint' => new PickupPoint(), |
| 189 |
'orderExported' => true, |
| 190 |
], |
| 191 |
|
| 192 |
]; |
| 193 |
} |
| 194 |
|
| 195 |
/** |
| 196 |
* @dataProvider shouldHidePacketaInfoProvider |
| 197 |
*/ |
| 198 |
public function testShouldHidePacketaInfo( |
| 199 |
bool $expected, |
| 200 |
bool $replaceShippingAddressWithPickupPointAddress, |
| 201 |
bool $shipToBillingAddressOnly, |
| 202 |
?PickupPoint $orderPickupPoint, |
| 203 |
bool $orderExported, |
| 204 |
): void { |
| 205 |
$detailCommonLogic = $this->createDetailCommonLogic(); |
| 206 |
$this->optionsProvider->method( 'replaceShippingAddressWithPickupPointAddress' )->willReturn( $replaceShippingAddressWithPickupPointAddress ); |
| 207 |
$this->wcAdapter->method( 'shipToBillingAddressOnly' )->willReturn( $shipToBillingAddressOnly ); |
| 208 |
|
| 209 |
$dummyOrder = DummyFactory::createOrderCzPp(); |
| 210 |
if ( $orderPickupPoint !== null ) { |
| 211 |
$dummyOrder->setPickupPoint( $orderPickupPoint ); |
| 212 |
} |
| 213 |
$dummyOrder->setIsExported( $orderExported ); |
| 214 |
$this->assertSame( $expected, $detailCommonLogic->shouldHidePacketaInfo( $dummyOrder ) ); |
| 215 |
} |
| 216 |
} |
| 217 |
|