Skip to content

Commit

Permalink
JML - Add getters for created_at and updated_at (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmleroux authored and Pierre Ducoudray committed Jun 13, 2016
1 parent 25c73b9 commit 203befe
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lib/Textmaster/Model/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,42 @@ public function setCustomData($customData, $key = null)
return $this->setProperty('custom_data', $customData);
}

/**
* {@inheritdoc}
*/
public function getCreatedAt()
{
$data = $this->getProperty('created_at');

return $this->parseFullDate($data);
}

/**
* {@inheritdoc}
*/
public function getUpdatedAt()
{
$data = $this->getProperty('updated_at');

return $this->parseFullDate($data);
}

/**
* Parse Textmaster date
*
* @param array $data
*
* @return \DateTime|null
*/
private function parseFullDate($data)
{
if (null !== $data && isset($data['full'])) {
return new \DateTime($data['full']);
}

return null;
}

/**
* {@inheritdoc}
*/
Expand Down
14 changes: 14 additions & 0 deletions lib/Textmaster/Model/DocumentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ public function getCustomData($key = null);
*/
public function setCustomData($customData, $key = null);

/**
* Get create date
*
* @return \DateTime|null
*/
public function getCreatedAt();

/**
* Get update date
*
* @return \DateTime|null
*/
public function getUpdatedAt();

/**
* Complete the document.
*
Expand Down
20 changes: 20 additions & 0 deletions test/Textmaster/Unit/Model/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ public function shouldCreateFromValues()
'original_content' => 'Text to translate.',
'instructions' => 'Translating instructions.',
'project_id' => $projectId,
'created_at' => [
'day' => 9,
'month' => 6,
'year' => 2016,
'full' => '2016-06-09 10:37:40 UTC',
],
'updated_at' => [
'day' => 10,
'month' => 6,
'year' => 2016,
'full' => '2016-06-10 15:37:40 UTC',
],
);

$document = new Document($this->clientMock, $values);
Expand All @@ -141,6 +153,14 @@ public function shouldCreateFromValues()
$this->assertSame(DocumentInterface::STATUS_IN_CREATION, $document->getStatus());
$this->assertSame('Text to translate.', $document->getOriginalContent());
$this->assertSame('Translating instructions.', $document->getInstructions());

$expectedDate = new \DateTime('2016-06-09 10:37:40 UTC');
$this->assertEquals($expectedDate, $document->getCreatedAt());
$this->assertEquals('20160609 10:37:40', $document->getCreatedAt()->format('Ymd H:i:s'));

$expectedDate = new \DateTime('2016-06-10 15:37:40 UTC');
$this->assertEquals($expectedDate, $document->getUpdatedAt());
$this->assertEquals('20160610 15:37:40', $document->getUpdatedAt()->format('Ymd H:i:s'));
}

/**
Expand Down

0 comments on commit 203befe

Please sign in to comment.