44 lines
1.4 KiB
PHP
44 lines
1.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\OceanpaymentKlarna\Test\Unit\Model;
|
|
|
|
use Esun\OceanpaymentKlarna\Model\SecretValueDecoder;
|
|
use Magento\Framework\Encryption\EncryptorInterface;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class SecretValueDecoderTest extends TestCase
|
|
{
|
|
public function testLeavesPlainTextValueUnchanged(): void
|
|
{
|
|
$encryptor = $this->createMock(EncryptorInterface::class);
|
|
$encryptor->expects(self::never())->method('decrypt');
|
|
|
|
self::assertSame('214127', (new SecretValueDecoder($encryptor))->decode('214127'));
|
|
}
|
|
|
|
public function testDecodesSingleEncryptedValue(): void
|
|
{
|
|
$encryptor = $this->createMock(EncryptorInterface::class);
|
|
$encryptor->expects(self::once())
|
|
->method('decrypt')
|
|
->with('0:3:encrypted')
|
|
->willReturn('214127');
|
|
|
|
self::assertSame('214127', (new SecretValueDecoder($encryptor))->decode('0:3:encrypted'));
|
|
}
|
|
|
|
public function testRecoversDoubleEncryptedValue(): void
|
|
{
|
|
$encryptor = $this->createMock(EncryptorInterface::class);
|
|
$encryptor->expects(self::exactly(2))
|
|
->method('decrypt')
|
|
->willReturnMap([
|
|
['0:3:outer', '0:3:inner'],
|
|
['0:3:inner', '214127'],
|
|
]);
|
|
|
|
self::assertSame('214127', (new SecretValueDecoder($encryptor))->decode('0:3:outer'));
|
|
}
|
|
}
|