Skip to content

Commit

Permalink
Add a method reject and ask for a revision (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Ducoudray authored and cdaguerre committed May 30, 2016
1 parent 39ca62c commit 3b511c9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
11 changes: 11 additions & 0 deletions lib/Textmaster/Model/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,17 @@ final public function complete($satisfaction = null, $message = null)
return $this;
}

/**
* {@inheritdoc}
*/
public function reject($message)
{
$this->getApi()->supportMessages()->create($this->getProject()->getId(), $this->getId(), $message);
$this->dispatchEvent(DocumentInterface::STATUS_INCOMPLETE, $this->data);

return $this;
}

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

/**
* Ask for a revision on the document.
*
* @param string $message
*
* @return DocumentInterface
*/
public function reject($message);

/**
* Get allowed status.
*
Expand Down
27 changes: 26 additions & 1 deletion test/Textmaster/Unit/Model/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public function setUp()

$clientMock = $this->getMockBuilder('Textmaster\Client')->setMethods(array('projects'))->disableOriginalConstructor()->getMock();
$projectApiMock = $this->getMock('Textmaster\Api\Project', array('documents', 'show'), array($clientMock));
$documentApiMock = $this->getMock('Textmaster\Api\Document', array('show', 'update', 'complete'), array($clientMock, $projectId), '', false);
$documentApiMock = $this->getMock('Textmaster\Api\Document', array('show', 'update', 'complete', 'supportMessages'), array($clientMock, $projectId), '', false);
$supportMessageApiMock = $this->getMock('Textmaster\Api\Project\Document\SupportMessage', array('create'), array($clientMock), '', false);

$clientMock->method('projects')
->willReturn($projectApiMock);
Expand All @@ -82,6 +83,12 @@ public function setUp()
$documentApiMock->method('complete')
->willReturn($completeValues);

$documentApiMock->method('supportMessages')
->willReturn($supportMessageApiMock);

$supportMessageApiMock->method('create')
->willReturn(null);

$this->clientMock = $clientMock;
}

Expand Down Expand Up @@ -324,6 +331,24 @@ public function shouldComplete()
$this->assertSame(DocumentInterface::STATUS_COMPLETED, $document->getStatus());
}

/**
* @test
*/
public function shouldReject()
{
$projectId = '654321';
$valuesToCreate = array(
'id' => '123456',
'project_id' => $projectId,
);

$document = new Document($this->clientMock, $valuesToCreate);
$document->save();
$document->reject('Bad job!');

$this->assertSame('123456', $document->getId());
}

/**
* @test
* @expectedException \Textmaster\Exception\InvalidArgumentException
Expand Down

0 comments on commit 3b511c9

Please sign in to comment.