Skip to content

Commit f5d5406

Browse files
author
Pierre Ducoudray
authored
Add work template property to project (#85)
1 parent 80660c0 commit f5d5406

File tree

10 files changed

+64
-19
lines changed

10 files changed

+64
-19
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/test export-ignore
55
/.gitattributes export-ignore
66
/.gitignore export-ignore
7+
/.php_cs export-ignore
78
/.travis.yml export-ignore
89
/phpunit.xml.dist export-ignore
910
/README.md export-ignore

lib/Textmaster/Model/Document.php

+13-5
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,17 @@ public function getType()
189189
/**
190190
* {@inheritdoc}
191191
*/
192-
public function getTranslatedContent()
192+
public function getSourceContent()
193193
{
194194
$authorWork = $this->getProperty('author_work');
195-
if (self::TYPE_STANDARD === $this->getType() && !empty($authorWork)) {
196-
return $authorWork['free_text'];
197-
}
198-
199195
if (ProjectInterface::ACTIVITY_COPYWRITING === $this->getProject()->getActivity()) {
200196
return $authorWork;
201197
}
202198

199+
if (self::TYPE_STANDARD === $this->getType() && !empty($authorWork)) {
200+
return $authorWork['free_text'];
201+
}
202+
203203
return $this->formatTranslatedContent();
204204
}
205205

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

214+
/**
215+
* {@inheritdoc}
216+
*/
217+
public function setWordCount($count)
218+
{
219+
return $this->setProperty('word_count', $count);
220+
}
221+
214222
/**
215223
* {@inheritdoc}
216224
*/

lib/Textmaster/Model/DocumentInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ public function setOriginalContent($content);
122122
public function getType();
123123

124124
/**
125-
* Get translated content.
125+
* Get source content.
126126
*
127127
* @return string|array
128128
*/
129-
public function getTranslatedContent();
129+
public function getSourceContent();
130130

131131
/**
132132
* Get word count.

lib/Textmaster/Model/Project.php

+17
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Project extends AbstractObject implements ProjectInterface
4040
'project_briefing',
4141
'options',
4242
'callback',
43+
'work_template',
4344
];
4445

4546
/**
@@ -197,6 +198,22 @@ public function setCallback(array $callback)
197198
$this->data['callback'] = $callback;
198199
}
199200

201+
/**
202+
* {@inheritdoc}
203+
*/
204+
public function getWorkTemplate()
205+
{
206+
return $this->getProperty('work_template');
207+
}
208+
209+
/**
210+
* {@inheritdoc}
211+
*/
212+
public function setWorkTemplate($template)
213+
{
214+
return $this->setProperty('work_template', $template);
215+
}
216+
200217
/**
201218
* {@inheritdoc}
202219
*/

lib/Textmaster/Model/ProjectInterface.php

+16
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,22 @@ public function getCallback();
193193
*/
194194
public function setCallback(array $callback);
195195

196+
/**
197+
* Get work template value.
198+
*
199+
* @return array
200+
*/
201+
public function getWorkTemplate();
202+
203+
/**
204+
* Set work template value.
205+
*
206+
* @param string $template
207+
*
208+
* @return ProjectInterface
209+
*/
210+
public function setWorkTemplate($template);
211+
196212
/**
197213
* Get documents.
198214
*

lib/Textmaster/Translator/Adapter/AbstractAdapter.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ public function create($subject, array $properties, DocumentInterface $document)
3939
$this->failIfDoesNotSupport($subject);
4040
$project = $document->getProject();
4141

42-
$language = $project->getLanguageFrom();
43-
$content = $this->getProperties($subject, $properties, $language, $project->getActivity());
44-
4542
$this->setSubjectOnDocument($subject, $document);
4643

47-
$document->setOriginalContent($content);
44+
if (ProjectInterface::ACTIVITY_COPYWRITING !== $project->getActivity()) {
45+
$language = $project->getLanguageFrom();
46+
$content = $this->getProperties($subject, $properties, $language, $project->getActivity());
47+
$document->setOriginalContent($content);
48+
}
4849

4950
return $document;
5051
}
@@ -70,7 +71,7 @@ public function compare(DocumentInterface $document)
7071

7172
$translated = $this->compareContent(
7273
$subject,
73-
$document->getTranslatedContent(),
74+
$document->getSourceContent(),
7475
$this->getLanguageTo($project),
7576
false
7677
);
@@ -90,7 +91,7 @@ public function complete(DocumentInterface $document, $satisfaction = null, $mes
9091
$this->failIfDoesNotSupport($subject);
9192

9293
/** @var array $properties */
93-
$properties = $document->getTranslatedContent();
94+
$properties = $document->getSourceContent();
9495

9596
$project = $document->getProject();
9697
$language = $this->getLanguageTo($project);

test/Textmaster/Functional/Api/ProjectTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public function shouldCreateProject()
117117
'language_to' => 'fr',
118118
'category' => 'C021',
119119
'project_briefing' => 'This project is only for testing purpose',
120+
'work_template' => '1_title_2_paragraphs',
120121
];
121122

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

134136
return $result['id'];
135137
}

test/Textmaster/Unit/Model/DocumentTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function shouldGetTranslatedContentForStandard()
187187
$this->assertSame(DocumentInterface::STATUS_IN_CREATION, $document->getStatus());
188188
$this->assertSame('Text to translate.', $document->getOriginalContent());
189189
$this->assertSame('Translating instructions.', $document->getInstructions());
190-
$this->assertSame('Translated text.', $document->getTranslatedContent());
190+
$this->assertSame('Translated text.', $document->getSourceContent());
191191
}
192192

193193
/**
@@ -220,7 +220,7 @@ public function shouldGetTranslatedContentForKeyValue()
220220
$this->assertSame(DocumentInterface::STATUS_IN_CREATION, $document->getStatus());
221221
$this->assertSame($values['original_content'], $document->getOriginalContent());
222222
$this->assertSame('Translating instructions.', $document->getInstructions());
223-
$this->assertSame($values['author_work'], $document->getTranslatedContent());
223+
$this->assertSame($values['author_work'], $document->getSourceContent());
224224
}
225225

226226
/**
@@ -257,7 +257,7 @@ public function shouldGetTranslatedContentForCopywriting()
257257
$this->assertSame(DocumentInterface::STATUS_IN_CREATION, $document->getStatus());
258258
$this->assertSame($values['original_content'], $document->getOriginalContent());
259259
$this->assertSame('Translating instructions.', $document->getInstructions());
260-
$this->assertSame($values['author_work'], $document->getTranslatedContent());
260+
$this->assertSame($values['author_work'], $document->getSourceContent());
261261
}
262262

263263
/**

test/Textmaster/Unit/Translator/Adapter/GedmoTranslatableAdapterTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function shouldCreateSameLocale()
4343
->method('getLanguageFrom')
4444
->willReturn('en');
4545

46-
$projectMock->expects($this->once())
46+
$projectMock->expects($this->exactly(2))
4747
->method('getActivity')
4848
->willReturn(ProjectInterface::ACTIVITY_TRANSLATION);
4949

test/Textmaster/Unit/Translator/Adapter/SyliusTranslatableAdapterTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function shouldComplete()
9494
->method('getCustomData')
9595
->willReturn(['class' => 'My\Class', 'id' => 1]);
9696
$documentMock->expects($this->once())
97-
->method('getTranslatedContent')
97+
->method('getSourceContent')
9898
->willReturn(['name' => 'my translation']);
9999
$documentMock->expects($this->once())
100100
->method('getProject')
@@ -154,7 +154,7 @@ public function shouldCompare()
154154
->method('getOriginalContent')
155155
->willReturn(['name' => ['original_phrase' => 'Name to translate']]);
156156
$documentMock->expects($this->once())
157-
->method('getTranslatedContent')
157+
->method('getSourceContent')
158158
->willReturn(['name' => 'Le nom à traduire']);
159159
$documentMock->expects($this->once())
160160
->method('getProject')

0 commit comments

Comments
 (0)