Skip to content

Commit

Permalink
Add work template property to project (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Ducoudray authored Sep 19, 2016
1 parent 80660c0 commit f5d5406
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/test export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php_cs export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/README.md export-ignore
18 changes: 13 additions & 5 deletions lib/Textmaster/Model/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,17 @@ public function getType()
/**
* {@inheritdoc}
*/
public function getTranslatedContent()
public function getSourceContent()
{
$authorWork = $this->getProperty('author_work');
if (self::TYPE_STANDARD === $this->getType() && !empty($authorWork)) {
return $authorWork['free_text'];
}

if (ProjectInterface::ACTIVITY_COPYWRITING === $this->getProject()->getActivity()) {
return $authorWork;
}

if (self::TYPE_STANDARD === $this->getType() && !empty($authorWork)) {
return $authorWork['free_text'];
}

return $this->formatTranslatedContent();
}

Expand All @@ -211,6 +211,14 @@ public function getWordCount()
return $this->getProperty('word_count');
}

/**
* {@inheritdoc}
*/
public function setWordCount($count)
{
return $this->setProperty('word_count', $count);
}

/**
* {@inheritdoc}
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/Textmaster/Model/DocumentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ public function setOriginalContent($content);
public function getType();

/**
* Get translated content.
* Get source content.
*
* @return string|array
*/
public function getTranslatedContent();
public function getSourceContent();

/**
* Get word count.
Expand Down
17 changes: 17 additions & 0 deletions lib/Textmaster/Model/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Project extends AbstractObject implements ProjectInterface
'project_briefing',
'options',
'callback',
'work_template',
];

/**
Expand Down Expand Up @@ -197,6 +198,22 @@ public function setCallback(array $callback)
$this->data['callback'] = $callback;
}

/**
* {@inheritdoc}
*/
public function getWorkTemplate()
{
return $this->getProperty('work_template');
}

/**
* {@inheritdoc}
*/
public function setWorkTemplate($template)
{
return $this->setProperty('work_template', $template);
}

/**
* {@inheritdoc}
*/
Expand Down
16 changes: 16 additions & 0 deletions lib/Textmaster/Model/ProjectInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,22 @@ public function getCallback();
*/
public function setCallback(array $callback);

/**
* Get work template value.
*
* @return array
*/
public function getWorkTemplate();

/**
* Set work template value.
*
* @param string $template
*
* @return ProjectInterface
*/
public function setWorkTemplate($template);

/**
* Get documents.
*
Expand Down
13 changes: 7 additions & 6 deletions lib/Textmaster/Translator/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ public function create($subject, array $properties, DocumentInterface $document)
$this->failIfDoesNotSupport($subject);
$project = $document->getProject();

$language = $project->getLanguageFrom();
$content = $this->getProperties($subject, $properties, $language, $project->getActivity());

$this->setSubjectOnDocument($subject, $document);

$document->setOriginalContent($content);
if (ProjectInterface::ACTIVITY_COPYWRITING !== $project->getActivity()) {
$language = $project->getLanguageFrom();
$content = $this->getProperties($subject, $properties, $language, $project->getActivity());
$document->setOriginalContent($content);
}

return $document;
}
Expand All @@ -70,7 +71,7 @@ public function compare(DocumentInterface $document)

$translated = $this->compareContent(
$subject,
$document->getTranslatedContent(),
$document->getSourceContent(),
$this->getLanguageTo($project),
false
);
Expand All @@ -90,7 +91,7 @@ public function complete(DocumentInterface $document, $satisfaction = null, $mes
$this->failIfDoesNotSupport($subject);

/** @var array $properties */
$properties = $document->getTranslatedContent();
$properties = $document->getSourceContent();

$project = $document->getProject();
$language = $this->getLanguageTo($project);
Expand Down
2 changes: 2 additions & 0 deletions test/Textmaster/Functional/Api/ProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public function shouldCreateProject()
'language_to' => 'fr',
'category' => 'C021',
'project_briefing' => 'This project is only for testing purpose',
'work_template' => '1_title_2_paragraphs',
];

$result = $this->api->create($params);
Expand All @@ -130,6 +131,7 @@ public function shouldCreateProject()
$this->assertSame('This project is only for testing purpose', $result['project_briefing']);
$this->assertSame(ProjectInterface::STATUS_IN_CREATION, $result['status']);
$this->assertSame('api', $result['creation_channel']);
$this->assertSame('1_title_2_paragraphs', $result['work_template']['name']);

return $result['id'];
}
Expand Down
6 changes: 3 additions & 3 deletions test/Textmaster/Unit/Model/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function shouldGetTranslatedContentForStandard()
$this->assertSame(DocumentInterface::STATUS_IN_CREATION, $document->getStatus());
$this->assertSame('Text to translate.', $document->getOriginalContent());
$this->assertSame('Translating instructions.', $document->getInstructions());
$this->assertSame('Translated text.', $document->getTranslatedContent());
$this->assertSame('Translated text.', $document->getSourceContent());
}

/**
Expand Down Expand Up @@ -220,7 +220,7 @@ public function shouldGetTranslatedContentForKeyValue()
$this->assertSame(DocumentInterface::STATUS_IN_CREATION, $document->getStatus());
$this->assertSame($values['original_content'], $document->getOriginalContent());
$this->assertSame('Translating instructions.', $document->getInstructions());
$this->assertSame($values['author_work'], $document->getTranslatedContent());
$this->assertSame($values['author_work'], $document->getSourceContent());
}

/**
Expand Down Expand Up @@ -257,7 +257,7 @@ public function shouldGetTranslatedContentForCopywriting()
$this->assertSame(DocumentInterface::STATUS_IN_CREATION, $document->getStatus());
$this->assertSame($values['original_content'], $document->getOriginalContent());
$this->assertSame('Translating instructions.', $document->getInstructions());
$this->assertSame($values['author_work'], $document->getTranslatedContent());
$this->assertSame($values['author_work'], $document->getSourceContent());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function shouldCreateSameLocale()
->method('getLanguageFrom')
->willReturn('en');

$projectMock->expects($this->once())
$projectMock->expects($this->exactly(2))
->method('getActivity')
->willReturn(ProjectInterface::ACTIVITY_TRANSLATION);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function shouldComplete()
->method('getCustomData')
->willReturn(['class' => 'My\Class', 'id' => 1]);
$documentMock->expects($this->once())
->method('getTranslatedContent')
->method('getSourceContent')
->willReturn(['name' => 'my translation']);
$documentMock->expects($this->once())
->method('getProject')
Expand Down Expand Up @@ -154,7 +154,7 @@ public function shouldCompare()
->method('getOriginalContent')
->willReturn(['name' => ['original_phrase' => 'Name to translate']]);
$documentMock->expects($this->once())
->method('getTranslatedContent')
->method('getSourceContent')
->willReturn(['name' => 'Le nom à traduire']);
$documentMock->expects($this->once())
->method('getProject')
Expand Down

0 comments on commit f5d5406

Please sign in to comment.