/** * Gathering expectations * * @param array 's of articles, discounts, costs, options * * @return array $aExpected of expected data */ protected function _gatherExpectedData($aTestCase) { // load calculated basket $oBasketConstruct = new BasketConstruct(); $oBasket = $oBasketConstruct->calculateBasket($aTestCase); // gathering data arrays $aExpected = array(); // Basket item list $aBasketItemList = $oBasket->getContents(); if ($aBasketItemList) { foreach ($aBasketItemList as $iKey => $oBasketItem) { $iArtId = $oBasketItem->getArticle()->getID(); $aExpected['articles'][$iArtId] = array($oBasketItem->getFUnitPrice(), $oBasketItem->getFTotalPrice()); } } // Basket total discounts $aProductDiscounts = $oBasket->getDiscounts(); if ($aProductDiscounts) { foreach ($aProductDiscounts as $oDiscount) { $aExpected['totals']['discounts'][$oDiscount->sOXID] = $oDiscount->fDiscount; } } // VAT's $aProductVats = $oBasket->getProductVats(); if ($aProductVats) { foreach ($aProductVats as $sPercent => $sSum) { $aExpected['totals']['vats'][$sPercent] = $sSum; } } // Wrapping costs $aExpected['totals']['wrapping']['brutto'] = $oBasket->getFWrappingCosts(); $aExpected['totals']['wrapping']['netto'] = $oBasket->getWrappCostNet(); $aExpected['totals']['wrapping']['vat'] = $oBasket->getWrappCostVat(); // Giftcard costs $aExpected['totals']['giftcard']['brutto'] = $oBasket->getFGiftCardCosts(); $aExpected['totals']['giftcard']['netto'] = $oBasket->getGiftCardCostNet(); $aExpected['totals']['giftcard']['vat'] = $oBasket->getGiftCardCostVat(); // Delivery costs $aExpected['totals']['delivery']['brutto'] = number_format(round($oBasket->getDeliveryCosts(), 2), 2, ',', '.'); $aExpected['totals']['delivery']['netto'] = $oBasket->getDelCostNet(); $aExpected['totals']['delivery']['vat'] = $oBasket->getDelCostVat(); // Payment costs $aExpected['totals']['payment']['brutto'] = number_format(round($oBasket->getPaymentCosts(), 2), 2, ',', '.'); $aExpected['totals']['payment']['netto'] = $oBasket->getPayCostNet(); $aExpected['totals']['payment']['vat'] = $oBasket->getPayCostVat(); // Vouchers $aExpected['totals']['voucher']['brutto'] = number_format(round($oBasket->getVoucherDiscValue(), 2), 2, ',', '.'); // Total netto & brutto, grand total $aExpected['totals']['totalNetto'] = $oBasket->getProductsNetPrice(); $aExpected['totals']['totalBrutto'] = $oBasket->getFProductsPrice(); $aExpected['totals']['grandTotal'] = $oBasket->getFPrice(); // Finished generating expectations return $aExpected; }
/** * Tests order numbering when middle one is saved without finalizing. * * @dataProvider providerOrderNumberingForDifferentShops * * @param array $testCase */ public function testOrderNumberingForDifferentShops3($testCase) { if ($testCase['skipped'] == 1) { $this->markTestSkipped("testcase is skipped"); } $options = $testCase['options']; // load calculated basket from provided data $basketConstruct = new BasketConstruct(); $basket = $basketConstruct->calculateBasket($testCase); $user = $basket->getBasketUser(); // Mocking _sendOrderByEmail, cause Jenkins return err, while mailing after saving order /** @var oxOrder|MockObject $order1 */ $order1 = $this->getMock('oxOrder', array('_sendOrderByEmail', 'validateDeliveryAddress', 'validateDelivery')); $order1->expects($this->any())->method('_sendOrderByEmail')->will($this->returnValue(0)); $order1->expects($this->any())->method('validateDeliveryAddress')->will($this->returnValue(null)); $order1->expects($this->any())->method('validateDelivery')->will($this->returnValue(null)); // if basket has products if ($basket->getProductsCount()) { $order1->finalizeOrder($basket, $user); } // Mocking _sendOrderByEmail, cause Jenkins return err, while mailing after saving order /** @var oxOrder|MockObject $order2 */ $order2 = $this->getMock('oxOrder', array('_sendOrderByEmail', 'validateDeliveryAddress', 'validateDelivery')); $order2->expects($this->any())->method('_sendOrderByEmail')->will($this->returnValue(0)); $order2->expects($this->any())->method('validateDeliveryAddress')->will($this->returnValue(null)); $order2->expects($this->any())->method('validateDelivery')->will($this->returnValue(null)); $order2->save(); // Mocking _sendOrderByEmail, cause Jenkins return err, while mailing after saving order /** @var oxOrder|MockObject $order3 */ $order3 = $this->getMock('oxOrder', array('_sendOrderByEmail', 'validateDeliveryAddress', 'validateDelivery')); $order3->expects($this->any())->method('_sendOrderByEmail')->will($this->returnValue(0)); $order3->expects($this->any())->method('validateDeliveryAddress')->will($this->returnValue(null)); $order3->expects($this->any())->method('validateDelivery')->will($this->returnValue(null)); // If separate numbering, then it must be restarted. $order3->setSeparateNumbering($options['separateNumbering']); // if basket has products if ($basket->getProductsCount()) { $order3->finalizeOrder($basket, $user); } $order1Nr = $order1->oxorder__oxordernr->value; $order3Nr = $order3->oxorder__oxordernr->value; if ($options['separateNumbering']) { $this->assertEquals(1, $order3Nr, 'Second order must start from begining if separate numbering.'); } else { $this->assertEquals($order1Nr, $order3Nr - 1, 'Second order must had bigger number if no separate numbering.'); } }
/** * Tests price calculation * * @dataProvider providerPrice * * @param array $aTestCase */ public function testPrice($aTestCase) { if ($aTestCase['skipped'] == 1) { $this->markTestSkipped("testcase is skipped"); } // gather data from test case $aExpected = $aTestCase['expected']; // load calculated basket from provided data $oConstruct = new BasketConstruct(); // create shops $iActiveShopId = $oConstruct->createShop($aTestCase['shop']); // create user if specified $oUser = $oConstruct->createObj($aTestCase['user'], "oxuser", "oxuser"); // create group and assign $oConstruct->createGroup($aTestCase['group']); // user login if ($oUser) { $oUser->login($aTestCase['user']['oxusername'], ''); } // setup options $oConstruct->setOptions($aTestCase['options']); // create categories $oConstruct->setCategories($aTestCase['categories']); // create articles $articlesData = $oConstruct->getArticles($aTestCase['articles']); // apply discounts $oConstruct->setDiscounts($aTestCase['discounts']); // set active shop if ($iActiveShopId != 1) { $oConstruct->setActiveShop($iActiveShopId); } // iteration through expectations foreach ($articlesData as $articleData) { $expected = $aExpected[$articleData['id']]; if (empty($expected)) { continue; } $article = oxNew('oxArticle'); $article->load($articleData['id']); $this->assertEquals($expected['base_price'], $this->getFormatted($article->getBasePrice()), "Base Price of article #{$articleData['id']}"); $this->assertEquals($expected['price'], $article->getFPrice(), "Price of article #{$articleData['id']}"); if (isset($expected['rrp_price'])) { $this->assertEquals($expected['rrp_price'], $article->getFTPrice(), "RRP price of article #{$articleData['id']}"); } if (isset($expected['unit_price'])) { $this->assertEquals($expected['unit_price'], $article->getFUnitPrice(), "Unit Price of article #{$articleData['id']}"); } if (isset($expected['is_range_price'])) { $this->assertEquals($expected['is_range_price'], $article->isRangePrice(), "Is range price check of article #{$articleData['id']}"); } if (isset($expected['min_price'])) { $this->assertEquals($expected['min_price'], $article->getFMinPrice(), "Min price of article #{$articleData['id']}"); } if (isset($expected['var_min_price'])) { $this->assertEquals($expected['var_min_price'], $article->getFVarMinPrice(), "Var min price of article #{$articleData['id']}"); } if (isset($expected['show_rrp'])) { $blShowRPP = false; if ($article->getTPrice() && $article->getTPrice()->getPrice() > $article->getPrice()->getPrice()) { $blShowRPP = true; } $this->assertEquals($expected['show_rrp'], $blShowRPP, "RRP price showing of article #{$articleData['id']}"); } } }
/** * Add articles * * @param array $articlesData new articles to add * @param object $order */ protected function _addArticles($articlesData, $order) { $basketConstruct = new BasketConstruct(); $articles = $basketConstruct->getArticles($articlesData); foreach ($articles as $article) { $product = oxNew('oxArticle'); $product->load($article['id']); $amount = $article['amount']; $orderArticle = oxNew('oxOrderArticle'); $orderArticle->oxorderarticles__oxartid = new oxField($product->getId()); $orderArticle->oxorderarticles__oxartnum = new oxField($product->oxarticles__oxartnum->value); $orderArticle->oxorderarticles__oxamount = new oxField($amount); $orderArticle->oxorderarticles__oxselvariant = new oxField(oxRegistry::getConfig()->getRequestParameter('sel')); $order->recalculateOrder(array($orderArticle)); } }
/** * Tests special basket calculations * * @dataProvider providerBasketCalculation * * @param array $testCase */ public function testBasketCalculation($testCase) { if ($testCase['skipped'] == 1) { $this->markTestSkipped("testcase is skipped"); } // gathering data arrays $expected = $testCase['expected']; //if not finished testing data skip test if (empty($expected)) { $this->markTestSkipped("skipping test case due invalid data provided"); } // load calculated basket from provided data $basketConstruct = new BasketConstruct(); $basket = $basketConstruct->calculateBasket($testCase); // check basket item list $expectedArticles = $expected['articles']; $basketItemList = $basket->getContents(); $this->assertEquals(count($expectedArticles), count($basketItemList), "Expected basket articles amount doesn't match actual"); if ($basketItemList) { foreach ($basketItemList as $key => $basketItem) { /** @var oxOrderArticle $basketItem */ $articleId = $basketItem->getArticle()->getID(); $this->assertEquals($expectedArticles[$articleId][0], $basketItem->getFUnitPrice(), "Unit price of article id {$articleId}"); $this->assertEquals($expectedArticles[$articleId][1], $basketItem->getFTotalPrice(), "Total price of article id {$articleId}"); } } // Total discounts $expectedDiscounts = $expected['totals']['discounts']; $productDiscounts = $basket->getDiscounts(); $this->assertEquals(count($expectedDiscounts), count($productDiscounts), "Expected basket discount amount doesn't match actual"); if (!empty($expectedDiscounts)) { foreach ($productDiscounts as $discount) { $this->assertEquals($expectedDiscounts[$discount->sOXID], $discount->fDiscount, "Total discount of {$discount->sOXID}"); } } // Total vats $expectedVats = $expected['totals']['vats']; $productVats = $basket->getProductVats(); $this->assertEquals(count($expectedVats), count($productVats), "Expected basket different vat amount doesn't match actual"); if (!empty($expectedVats)) { foreach ($productVats as $percent => $sum) { $this->assertEquals($expectedVats[$percent], $sum, "Total Vat of {$percent}%"); } } // Wrapping costs $expectedWrappings = $expected['totals']['wrapping']; if (!empty($expectedWrappings)) { $this->assertEquals($expectedWrappings['brutto'], $basket->getFWrappingCosts(), "Total wrappings brutto price"); $this->assertEquals($expectedWrappings['netto'], $basket->getWrappCostNet(), "Total wrappings netto price"); $this->assertEquals($expectedWrappings['vat'], $basket->getWrappCostVat(), "Total wrappings vat price"); } // Giftcard costs $expectedCards = $expected['totals']['giftcard']; if (!empty($expectedCards)) { $this->assertEquals($expectedCards['brutto'], $basket->getFGiftCardCosts(), "Total giftcard brutto price"); $this->assertEquals($expectedCards['netto'], $basket->getGiftCardCostNet(), "Total giftcard netto price"); $this->assertEquals($expectedCards['vat'], $basket->getGiftCardCostVat(), "Total giftcard vat price"); } // Delivery costs $expectedDeliveryCosts = $expected['totals']['delivery']; if (!empty($expectedDeliveryCosts)) { $this->assertEquals($expectedDeliveryCosts['brutto'], number_format(round($basket->getDeliveryCosts(), 2), 2, ',', '.'), "Delivery total brutto price"); $this->assertEquals($expectedDeliveryCosts['netto'], $basket->getDelCostNet(), "Delivery total netto price"); $this->assertEquals($expectedDeliveryCosts['vat'], $basket->getDelCostVat(), "Delivery total vat price"); } // Payment costs $expectedPayments = $expected['totals']['payment']; if (!empty($expectedPayments)) { $this->assertEquals($expectedPayments['brutto'], number_format(round($basket->getPaymentCosts(), 2), 2, ',', '.'), "Payment total brutto price"); $this->assertEquals($expectedPayments['netto'], $basket->getPayCostNet(), "Payment total netto price"); $this->assertEquals($expectedPayments['vat'], $basket->getPayCostVat(), "Payment total vat price"); } // Vouchers $expectedVouchers = $expected['totals']['voucher']; if (!empty($expectedVouchers)) { $this->assertEquals($expectedVouchers['brutto'], number_format(round($basket->getVoucherDiscValue(), 2), 2, ',', '.'), "Voucher total discount brutto"); } // Total netto & brutto, grand total $this->assertEquals($expected['totals']['totalNetto'], $basket->getProductsNetPrice(), "Total Netto"); $this->assertEquals($expected['totals']['totalBrutto'], $basket->getFProductsPrice(), "Total Brutto"); $this->assertEquals($expected['totals']['grandTotal'], $basket->getFPrice(), "Grand Total"); }