Skip to content

Commit

Permalink
5.5.1 release (#52)
Browse files Browse the repository at this point in the history
* Fix unit tests for OXID 6.3

* Fix Spelling on new Klarna admin start page

* Fix bug related with delivery cost adding up
add unit test

* add codeception test to check shipping method price

* keep calcDeliverycost parent call for compatibility with other modules.

* Fix Spelling on new Klarna admin start page english

* version 5.5.1 update documentation
  • Loading branch information
tc-hugo committed Jul 1, 2021
1 parent 29d57a2 commit 0d32160
Show file tree
Hide file tree
Showing 22 changed files with 198 additions and 51 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### 5.5.1
* Fix spelling on new Klarna admin start page DE/EN
* Bugfix: Shipping costs add up
* Update tests to be compatible with OXID 6.3.x
* Update tests to be compatible with PHPUnit8 as well as older versions.

### 5.5.0
* Remove Instant Shopping
* Backend Rebranding
Expand Down
Binary file not shown.
Binary file not shown.
12 changes: 12 additions & 0 deletions Model/KlarnaBasket.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,21 @@ protected function _getKlarnaCheckoutDiscount(Price $oPrice, $iLang = null, $tax
*/
public function tcklarna_calculateDeliveryCost()
{
$oDeliveryList = oxNew(DeliveryList::class);
Registry::set(DeliveryList::class, $oDeliveryList);

return parent::_calcDeliveryCost();
}

/**
* @throws \OxidEsales\Eshop\Core\Exception\SystemComponentException
* @return object
*/
protected function _calcDeliveryCost()
{
return KlarnaUtils::isKlarnaPaymentsEnabled()?$this->tcklarna_calculateDeliveryCost():parent::_calcDeliveryCost();
}

/**
* Get average of order VAT
* @return float
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Klarna Checkout and Klarna Payments Module for the OXID eShop
### Title: Klarna Checkout and Klarna Payments Module for the OXID eShop
### Author: cgrd GmbH, https://www.cgrd.de/oxid-eshop
### Prefix: tcklarna
### Version: 5.5.0
### Version: 5.5.1
### Link: https://www.klarna.com/de/verkaeufer/plattformen-und-partner/oxid/
### Mail: oxid@klarna.com

Expand All @@ -21,11 +21,11 @@ OXID eShop Plugin to integrate Klarna Checkout and Klarna Payments to OXID eShop

In the shop's main folder ( the one with composer.json file) run this command:

composer require topconcepts/oxid-klarna-6:v5.5.0
composer require topconcepts/oxid-klarna-6:v5.5.1

or add the following line within the "require" section to your composer.json file:

"topconcepts/oxid-klarna-6": "v5.5.0"
"topconcepts/oxid-klarna-6": "v5.5.1"

and run

Expand All @@ -36,5 +36,5 @@ and run

See folder /Documentation in this package or download latest manuals here:

### In English: https://www.cgrd.de/customer/klarna/docs/klarna-module-for-oxid-en-5.5.0.pdf
### In German: https://www.cgrd.de/customer/klarna/docs/klarna-module-for-oxid-de-5.5.0.pdf
### In English: https://www.cgrd.de/customer/klarna/docs/klarna-module-for-oxid-en-5.5.1.pdf
### In German: https://www.cgrd.de/customer/klarna/docs/klarna-module-for-oxid-de-5.5.1.pdf
4 changes: 2 additions & 2 deletions Tests/Codeception/Page/Kco.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function fillKcoUserForm()
* @param AcceptanceTester $I
* @throws \Exception
*/
public function fillKcoShippingForm() {
public function fillKcoShippingForm($shippingMethod = 'UPS 48') {
$I = $this->user;
$I->wait(4); // wait for loaders and overlays to be hidden
$I->click('//*[@id="klarna-checkout-shipping-details"]//*[@id="preview__link"]');
Expand All @@ -152,7 +152,7 @@ public function fillKcoShippingForm() {
$I->switchToIFrame();
$I->switchToIFrame($this->frames['main']);
$I->wait(5);
$I->selectOption('#SHIPMO-container input[name=radio]', 'UPS 48');
$I->selectOption('#SHIPMO-container input[name=radio]', $shippingMethod);
$I->wait(3);
}

Expand Down
57 changes: 57 additions & 0 deletions Tests/Codeception/acceptance/CheckoutKCOCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,61 @@ public function createAccountAndSubscribe(AcceptanceTester $I)
$I->seeOrderInDb($klarnaId, $inputDataMapper);
$I->seeInKlarnaAPI($klarnaId, "AUTHORIZED", true);
}

/**
* @group KCO_frontend
* @param AcceptanceTester $I
* @throws \Exception
*/
public function differentShippingMethod(AcceptanceTester $I)
{
$I->clearShopCache();
$I->wantToTest('Checkout with different shipping method');
$I->loadKlarnaAdminConfig('KCO');
$homePage = $I->openShop();
$basket = new Basket($I);
$basket->addProductToBasket('05848170643ab0deb9914566391c0c63', 1);
$basket->addProductToBasket('058de8224773a1d5fd54d523f0c823e0', 1);
$homePage->openMiniBasket();
$I->click(Translator::translate('CHECKOUT'));
$I->waitForPageLoad();
$I->click("//form[@id='select-country-form']//button[@value='DE']");
$I->wait(2);

$kco = new Kco($I);
$kco->fillKcoUserForm();
$I->wait(2);
//Test if shipping method price is correct
$I->see('12,90 €');
$I->wait(2);
//different shipping method
$kco->fillKcoShippingForm('UPS Express 24');
$I->wait(2);
$I->executeJS('document.querySelector("[data-cid=\'button.buy_button\']").click()');
$I->wait(2);
$I->switchToIFrame(); // navigate back to to main document frame
$I->waitForElement('#thankyouPage');
$I->waitForPageLoad();

$billEmail = Fixtures::get('gKCOEmail'); // recall generated and stored email
$I->seeInDatabase('oxuser', ['oxusername' => $billEmail, 'oxpassword' => '']);
$klarnaId = $I->grabFromDatabase('oxorder', 'TCKLARNA_ORDERID', ['OXBILLEMAIL' => $billEmail]);
$I->assertNotEmpty($klarnaId);

$inputDataMapper = [
'sKCOFormPostCode' => 'OXBILLZIP',
'sKCOFormGivenName' => 'OXBILLFNAME',
'sKCOFormFamilyName' => 'OXBILLLNAME',
'sKCOFormStreetName' => 'OXBILLSTREET',
'sKCOFormStreetNumber' => 'OXBILLSTREETNR',
'sKCOFormCity' => 'OXBILLCITY',
'sKCOFormDelPostCode' => 'OXDELZIP',
'sKCOFormDelStreetName' => 'OXDELSTREET',
'sKCOFormDelStreetNumber' => 'OXDELSTREETNR',
'sKCOFormDelCity' => 'OXDELCITY',
];

$I->seeOrderInDb($klarnaId, $inputDataMapper);
$I->seeInKlarnaAPI($klarnaId, "AUTHORIZED", true);
}
}
2 changes: 1 addition & 1 deletion Tests/Unit/Component/KlarnaBasketComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
class KlarnaBasketComponentTest extends ModuleUnitTestCase {

protected function setUp() {
protected function setUp(): void {
parent::setUp();
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/Unit/Controller/Admin/KlarnaOrderOverviewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,20 +276,20 @@ public function captureInSyncDataProvider() {
}

public function testIsCredentialsValid() {
$this->setOrder();
$controller = $this->getMockBuilder(OrderOverview::class)
->setMethods(['getEditObjectId',])
->getMock();
$controller->expects($this->any())->method('getEditObjectId')->willReturn('test');
$result = $controller->isCredentialsValid();
$this->assertFalse($result);

$this->setOrder();
$this->setModuleConfVar('aKlarnaCreds_DE', '');
$this->setModuleConfVar('sKlarnaMerchantId', 'smid');
$this->setModuleConfVar('sKlarnaPassword', 'psw');
$controller = $this->getMockBuilder(OrderOverview::class)
->setMethods(['getEditObjectId'])
->getMock();
->setMethods(['getEditObjectId'])
->getMock();
$controller->expects($this->any())->method('getEditObjectId')->willReturn('test');
$result = $controller->isCredentialsValid();
$this->assertTrue($result);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/Controller/KlarnaExpressControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public function testCheckSsl($sslredirect, $expectedResult) {
$oRequest->expects($this->once())->method('getRequestEscapedParameter')->willReturn($sslredirect);
$kcoController = oxNew(KlarnaExpressController::class);
$kcoController->checkSsl($oRequest);
$this->assertContains((string)$expectedResult, (string)\oxUtilsHelper::$sRedirectUrl);
$this->doAssertContains((string)$expectedResult, (string)\oxUtilsHelper::$sRedirectUrl);
}

public function checkSslDataProvider() {
Expand Down
28 changes: 14 additions & 14 deletions Tests/Unit/Controller/KlarnaPaymentControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,28 @@ public function initDataProvider()

return [
['KCO', false, null, 'DE', null,
[null, true, $redirectUrl],
[null, true, $redirectUrl],
],
['KP', false, null, 'DE', null,
[null, true, null],
[null, true, null],
],
['KCO', false, null, 'AF', null,
[null, true, null],
[null, true, null],
],
['KCO', $oUser, null, null, null,
[null, true, $redirectUrl],
[null, true, $redirectUrl],
],
['KCO', $oUser, null, null, 'nonKCORequest',
[null, true, null],
[null, true, null],
],
['KCO', $oUserAT, 'amazonRef', null, null,
['AT', false, null],
['AT', false, null],
],
['KCO', $oUserDE, null, null, null,
['DE', true, $redirectUrl],
['DE', true, $redirectUrl],
],
['KCO', $oUserAF, null, null, null,
['AF', true, null],
['AF', true, null],
],
];
}
Expand Down Expand Up @@ -110,7 +110,7 @@ public function testRemoveKlarnaPrefix()
{
$oPaymentController = oxNew(PaymentController::class);
$result = $oPaymentController->removeKlarnaPrefix('Klarna String');
$this->assertNotContains('Klarna ', $result);
$this->doAssertNotContains('Klarna ', $result);
}

public function testIncludeKPWidget()
Expand Down Expand Up @@ -413,23 +413,23 @@ public function validatePaymentDataProvider()
return [
// authorized (requires finalization)
['klarna_pay_later', true, null, self::COUNTRIES['DE'],
['KP_data'], 'order'],
['KP_data'], 'order'],

// authorized (token present)
['klarna_pay_now', null, 'authToken', self::COUNTRIES['DE'],
['KP_data'], 'order'],
['KP_data'], 'order'],

// error - not available in this country
['klarna_pay_now', null, 'authToken', self::COUNTRIES['AF'],
['KP_data'], null],
['KP_data'], null],

// not authorized and no error
['klarna_slice_it', null, null, null,
['KP_data'], null],
['KP_data'], null],

// not KP
['other', null, null, null,
null, 'order']
null, 'order']
];
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/Unit/Controller/KlarnaValidationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
class KlarnaValidationControllerTest extends ModuleUnitTestCase
{

public function setUp()
public function setUp(): void
{
parent::setUp();
$this->setModuleConfVar('blKlarnaLoggingEnabled', true, 'bool');
}

public function tearDown()
public function tearDown(): void
{
parent::tearDown();
$this->setModuleConfVar('blKlarnaLoggingEnabled', false, 'bool');
Expand Down Expand Up @@ -114,7 +114,7 @@ public function testInit_errorsAndLogs()
$this->assertNotEmpty($result->count());

$this->assertEquals(303, \oxUtilsHelper::$iCode);
$this->assertContains('klarnaInvalid=1&MY_ERROR=33&CANT_BUY=10', \oxUtilsHelper::$sRedirectUrl);
$this->doAssertContains('klarnaInvalid=1&MY_ERROR=33&CANT_BUY=10', \oxUtilsHelper::$sRedirectUrl);
}


Expand Down
13 changes: 11 additions & 2 deletions Tests/Unit/Core/KlarnaFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testKlarnaToOxidAddress($sKey, $addressData, $expected)
$result = KlarnaFormatter::klarnaToOxidAddress($addressData, $sKey);
$sKey === null
? $this->assertNull($result)
: $this->assertArraySubset($expected, $result);
: $this->doAssertArraySubset($expected, $result);
}

public function klarnaToOxidAddressDataprovider()
Expand Down Expand Up @@ -165,4 +165,13 @@ public function addressFormatterDataProvider()
['c95a1d97acaebd371851727d1173dcd0', false]
];
}
}

protected function doAssertArraySubset($needle, $haystack)
{
if (method_exists($this, 'assertArraySubsetOxid')) {
parent::assertArraySubsetOxid($needle, $haystack);
} else {
parent::assertArraySubset($needle, $haystack);
}
}
}
4 changes: 2 additions & 2 deletions Tests/Unit/Core/KlarnaPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ public function test__construct($aPost, $results)

$oKlarnaOrder = new KlarnaPayment($oBasket, $oUser, $aPost);

$this->assertContains($results['controllerName'], $oKlarnaOrder->refreshUrl);
$this->doAssertContains($results['controllerName'], $oKlarnaOrder->refreshUrl);
$this->assertEquals($results['_sPaymentMethod'], $this->getProtectedClassProperty($oKlarnaOrder, '_sPaymentMethod'));
$this->assertEquals($results['currencyToCountryMatch'], $this->getProtectedClassProperty($oKlarnaOrder, 'currencyToCountryMatch'));
$this->assertEquals((bool)$results['error'], $oKlarnaOrder->isError());
$results['error'] && $this->assertContains($results['error'], $oKlarnaOrder->getError()[0]);
$results['error'] && $this->doAssertContains($results['error'], $oKlarnaOrder->getError()[0]);
$this->assertEquals($results['reauthorizeRequired'], $this->getSessionParam('reauthorizeRequired'));
$this->assertEquals($results['sessionValid'], $oKlarnaOrder->isSessionValid());

Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/Core/KlarnaUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testCalculateOrderAmountsPricesAndTaxes_1()
->getMock();
$item->expects($this->exactly(2))->method('isBundle')->willReturn(false);
$item->expects($this->once())->method('getUnitPrice')->willReturn($price);
$item->expects($this->once())->method('getArticle')->willReturn($article);
$item->expects($this->exactly(2))->method('getArticle')->willReturn($article);
$item->expects($this->once())->method('getRegularUnitPrice')->willReturn($priceUnit);
$result = KlarnaUtils::calculateOrderAmountsPricesAndTaxes($item, true);
$expected = [
Expand Down
45 changes: 45 additions & 0 deletions Tests/Unit/Model/KlarnaBasketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,51 @@ public function testSetKlarnaOrderLang($iLang)
$this->assertEquals($iLang, $result);
}

/**
*
*/
public function testTcklarna_calculateDeliveryCost()
{
$oBasket = $this->getMockBuilder(Basket::class)->setMethods(['getAdditionalServicesVatPercent'])->getMock();
$oBasket->expects($this->once())->method('getAdditionalServicesVatPercent')->willReturn(7.00);
$this->setConfigParam('blDeliveryVatOnTop', true);
$oBasket->setDeliveryPrice('price already set');

$result = $oBasket->tcklarna_calculateDeliveryCost();
$this->assertEquals('price already set', $result);


$oBasket->setDeliveryPrice(null);
$this->setConfigParam('blCalculateDelCostIfNotLoggedIn', false);

$result = $oBasket->tcklarna_calculateDeliveryCost();
$this->assertTrue($result instanceof Price);
$this->assertTrue($result->isNettoMode());
$this->assertEquals(0, $result->getVat());
$this->assertEquals(0, $result->getBruttoPrice());
$this->assertEquals(0, $result->getNettoPrice());
$this->assertEquals(0, $result->getVatValue());


$this->setConfigParam('blDeliveryVatOnTop', false);
$oUser = oxNew(User::class);
$oUser->load('oxdefaultadmin');
$oBasket->setBasketUser($oUser);
$oDelivery = oxNew(Delivery::class);
$oPrice = oxNew(Price::class);
$oPrice->setPrice(100.00);
$oDelivery->setDeliveryPrice($oPrice);
$oDeliveryList = $this->getMockBuilder(DeliveryList::class)->setMethods(['getDeliveryList'])->getMock();
$oDeliveryList->expects($this->once())->method('getDeliveryList')->willReturn([$oDelivery]);
UtilsObject::setClassInstance(DeliveryList::class, $oDeliveryList);

$result = $oBasket->tcklarna_calculateDeliveryCost();
$this->assertTrue($result instanceof Price);
$this->assertEquals(7, $result->getVat());
$this->assertEquals(100, $result->getBruttoPrice());
$this->assertEquals(6.54, $result->getVatValue());
}

/**
*
* @dataProvider KlarnaPaymentDeliveryDataProvider
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/Model/KlarnaUserPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testGetBadgeUrl($payId, $expectedResult, $notUsed)

$result = $userPaymentModel->getBadgeUrl();

$this->assertContains($expectedResult, $result);
$this->doAssertContains($expectedResult, $result);
}

public function paymentDataProvider()
Expand Down
Loading

0 comments on commit 0d32160

Please sign in to comment.