add initial test for SMS model

This commit is contained in:
2022-07-15 00:19:48 +02:00
gecommit door Daniel Seifert
bovenliggende a4889fe4bc
commit 7d54e545e7
6 gewijzigde bestanden met toevoegingen van 163 en 2 verwijderingen

Bestand weergeven

@ -22,6 +22,9 @@
"oxid-esales/oxideshop-ce": "6.7 - 6.10", "oxid-esales/oxideshop-ce": "6.7 - 6.10",
"d3/linkmobility-php-client": "^1.2.0" "d3/linkmobility-php-client": "^1.2.0"
}, },
"require-dev": {
"d3/modcfg": "^5.3.7.0 || ^6.0"
},
"extra": { "extra": {
"oxideshop": { "oxideshop": {
"source-directory": "/src", "source-directory": "/src",

Bestand weergeven

@ -73,7 +73,7 @@ class AdminOrder extends AdminController
{ {
$messageBody = Registry::getRequest()->getRequestEscapedParameter('messagebody'); $messageBody = Registry::getRequest()->getRequestEscapedParameter('messagebody');
if (strlen($messageBody) <= 1) { if (false === is_string($messageBody) || strlen($messageBody) <= 1) {
Registry::getUtilsView()->addErrorToDisplay( Registry::getUtilsView()->addErrorToDisplay(
Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH') Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH')
); );

Bestand weergeven

@ -72,7 +72,7 @@ class Sms
try { try {
Registry::getLogger()->debug('startRequest', ['orderId' => $order->getId()]); Registry::getLogger()->debug('startRequest', ['orderId' => $order->getId()]);
$return = $this->sendCustomRecipientMessage( $return = $this->sendCustomRecipientMessage(
[ oxNew(OrderRecipients::class, $order)->getSmsRecipient() ] [ $this->getOrderRecipient($order) ]
); );
Registry::getLogger()->debug('finishRequest', ['orderId' => $order->getId()]); Registry::getLogger()->debug('finishRequest', ['orderId' => $order->getId()]);
return $return; return $return;
@ -82,6 +82,16 @@ class Sms
} }
} }
/**
* @param Order $order
* @return Recipient
* @throws noRecipientFoundException
*/
protected function getOrderRecipient(Order $order): Recipient
{
return oxNew(OrderRecipients::class, $order)->getSmsRecipient();
}
/** /**
* @param array $recipientsArray * @param array $recipientsArray
* *

Bestand weergeven

@ -0,0 +1,52 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Linkmobility4OXID\Tests\Application\Controller\Admin;
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
class AdminOrderTest extends d3ModCfgUnitTestCase
{
/** @var AdminOrder */
protected $controller;
public function setUp()
{
parent::setUp();
$this->controller = oxNew(AdminOrder::class);
}
public function tearDown()
{
parent::tearDown();
unset($this->controller);
}
/**
* @test
* @return void
* @throws \ReflectionException
*/
public function testSend()
{
$this->callMethod(
$this->controller,
'send'
);
}
}

Bestand weergeven

@ -0,0 +1,94 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Linkmobility4OXID\Tests\Application\Model;
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder;
use D3\Linkmobility4OXID\Application\Model\Sms;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use OxidEsales\Eshop\Application\Model\Country;
use OxidEsales\Eshop\Application\Model\Order;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class SmsTest extends d3ModCfgUnitTestCase
{
/** @var Sms */
protected $model;
protected $countryId = 'countryIdNo1';
public function setUp()
{
parent::setUp();
$this->model = oxNew(Sms::class, 'demomessage');
$country = oxNew(Country::class);
$country->setId($this->countryId);
$country->assign([
'oxisoalpha2' => 'DE'
]);
$country->save();
}
public function tearDown()
{
parent::tearDown();
$country = oxNew(Country::class);
$country->delete($this->countryId);
unset($this->model);
}
/**
* @test
* @return void
* @throws ReflectionException
*/
public function testSendOrderMessage()
{
/** @var Order|MockObject $orderMock */
$orderMock = $this->getMockBuilder(Order::class)
->setMethods(['getFieldData'])
->disableOriginalConstructor()
->getMock();
$orderMock->method('getFieldData')->willReturnCallback([$this, 'orderFieldDataCallback']);
$this->assertTrue(
$this->callMethod(
$this->model,
'sendOrderMessage',
[$orderMock]
)
);
}
public function orderFieldDataCallback()
{
$aArgs = func_get_args();
switch ($aArgs[0]) {
case 'oxdelfon':
return '015792300219';
case 'oxdelcountryid':
return $this->countryId;
case 'oxbillfon':
return '015792300219';
}
$this->fail('Unknown variable '.$aArgs[0]);
}
}

Bestand weergeven

@ -7,6 +7,8 @@ See https://github.com/OXID-eSales/testing_library
### Configuration ### Configuration
Set up the module completely with your personal data (API Key, transmitter, country code). These will be used to test the successful configuration.
Please install the packages listed in the composer.json in "require-dev". Unfortunately Composer does not provide an automatic installation. Please install the packages listed in the composer.json in "require-dev". Unfortunately Composer does not provide an automatic installation.
Here is an example of Testing Library configuration file `oxideshop/test_config.yml` Here is an example of Testing Library configuration file `oxideshop/test_config.yml`