linkmobility4oxid/src/tests/unit/Application/Controller/Admin/AdminOrderTest.php

104 lines
3.4 KiB
PHP
Raw Normal View History

2022-12-26 00:20:16 +01:00
<?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\unit\Application\Controller\Admin;
2022-12-31 00:29:59 +01:00
use D3\DIContainerHandler\d3DicHandler;
2022-12-26 00:20:16 +01:00
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder;
use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException;
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
use D3\Linkmobility4OXID\Application\Model\OrderRecipients;
use D3\TestingTools\Development\CanAccessRestricted;
use OxidEsales\Eshop\Application\Model\Order;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
2022-12-28 00:09:24 +01:00
class AdminOrderTest extends AdminSend
2022-12-26 00:20:16 +01:00
{
use CanAccessRestricted;
2022-12-28 00:09:24 +01:00
protected $subjectUnderTestClass = AdminOrder::class;
protected $itemClass = Order::class;
protected $itemRecipientClass = OrderRecipients::class;
2022-12-26 00:20:16 +01:00
2022-12-31 00:29:59 +01:00
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder::__construct
*/
public function canConstruct()
{
/** @var Order|MockObject $itemMock */
$itemMock = $this->getMockBuilder($this->itemClass)
->onlyMethods(['load'])
->getMock();
$itemMock->method('load')->willReturn(true);
2023-01-03 11:20:12 +01:00
d3GetOxidDIC()->set('d3ox.linkmobility.'.Order::class, $itemMock);
2022-12-31 00:29:59 +01:00
$sut = parent::canConstruct();
$this->assertSame(
$itemMock,
$this->getValue(
$sut,
'item'
)
);
}
2022-12-26 00:20:16 +01:00
/**
* @test
2022-12-28 00:09:24 +01:00
* @param $canSendItemMessage
2022-12-26 00:20:16 +01:00
* @return void
* @throws ReflectionException
* @covers \D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder::sendMessage
* @dataProvider canSendMessageDataProvider
*/
2022-12-28 00:09:24 +01:00
public function canSendMessage($canSendItemMessage)
2022-12-26 00:20:16 +01:00
{
/** @var Sms|MockObject $smsMock */
$smsMock = $this->getMockBuilder(Sms::class)
->disableOriginalConstructor()
->onlyMethods(['sendOrderMessage'])
->getMock();
2022-12-28 00:09:24 +01:00
$smsMock->expects($this->once())->method('sendOrderMessage')->willReturn($canSendItemMessage);
2023-01-03 11:20:12 +01:00
d3GetOxidDIC()->set(Sms::class, $smsMock);
2022-12-26 00:20:16 +01:00
/** @var AdminOrder|MockObject $sut */
$sut = $this->getMockBuilder(AdminOrder::class)
->disableOriginalConstructor()
2022-12-31 00:29:59 +01:00
->onlyMethods(['getMessageBody', 'getSuccessSentMessage', 'getUnsuccessfullySentMessage'])
2022-12-26 00:20:16 +01:00
->getMock();
$sut->method('getMessageBody')->willReturn('messageBodyFixture');
2022-12-28 00:09:24 +01:00
$sut->expects($this->exactly((int) $canSendItemMessage))->method('getSuccessSentMessage')
2022-12-26 00:20:16 +01:00
->willReturn(oxNew(successfullySentException::class, 'expectedReturn'));
2022-12-28 00:09:24 +01:00
$sut->expects($this->exactly((int) !$canSendItemMessage))->method('getUnsuccessfullySentMessage')
2022-12-26 00:20:16 +01:00
->willReturn('expectedReturn');
2022-12-28 00:09:24 +01:00
$this->setValue(
$sut,
'item',
oxNew($this->itemClass)
2022-12-26 00:20:16 +01:00
);
$this->assertIsString(
$this->callMethod(
$sut,
2022-12-28 00:09:24 +01:00
'sendMessage'
2022-12-26 00:20:16 +01:00
)
);
}
}