9 use \Magento\Shipping\Model\Carrier\AbstractCarrierOnline;
40 $this->stockRegistry = $this->createMock(\
Magento\CatalogInventory\Model\StockRegistry::class);
41 $this->stockItemData = $this->createMock(\
Magento\CatalogInventory\Model\Stock\Item::class);
43 $this->stockRegistry->expects($this->any())->method(
'getStockItem')
44 ->with($this->productId, 10)
45 ->will($this->returnValue($this->stockItemData));
47 $objectManagerHelper =
new ObjectManagerHelper($this);
48 $carrierArgs = $objectManagerHelper->getConstructArguments(
51 'stockRegistry' => $this->stockRegistry,
52 'xmlSecurity' =>
new \
Magento\Framework\Xml\Security(),
55 $this->carrier = $this->getMockBuilder(\
Magento\
Shipping\Model\Carrier\AbstractCarrierOnline::class)
56 ->setConstructorArgs($carrierArgs)
57 ->setMethods([
'getConfigData',
'_doShipmentRequest',
'collectRates'])
66 $this->carrier->expects($this->any())->method(
'getConfigData')->will($this->returnCallback(
function ($key) {
68 'max_package_weight' => 10,
75 $product->expects($this->any())->method(
'getId')->will($this->returnValue($this->productId));
78 ->disableOriginalConstructor()
79 ->setMethods([
'getProduct',
'getQty',
'getWeight',
'__wakeup',
'getStore'])
81 $item->expects($this->any())->method(
'getProduct')->will($this->returnValue(
$product));
83 $store = $this->createPartialMock(\
Magento\
Store\Model\Store::class, [
'getWebsiteId']);
84 $store->expects($this->any())
85 ->method(
'getWebsiteId')
86 ->will($this->returnValue(10));
87 $item->expects($this->any())->method(
'getStore')->will($this->returnValue(
$store));
91 $request->setData(
'dest_postcode', 1);
94 $this->stockRegistry->expects($this->atLeastOnce())->method(
'getStockItem')->with($this->productId);
95 $this->stockItemData->expects($this->atLeastOnce())->method(
'getEnableQtyIncrements')
96 ->will($this->returnValue(
true));
97 $this->stockItemData->expects($this->atLeastOnce())->method(
'getQtyIncrements')
98 ->will($this->returnValue(5));
99 $this->stockItemData->expects($this->atLeastOnce())->method(
'getIsQtyDecimal')->will($this->returnValue(
true));
100 $this->stockItemData->expects($this->atLeastOnce())->method(
'getIsDecimalDivided')
101 ->will($this->returnValue(
true));
103 $this->carrier->processAdditionalValidation(
$request);
108 $xmlString =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><GetResponse><value>42</value>></GetResponse>";
109 $simpleXmlElement = $this->carrier->parseXml($xmlString);
110 $this->assertEquals(
'GetResponse', $simpleXmlElement->getName());
111 $this->assertEquals(42, (
int)$simpleXmlElement->value);
112 $this->assertInstanceOf(
'SimpleXMLElement', $simpleXmlElement);
113 $customSimpleXmlElement = $this->carrier->parseXml(
117 $this->assertInstanceOf(\
Magento\
Shipping\Model\Simplexml\Element::class, $customSimpleXmlElement);
126 $xmlString =
'<!DOCTYPE scan [ 127 <!ENTITY test SYSTEM "php://filter/read=convert.base64-encode/resource=' 128 .
__DIR__ .
'/AbstractCarrierOnline/xxe-xml.txt">]><scan>&test;</scan>';
130 $xmlElement = $this->carrier->parseXml($xmlString);
133 echo $xmlElement->asXML();
142 $xmlString =
'<?xml version="1.0"?> 144 <!ENTITY value "value"> 145 <!ENTITY value1 "&value;&value;&value;&value;&value;&value;&value;&value;&value;&value;"> 146 <!ENTITY value2 "&value1;&value1;&value1;&value1;&value1;&value1;&value1;&value1;&value1;&value1;"> 148 <test>&value2;</test>';
150 $this->carrier->parseXml($xmlString);
defined('TESTS_BP')||define('TESTS_BP' __DIR__