This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Moip\Tests\Resource; |
||
| 4 | |||
| 5 | use Moip\Resource\Orders; |
||
| 6 | use Moip\Tests\TestCase; |
||
| 7 | |||
| 8 | class OrdersTest extends TestCase |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Send http request. |
||
| 12 | * |
||
| 13 | * @param \Moip\Resource\Orders $order |
||
| 14 | * @param string $body |
||
| 15 | * |
||
| 16 | * @return \Moip\Resource\Orders |
||
| 17 | */ |
||
| 18 | private function executeOrder(Orders $order = null, $body = null) |
||
| 19 | { |
||
| 20 | if (empty($body)) { |
||
| 21 | $body = $this->body_order; |
||
| 22 | } |
||
| 23 | if (empty($order)) { |
||
| 24 | $order = $this->createOrder(); |
||
| 25 | } |
||
| 26 | $this->mockHttpSession($body); |
||
| 27 | |||
| 28 | return $order->create(); |
||
|
0 ignored issues
–
show
Bug
Compatibility
introduced
by
Loading history...
|
|||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @const string |
||
| 33 | */ |
||
| 34 | public function testAssertConstPath() |
||
| 35 | { |
||
| 36 | $this->assertEquals('orders', Orders::PATH); |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Tests if the primary receiver constant has the correct value. |
||
| 41 | * |
||
| 42 | * @const string |
||
| 43 | */ |
||
| 44 | public function testAssertConstReceiverTypePrimary() |
||
| 45 | { |
||
| 46 | $this->assertEquals('PRIMARY', Orders::RECEIVER_TYPE_PRIMARY); |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Tests if the secondary receiver constant has the correct value. |
||
| 51 | * |
||
| 52 | * @const string |
||
| 53 | */ |
||
| 54 | public function testAssertConstReceiverTypeSecpndary() |
||
| 55 | { |
||
| 56 | $this->assertEquals('SECONDARY', Orders::RECEIVER_TYPE_SECONDARY); |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Tests the currency in the order creation response. |
||
| 61 | * |
||
| 62 | * @const string |
||
| 63 | */ |
||
| 64 | public function testAssertConstAmountCurrency() |
||
| 65 | { |
||
| 66 | $this->assertEquals('BRL', Orders::AMOUNT_CURRENCY); |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * MoipTest creating an order. |
||
| 71 | */ |
||
| 72 | public function testCreateOrder() |
||
| 73 | { |
||
| 74 | $order_created = $this->executeOrder(); |
||
| 75 | |||
| 76 | $this->assertEquals($this->last_ord_id, $order_created->getOwnId()); |
||
| 77 | $this->assertEquals('CREATED', $order_created->getStatus()); |
||
| 78 | $this->assertEquals(new \DateTime('2016-02-19T12:24:55.849-02'), $order_created->getCreatedAt()); |
||
| 79 | $this->assertEquals(new \DateTime('2016-02-19T12:24:55.849-02'), $order_created->getUpdatedAt()); |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Tests if created items price are correct. |
||
| 84 | */ |
||
| 85 | public function testItems() |
||
| 86 | { |
||
| 87 | $order_created = $this->executeOrder(); |
||
| 88 | $itens = $order_created->getItemIterator()->getArrayCopy(); |
||
| 89 | $this->assertEquals(100000, $itens[0]->price); |
||
| 90 | $this->assertEquals(990, $itens[1]->price); |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Test if created order shipping address is correct. |
||
| 95 | */ |
||
| 96 | public function testShippingAddress() |
||
| 97 | { |
||
| 98 | $order_created = $this->executeOrder(); |
||
| 99 | |||
| 100 | $this->assertEquals('01234000', $order_created->getCustomer()->getShippingAddress()->{'zipCode'}); |
||
| 101 | $this->assertEquals('Avenida Faria Lima', $order_created->getCustomer()->getShippingAddress()->{'street'}); |
||
| 102 | $this->assertEquals('2927', $order_created->getCustomer()->getShippingAddress()->{'streetNumber'}); |
||
| 103 | $this->assertEquals('8', $order_created->getCustomer()->getShippingAddress()->{'complement'}); |
||
| 104 | $this->assertEquals('Sao Paulo', $order_created->getCustomer()->getShippingAddress()->{'city'}); |
||
| 105 | $this->assertEquals('Itaim', $order_created->getCustomer()->getShippingAddress()->{'district'}); |
||
| 106 | $this->assertEquals('SP', $order_created->getCustomer()->getShippingAddress()->{'state'}); |
||
| 107 | $this->assertEquals('BRA', $order_created->getCustomer()->getShippingAddress()->{'country'}); |
||
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | *MoipTest if the total is correct. |
||
| 112 | */ |
||
| 113 | public function testTotal() |
||
| 114 | { |
||
| 115 | $order = $this->executeOrder(); |
||
| 116 | |||
| 117 | $total = $order->getSubtotalItems() + $order->getSubtotalShipping() + $order->getSubtotalAddition() - $order->getSubtotalDiscount(); |
||
| 118 | $this->assertEquals($total, $order->getAmountTotal()); |
||
| 119 | } |
||
| 120 | |||
| 121 | /** |
||
| 122 | * MoipTest if the total is equal to the expected total. |
||
| 123 | */ |
||
| 124 | public function testTotalConstant() |
||
| 125 | { |
||
| 126 | $order = $this->executeOrder(); |
||
| 127 | $expected = (100000 + 2 * 990 + 1490) - 1000; |
||
| 128 | $total_calculated = $order->getSubtotalItems() + $order->getSubtotalShipping() + $order->getSubtotalAddition() - $order->getSubtotalDiscount(); |
||
| 129 | |||
| 130 | $this->assertEquals($expected, $total_calculated); |
||
| 131 | $this->assertEquals($expected, $order->getAmountTotal()); |
||
| 132 | } |
||
| 133 | |||
| 134 | /** |
||
| 135 | * MoipTest if order is created with installment preferences. |
||
| 136 | */ |
||
| 137 | public function testCreateOrderWithInstallmentPreferences() |
||
| 138 | { |
||
| 139 | $quantity = [1, 6]; |
||
| 140 | $discount = 0; |
||
| 141 | $additional = 100; |
||
| 142 | $order = $this->createOrder()->addInstallmentCheckoutPreferences($quantity, $discount, $additional); |
||
| 143 | $returned_order = $this->executeOrder($order); |
||
| 144 | $this->assertNotEmpty($returned_order->getId()); |
||
| 145 | $this->assertEquals([1, 6], $returned_order->getCheckoutPreferences()->installments[0]->quantity); |
||
| 146 | } |
||
| 147 | |||
| 148 | public function testCreateOrderAddingReceiverNoAmount() |
||
| 149 | { |
||
| 150 | $order = $this->createOrder()->addReceiver('MPA-7ED9D2D0BC81', 'PRIMARY'); |
||
| 151 | $receivers = $order->getReceiverIterator(); |
||
| 152 | $this->assertEquals('MPA-7ED9D2D0BC81', $receivers[0]->moipAccount->id); |
||
| 153 | } |
||
| 154 | |||
| 155 | public function testCreateOrderAddingReceiverAmountFixed() |
||
| 156 | { |
||
| 157 | $order = $this->createOrder()->addReceiver('MPA-7ED9D2D0BC81', 'PRIMARY', 30000); |
||
| 158 | $receivers = $order->getReceiverIterator(); |
||
| 159 | $this->assertEquals(30000, $receivers[0]->amount->fixed); |
||
| 160 | } |
||
| 161 | |||
| 162 | public function testCreateOrderAddingReceiverAmountPercentual() |
||
| 163 | { |
||
| 164 | $order = $this->createOrder()->addReceiver('MPA-7ED9D2D0BC81', 'PRIMARY', null, 40); |
||
| 165 | $receivers = $order->getReceiverIterator(); |
||
| 166 | $this->assertEquals(40, $receivers[0]->amount->percentual); |
||
| 167 | } |
||
| 168 | |||
| 169 | public function testCreateOrderAddingReceiverFeePayor() |
||
| 170 | { |
||
| 171 | $order = $this->createOrder()->addReceiver('MPA-7ED9D2D0BC81', 'PRIMARY', null, 40, true); |
||
| 172 | $receivers = $order->getReceiverIterator(); |
||
| 173 | $this->assertEquals(40, $receivers[0]->amount->percentual); |
||
| 174 | $this->assertTrue($receivers[0]->feePayor); |
||
| 175 | $order2 = $this->createOrder()->addReceiver('MPA-7ED9D2D0BC81', 'PRIMARY', 30000, null, true); |
||
| 176 | $receivers2 = $order2->getReceiverIterator(); |
||
| 177 | $this->assertEquals(30000, $receivers2[0]->amount->fixed); |
||
| 178 | $this->assertTrue($receivers2[0]->feePayor); |
||
| 179 | } |
||
| 180 | } |
||
| 181 |