View source
<?php
namespace Drupal\Tests\feeds\Unit\Feeds\Target;
use Drupal\feeds\Feeds\Target\Telephone;
class TelephoneTest extends FieldTargetTestBase {
protected function getTargetClass() {
return Telephone::class;
}
public function testPrepareValue($expected, $value) {
$method = $this
->getMethod('Drupal\\feeds\\Feeds\\Target\\Telephone', 'prepareTarget')
->getClosure();
$field_definition = $this
->getMockFieldDefinition();
$field_definition
->expects($this
->any())
->method('getType')
->will($this
->returnValue('string'));
$configuration = [
'feed_type' => $this
->createMock('Drupal\\feeds\\FeedTypeInterface'),
'target_definition' => $method($field_definition),
];
$target = new Telephone($configuration, 'telephone', []);
$method = $this
->getProtectedClosure($target, 'prepareValue');
$values = [
'value' => $value,
];
$method(0, $values);
$this
->assertSame($expected, $values['value']);
}
public function dataProviderPrepareValue() {
return [
[
'string',
'string',
],
[
'',
'',
],
[
'+49123456789',
'+49123456789',
],
[
'+49 123 456789',
'+49 123 456789',
],
[
'+49 123 456789-0',
'+49 123 456789-0',
],
[
'+49 (0)123 456789-0',
'+49 (0)123 456789-0',
],
[
'+123456789123456789',
'+123456789123456789',
],
[
'+41 1234567',
'+41 1234567',
],
[
'+41 10000000000000000000',
'+41 10000000000000000000',
],
];
}
}