add initial test for SMS model
This commit is contained in:
parent
a4889fe4bc
commit
7d54e545e7
@ -22,6 +22,9 @@
|
||||
"oxid-esales/oxideshop-ce": "6.7 - 6.10",
|
||||
"d3/linkmobility-php-client": "^1.2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"d3/modcfg": "^5.3.7.0 || ^6.0"
|
||||
},
|
||||
"extra": {
|
||||
"oxideshop": {
|
||||
"source-directory": "/src",
|
||||
|
@ -73,7 +73,7 @@ class AdminOrder extends AdminController
|
||||
{
|
||||
$messageBody = Registry::getRequest()->getRequestEscapedParameter('messagebody');
|
||||
|
||||
if (strlen($messageBody) <= 1) {
|
||||
if (false === is_string($messageBody) || strlen($messageBody) <= 1) {
|
||||
Registry::getUtilsView()->addErrorToDisplay(
|
||||
Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH')
|
||||
);
|
||||
|
@ -72,7 +72,7 @@ class Sms
|
||||
try {
|
||||
Registry::getLogger()->debug('startRequest', ['orderId' => $order->getId()]);
|
||||
$return = $this->sendCustomRecipientMessage(
|
||||
[ oxNew(OrderRecipients::class, $order)->getSmsRecipient() ]
|
||||
[ $this->getOrderRecipient($order) ]
|
||||
);
|
||||
Registry::getLogger()->debug('finishRequest', ['orderId' => $order->getId()]);
|
||||
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
|
||||
*
|
||||
|
52
tests/Application/Controller/Admin/AdminOrderTest.php
Normal file
52
tests/Application/Controller/Admin/AdminOrderTest.php
Normal file
@ -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'
|
||||
);
|
||||
}
|
||||
}
|
94
tests/Application/Model/SmsTest.php
Normal file
94
tests/Application/Model/SmsTest.php
Normal file
@ -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]);
|
||||
}
|
||||
}
|
@ -7,6 +7,8 @@ See https://github.com/OXID-eSales/testing_library
|
||||
|
||||
### 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.
|
||||
|
||||
Here is an example of Testing Library configuration file `oxideshop/test_config.yml`
|
||||
|
Loading…
Reference in New Issue
Block a user