Fix tests
This commit is contained in:
parent
c8f8fe16cb
commit
6cea36b050
16 changed files with 74 additions and 49 deletions
|
@ -79,13 +79,17 @@ class Customer implements CustomerManagerInterface
|
|||
'index' => $billing->getPostcode(),
|
||||
'region' => $billing->getRegion(),
|
||||
'city' => $billing->getCity(),
|
||||
'street' => $billing->getStreet(),
|
||||
'street' => is_array($billing->getStreet())
|
||||
? implode(', ', $billing->getStreet())
|
||||
: $billing->getStreet(),
|
||||
'text' => sprintf(
|
||||
'%s %s %s %s',
|
||||
$billing->getPostcode(),
|
||||
$billing->getRegion(),
|
||||
$billing->getCity(),
|
||||
$billing->getStreet()
|
||||
is_array($billing->getStreet())
|
||||
? implode(', ', $billing->getStreet())
|
||||
: $billing->getStreet()
|
||||
)
|
||||
]
|
||||
];
|
||||
|
|
|
@ -20,8 +20,9 @@ class FieldsetTest extends TestCase
|
|||
protected $testElementId = 'test_element_id';
|
||||
protected $testFieldSetCss = 'test_fieldset_css';
|
||||
protected $objectFactory;
|
||||
protected $secureRenderer;
|
||||
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
|
||||
$factoryMock = $this->createMock(\Magento\Framework\Data\Form\Element\Factory::class);
|
||||
|
@ -88,6 +89,20 @@ class FieldsetTest extends TestCase
|
|||
$factoryCollection->expects($this->any())->method('create')->willReturn($elementCollection);
|
||||
$rendererMock = $this->createMock(\Magento\Framework\Data\Form\Element\Renderer\RendererInterface::class);
|
||||
|
||||
$this->secureRenderer = $this->createMock(\Magento\Framework\View\Helper\SecureHtmlRenderer::class);
|
||||
$this->secureRenderer->method('renderEventListenerAsTag')
|
||||
->willReturnCallback(
|
||||
function (string $event, string $js, string $selector): string {
|
||||
return "<script>document.querySelector('$selector').$event = function () { $js };</script>";
|
||||
}
|
||||
);
|
||||
$this->secureRenderer->method('renderStyleAsTag')
|
||||
->willReturnCallback(
|
||||
function (string $style, string $selector): string {
|
||||
return "<style>$selector { $style }</style>";
|
||||
}
|
||||
);
|
||||
|
||||
$this->urlModelMock = $this->createMock(\Magento\Backend\Model\Url::class);
|
||||
$this->layoutMock = $this->createMock(\Magento\Framework\View\Layout::class);
|
||||
$this->groupMock = $this->createMock(\Magento\Config\Model\Config\Structure\Element\Group::class);
|
||||
|
@ -100,7 +115,8 @@ class FieldsetTest extends TestCase
|
|||
$this->helperMock = $this->createMock(\Magento\Framework\View\Helper\Js::class);
|
||||
$this->form = $this->createPartialMock(
|
||||
\Magento\Config\Block\System\Config\Form::class,
|
||||
['getElements', 'getRequest']
|
||||
//['getElements', 'getRequest']
|
||||
['getRequest']
|
||||
);
|
||||
//$this->form->expects($this->any())->method('getElements')->willReturn($elementCollection);
|
||||
$this->form->expects($this->any())->method('getRequest')->willReturn($this->requestMock);
|
||||
|
|
|
@ -8,7 +8,7 @@ if (!class_exists('\PHPUnit\Framework\TestCase')) {
|
|||
|
||||
abstract class TestCase extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function createMock($originalClassName)
|
||||
public function createMock(string $originalClassName): \PHPUnit\Framework\MockObject\MockObject
|
||||
{
|
||||
if (method_exists(\PHPUnit\Framework\TestCase::class, 'createMock')) {
|
||||
return parent::createMock($originalClassName);
|
||||
|
@ -40,7 +40,7 @@ if (!class_exists('\PHPUnit\Framework\TestCase')) {
|
|||
|
||||
abstract class TestCase extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function createMock($originalClassName)
|
||||
public function createMock(string $originalClassName): \PHPUnit\Framework\MockObject\MockObject
|
||||
{
|
||||
if (method_exists(\PHPUnit\Framework\TestCase::class, 'createMock')) {
|
||||
return parent::createMock($originalClassName);
|
||||
|
|
|
@ -52,7 +52,8 @@ class PaymentTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest
|
|||
'client' => $client,
|
||||
'paymentConfig' => $paymentConfig,
|
||||
'context' => $this->context,
|
||||
'objectFactory' => $this->objectFactory
|
||||
'objectFactory' => $this->objectFactory,
|
||||
'secureRenderer' => $this->secureRenderer
|
||||
];
|
||||
|
||||
$payment = $this->objectManager->getObject(
|
||||
|
@ -65,15 +66,15 @@ class PaymentTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest
|
|||
|
||||
$html = $payment->render($this->elementMock);
|
||||
|
||||
$this->assertContains($this->testElementId, $html);
|
||||
$this->assertContains($this->testFieldSetCss, $html);
|
||||
$this->assertStringContainsString($this->testElementId, $html);
|
||||
$this->assertStringContainsString($this->testFieldSetCss, $html);
|
||||
|
||||
if (!$isConfigured) {
|
||||
$expected = sprintf(
|
||||
'<div style="margin-left: 15px;"><b><i>%s</i></b></div>',
|
||||
__('Enter API of your URL and API key')
|
||||
);
|
||||
$this->assertContains($expected, $html);
|
||||
$this->assertStringContainsString($expected, $html);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,8 @@ class ShippingTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest
|
|||
'client' => $client,
|
||||
'shippingConfig' => $shippingConfig,
|
||||
'context' => $this->context,
|
||||
'objectFactory' => $this->objectFactory
|
||||
'objectFactory' => $this->objectFactory,
|
||||
'secureRenderer' => $this->secureRenderer
|
||||
];
|
||||
|
||||
$shipping = $this->objectManager->getObject(
|
||||
|
@ -65,15 +66,15 @@ class ShippingTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest
|
|||
|
||||
$html = $shipping->render($this->elementMock);
|
||||
|
||||
$this->assertContains($this->testElementId, $html);
|
||||
$this->assertContains($this->testFieldSetCss, $html);
|
||||
$this->assertStringContainsString($this->testElementId, $html);
|
||||
$this->assertStringContainsString($this->testFieldSetCss, $html);
|
||||
|
||||
if (!$isConfigured) {
|
||||
$expected = sprintf(
|
||||
'<div style="margin-left: 15px;"><b><i>%s</i></b></div>',
|
||||
__('Enter API of your URL and API key')
|
||||
);
|
||||
$this->assertContains($expected, $html);
|
||||
$this->assertStringContainsString($expected, $html);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,8 @@ class SiteTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest
|
|||
'data' => ['group' => $this->groupMock],
|
||||
'client' => $client,
|
||||
'context' => $this->context,
|
||||
'objectFactory' => $this->objectFactory
|
||||
'objectFactory' => $this->objectFactory,
|
||||
'secureRenderer' => $this->secureRenderer
|
||||
];
|
||||
|
||||
$site = $this->objectManager->getObject(
|
||||
|
@ -56,15 +57,15 @@ class SiteTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest
|
|||
|
||||
$html = $site->render($this->elementMock);
|
||||
|
||||
$this->assertContains($this->testElementId, $html);
|
||||
$this->assertContains($this->testFieldSetCss, $html);
|
||||
$this->assertStringContainsString($this->testElementId, $html);
|
||||
$this->assertStringContainsString($this->testFieldSetCss, $html);
|
||||
|
||||
if (!$isConfigured) {
|
||||
$expected = sprintf(
|
||||
'<div style="margin-left: 15px;"><b><i>%s</i></b></div>',
|
||||
__('Enter API of your URL and API key')
|
||||
);
|
||||
$this->assertContains($expected, $html);
|
||||
$this->assertStringContainsString($expected, $html);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,8 @@ class SitesTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest
|
|||
'client' => $client,
|
||||
'storeManager' => $storeManager,
|
||||
'context' => $this->context,
|
||||
'objectFactory' => $this->objectFactory
|
||||
'objectFactory' => $this->objectFactory,
|
||||
'secureRenderer' => $this->secureRenderer
|
||||
];
|
||||
|
||||
$sites = $this->objectManager->getObject(
|
||||
|
@ -68,15 +69,15 @@ class SitesTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest
|
|||
|
||||
$html = $sites->render($this->elementMock);
|
||||
|
||||
$this->assertContains($this->testElementId, $html);
|
||||
$this->assertContains($this->testFieldSetCss, $html);
|
||||
$this->assertStringContainsString($this->testElementId, $html);
|
||||
$this->assertStringContainsString($this->testFieldSetCss, $html);
|
||||
|
||||
if (!$isConfigured) {
|
||||
$expected = sprintf(
|
||||
'<div style="margin-left: 15px;"><b><i>%s</i></b></div>',
|
||||
__('Enter API of your URL and API key')
|
||||
);
|
||||
$this->assertContains($expected, $html);
|
||||
$this->assertStringContainsString($expected, $html);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,8 @@ class StatusTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest
|
|||
'client' => $client,
|
||||
'statusCollection' => $statusCollection,
|
||||
'context' => $this->context,
|
||||
'objectFactory' => $this->objectFactory
|
||||
'objectFactory' => $this->objectFactory,
|
||||
'secureRenderer' => $this->secureRenderer
|
||||
];
|
||||
|
||||
$status = $this->objectManager->getObject(
|
||||
|
@ -65,15 +66,15 @@ class StatusTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest
|
|||
|
||||
$html = $status->render($this->elementMock);
|
||||
|
||||
$this->assertContains($this->testElementId, $html);
|
||||
$this->assertContains($this->testFieldSetCss, $html);
|
||||
$this->assertStringContainsString($this->testElementId, $html);
|
||||
$this->assertStringContainsString($this->testFieldSetCss, $html);
|
||||
|
||||
if (!$isConfigured) {
|
||||
$expected = sprintf(
|
||||
'<div style="margin-left: 15px;"><b><i>%s</i></b></div>',
|
||||
__('Enter API of your URL and API key')
|
||||
);
|
||||
$this->assertContains($expected, $html);
|
||||
$this->assertStringContainsString($expected, $html);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ class DaemonCollectorTest extends TestCase
|
|||
|
||||
const SITE_KEY = 'RC-XXXXXXX-X';
|
||||
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
$context = $this->createMock(\Magento\Framework\View\Element\Template\Context::class);
|
||||
$customerSession = $this->createMock(\Magento\Customer\Model\Session::class);
|
||||
|
@ -57,11 +57,11 @@ class DaemonCollectorTest extends TestCase
|
|||
|
||||
$js = $this->unit->buildScript()->getJs();
|
||||
|
||||
$this->assertContains('<script type="text/javascript">', $js);
|
||||
$this->assertContains('</script>', $js);
|
||||
$this->assertContains('_rc(\'send\', \'pageView\');', $js);
|
||||
$this->assertContains(self::SITE_KEY, $js);
|
||||
$this->assertContains('customerId', $js);
|
||||
$this->assertStringContainsString('<script type="text/javascript">', $js);
|
||||
$this->assertStringContainsString('</script>', $js);
|
||||
$this->assertStringContainsString('_rc(\'send\', \'pageView\');', $js);
|
||||
$this->assertStringContainsString(self::SITE_KEY, $js);
|
||||
$this->assertStringContainsString('customerId', $js);
|
||||
}
|
||||
|
||||
public function testGetJSWithoutCustomer()
|
||||
|
@ -72,10 +72,10 @@ class DaemonCollectorTest extends TestCase
|
|||
|
||||
$js = $this->unit->buildScript()->getJs();
|
||||
|
||||
$this->assertContains('<script type="text/javascript">', $js);
|
||||
$this->assertContains('</script>', $js);
|
||||
$this->assertContains('_rc(\'send\', \'pageView\');', $js);
|
||||
$this->assertContains(self::SITE_KEY, $js);
|
||||
$this->assertNotContains('customerId', $js);
|
||||
$this->assertStringContainsString('<script type="text/javascript">', $js);
|
||||
$this->assertStringContainsString('</script>', $js);
|
||||
$this->assertStringContainsString('_rc(\'send\', \'pageView\');', $js);
|
||||
$this->assertStringContainsString(self::SITE_KEY, $js);
|
||||
$this->assertStringNotContainsString('customerId', $js);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class CustomerTest extends TestCase
|
|||
private $helper;
|
||||
private $mockServiceCustomer;
|
||||
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->mockApi = $this->getMockBuilder(\Retailcrm\Retailcrm\Helper\Proxy::class)
|
||||
->disableOriginalConstructor()
|
||||
|
|
|
@ -25,7 +25,7 @@ class OrderCreateTest extends TestCase
|
|||
private $mockServiceCustomer;
|
||||
private $mockCustomer;
|
||||
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->mockApi = $this->getMockBuilder(\Retailcrm\Retailcrm\Helper\Proxy::class)
|
||||
->disableOriginalConstructor()
|
||||
|
|
|
@ -16,7 +16,7 @@ class OrderUpdateTest extends TestCase
|
|||
private $mockPayment;
|
||||
private $registry;
|
||||
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->mockApi = $this->getMockBuilder(\Retailcrm\Retailcrm\Helper\Proxy::class)
|
||||
->disableOriginalConstructor()
|
||||
|
|
|
@ -12,7 +12,7 @@ class CustomerTest extends TestCase
|
|||
private $mockOrder;
|
||||
private $mockBillingAddress;
|
||||
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->mockData = $this->getMockBuilder(\Retailcrm\Retailcrm\Helper\Data::class)
|
||||
->disableOriginalConstructor()
|
||||
|
@ -72,14 +72,14 @@ class CustomerTest extends TestCase
|
|||
$result = $this->unit->prepareCustomerFromOrder($this->mockOrder);
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertInternalType('array', $result);
|
||||
$this->assertIsArray($result);
|
||||
$this->assertArrayNotHasKey('externalId', $result);
|
||||
$this->assertArrayHasKey('email', $result);
|
||||
$this->assertArrayHasKey('firstName', $result);
|
||||
$this->assertArrayHasKey('lastName', $result);
|
||||
$this->assertArrayHasKey('patronymic', $result);
|
||||
$this->assertArrayHasKey('address', $result);
|
||||
$this->assertInternalType('array', $result['address']);
|
||||
$this->assertIsArray($result['address']);
|
||||
$this->assertArrayHasKey('countryIso', $result['address']);
|
||||
$this->assertArrayHasKey('index', $result['address']);
|
||||
$this->assertArrayHasKey('region', $result['address']);
|
||||
|
@ -167,7 +167,7 @@ class CustomerTest extends TestCase
|
|||
$result = $this->unit->process($this->mockCustomer);
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertInternalType('array', $result);
|
||||
$this->assertIsArray($result);
|
||||
$this->assertArrayHasKey('externalId', $result);
|
||||
$this->assertNotEmpty($result['externalId']);
|
||||
$this->assertEquals($this->getAfterSaveCustomerTestData()['id'], $result['externalId']);
|
||||
|
|
|
@ -13,7 +13,7 @@ class IntegrationModuleTest extends TestCase
|
|||
|
||||
const ACCOUNT_URL = 'test';
|
||||
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->mockData = $this->getMockBuilder(\Retailcrm\Retailcrm\Helper\Data::class)
|
||||
->disableOriginalConstructor()
|
||||
|
@ -76,7 +76,7 @@ class IntegrationModuleTest extends TestCase
|
|||
$configuration['logo']
|
||||
);
|
||||
$this->assertArrayHasKey('code', $configuration);
|
||||
$this->assertContains(
|
||||
$this->assertStringContainsString(
|
||||
\Retailcrm\Retailcrm\Model\Service\IntegrationModule::INTEGRATION_CODE,
|
||||
$configuration['code']
|
||||
);
|
||||
|
@ -90,7 +90,7 @@ class IntegrationModuleTest extends TestCase
|
|||
$this->assertArrayHasKey('accountUrl', $configuration);
|
||||
$this->assertEquals(self::ACCOUNT_URL, $configuration['accountUrl']);
|
||||
$this->assertArrayHasKey('integrationCode', $configuration);
|
||||
$this->assertContains(
|
||||
$this->assertStringContainsString(
|
||||
\Retailcrm\Retailcrm\Model\Service\IntegrationModule::INTEGRATION_CODE,
|
||||
$configuration['integrationCode']
|
||||
);
|
||||
|
|
|
@ -11,7 +11,7 @@ class InventoriesUploadTest extends TestCase
|
|||
private $mockResponse;
|
||||
private $mockProduct;
|
||||
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->mockApi = $this->getMockBuilder(\Retailcrm\Retailcrm\Helper\Proxy::class)
|
||||
->disableOriginalConstructor()
|
||||
|
|
|
@ -13,7 +13,7 @@ class OrderTest extends TestCase
|
|||
private $mockOrder;
|
||||
private $unit;
|
||||
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->mockProductRepository = $this->getMockBuilder(\Magento\Catalog\Model\ProductRepository::class)
|
||||
->disableOriginalConstructor()
|
||||
|
|
Loading…
Add table
Reference in a new issue