1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Payments\Mobilpay\Tests\FileLoader; |
4
|
|
|
|
5
|
|
|
use ByTIC\Payments\Mobilpay\Gateway; |
6
|
|
|
use ByTIC\Payments\Mobilpay\Tests\AbstractTest; |
7
|
|
|
use ByTIC\Payments\Mobilpay\Tests\Fixtures\MobilpayData; |
8
|
|
|
use ByTIC\Payments\Mobilpay\Tests\Fixtures\Records\PaymentMethods\PaymentMethod; |
9
|
|
|
use ByTIC\Payments\Mobilpay\Tests\Fixtures\Records\PaymentMethods\PaymentMethods; |
10
|
|
|
use ByTIC\Payments\Models\Methods\Types\CreditCards; |
11
|
|
|
use Nip\Records\Locator\ModelLocator; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class HasFileLoaderTest |
15
|
|
|
* @package ByTIC\Payments\Mobilpay\Tests\FileLoader |
16
|
|
|
*/ |
17
|
|
|
class HasFileLoaderTest extends AbstractTest |
18
|
|
|
{ |
19
|
|
|
public function testSaveToModelOptions() |
20
|
|
|
{ |
21
|
|
|
/** @var PaymentMethod $paymentMethod */ |
22
|
|
|
$paymentMethods = \Mockery::mock(PaymentMethods::class)->makePartial(); |
23
|
|
|
$paymentMethods->shouldReceive('save'); |
24
|
|
|
|
25
|
|
|
ModelLocator::set(PaymentMethods::class, $paymentMethods); |
|
|
|
|
26
|
|
|
|
27
|
|
|
$paymentMethod = new PaymentMethod(); |
28
|
|
|
|
29
|
|
|
$paymentMethod->type = 'credit-cards'; |
|
|
|
|
30
|
|
|
$options = unserialize(MobilpayData::getMethodOptions()); |
31
|
|
|
$options['mobilpay']['file'] = 'public.cer'; |
32
|
|
|
$options['mobilpay']['private-key'] = 'private.key'; |
33
|
|
|
$paymentMethod->options = serialize($options); |
34
|
|
|
|
35
|
|
|
$type = new CreditCards(); |
36
|
|
|
$type->setItem($paymentMethod); |
37
|
|
|
$paymentMethod->setType($type); |
38
|
|
|
|
39
|
|
|
$directoryPath = $paymentMethod->getFilesDirectory(); |
40
|
|
|
MobilpayData::buildCertificates(); |
41
|
|
|
self::assertDirectoryExists($directoryPath); |
42
|
|
|
|
43
|
|
|
/** @var Gateway $gateway */ |
44
|
|
|
$gateway = $paymentMethod->getType()->getGateway(); |
|
|
|
|
45
|
|
|
|
46
|
|
|
self::assertGreaterThan(5, strlen($gateway->getCertificate())); |
|
|
|
|
47
|
|
|
self::assertGreaterThan(5, strlen($gateway->getPrivateKey())); |
48
|
|
|
|
49
|
|
|
$options = $paymentMethod->getPaymentGatewayOptions(); |
50
|
|
|
|
51
|
|
|
self::assertArrayNotHasKey('file', $options); |
52
|
|
|
self::assertArrayNotHasKey('private-key', $options); |
53
|
|
|
|
54
|
|
|
self::assertGreaterThan(50, strlen($options['certificate'])); |
55
|
|
|
self::assertGreaterThan(50, strlen($options['privateKey'])); |
56
|
|
|
self::assertDirectoryNotExists($directoryPath); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|