View source
<?php
namespace Drupal\Tests\commerce_payment\Unit;
use Drupal\commerce_payment\CreditCardType;
use Drupal\Tests\UnitTestCase;
class CreditCardTypeTest extends UnitTestCase {
protected $definition;
protected $type;
protected function setUp() : void {
parent::setUp();
$this->definition = [
'id' => 'dummy',
'label' => 'DummyCard',
'number_prefixes' => [
'51-55',
'500',
'222100-272099',
],
'number_lengths' => [
5,
10,
],
'security_code_length' => 6,
'uses_luhn' => FALSE,
];
$this->type = new CreditCardType($this->definition);
}
public function testGetId() {
$this
->assertEquals($this->definition['id'], $this->type
->getId());
}
public function testGetLabel() {
$this
->assertEquals($this->definition['label'], $this->type
->getLabel());
}
public function testGetNumberPrefixes() {
$this
->assertEquals($this->definition['number_prefixes'], $this->type
->getNumberPrefixes());
}
public function testGetNumberLengths() {
$this
->assertEquals($this->definition['number_lengths'], $this->type
->getNumberLengths(), 'Credit card type number length matches.');
}
public function testGetSecurityCodeLength() {
$this
->assertEquals($this->definition['security_code_length'], $this->type
->getSecurityCodeLength(), 'Credit card type security code length matches.');
}
public function testUsesLuhn() {
$this
->assertEquals($this->definition['uses_luhn'], $this->type
->usesLuhn());
}
public function testInvalidDefinition($definition, $message) {
$this
->expectException(\InvalidArgumentException::class);
$this
->expectExceptionMessage($message);
$card = new CreditCardType($definition);
}
public function definitionProvider() {
return [
[
[],
'Missing required property id.',
],
[
[
'id' => 'llama',
],
'Missing required property label.',
],
[
[
'id' => 'llama',
'label' => 'Llama',
],
'Missing required property number_prefixes.',
],
];
}
}