You are here

public function TimestampTest::testPrepareValue in Feeds 8.3

@covers ::prepareValue

File

tests/src/Unit/Feeds/Target/TimestampTest.php, line 23

Class

TimestampTest
@coversDefaultClass \Drupal\feeds\Feeds\Target\Timestamp @group feeds

Namespace

Drupal\Tests\feeds\Unit\Feeds\Target

Code

public function testPrepareValue() {
  $method = $this
    ->getMethod(Timestamp::class, 'prepareTarget')
    ->getClosure();
  $target_definition = $method($this
    ->getMockFieldDefinition());
  $configuration = [
    'feed_type' => $this
      ->createMock('Drupal\\feeds\\FeedTypeInterface'),
    'target_definition' => $target_definition,
  ];
  $target = new Timestamp($configuration, 'timestamp', []);
  $method = $this
    ->getProtectedClosure($target, 'prepareValue');

  // Test valid timestamp.
  $values = [
    'value' => 1411606273,
  ];
  $method(0, $values);
  $this
    ->assertSame($values['value'], 1411606273);

  // Test year value.
  $values = [
    'value' => 2000,
  ];
  $method(0, $values);
  $this
    ->assertSame($values['value'], strtotime('2000-01-01T00:00:00Z'));

  // Test invalid value.
  $values = [
    'value' => 'abc',
  ];
  $method(0, $values);
  $this
    ->assertSame($values['value'], '');
}