Skip to content

Commit

Permalink
Add option to use my favorite authors to do a project (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
LaetitiaRiffaud authored and Pierre Ducoudray committed May 23, 2017
1 parent 1e8e2cf commit cf5cad1
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 32 deletions.
3 changes: 1 addition & 2 deletions Features/Context/TranslationContextTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function createTranslationProject(TableNode $table)
json_decode($data['options'], true),
isset($data['activity']) ? $data['activity'] : null,
isset($data['workTemplate']) ? $data['workTemplate'] : null,
json_decode($data['textmasters'], true)
json_decode($data['useMyTextmasters'])
);

if (null !== $project) {
Expand All @@ -111,7 +111,6 @@ public function createTranslationProject(TableNode $table)
PHPUnit_Framework_Assert::assertSame($data['category'], $project->getCategory());
PHPUnit_Framework_Assert::assertSame($data['briefing'], $project->getBriefing());
PHPUnit_Framework_Assert::assertSame(json_decode($data['options'], true), $project->getOptions());
PHPUnit_Framework_Assert::assertSame(json_decode($data['textmasters'], true), $project->getTextmasters());
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions Features/copywriting.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Feature: Copywriting management
| Hello NYC | NYC is the big apple | en |
Then I should have "0" translatables with job for class "Worldia\Bundle\ProductTestBundle\Entity\Product" and locale en
When I generate a translation batch with the following parameters:
| finder | filter | name | languageFrom | category | briefing | options | activity | textmasters |
| product | {} | PROJECT-1 | en | C054 | Nothing | {"language_level": "premium"} | copywriting | [] |
| finder | filter | name | languageFrom | category | briefing | options | activity | useMyTextmasters |
| product | {} | PROJECT-1 | en | C054 | Nothing | {"language_level": "premium"} | copywriting | false |
Then I should have "2" translatables with job for class "Worldia\Bundle\ProductTestBundle\Entity\Product" and locale en
When I receive the request '{ "id": "PROJECT-1", "name": "PROJECT-1", "status": "in_progress"}'
Then I should have the following jobs:
Expand All @@ -33,14 +33,14 @@ Feature: Copywriting management
| title | description | locale |
| Super title | Super description | en |
When I generate a translation batch with the following parameters:
| finder | filter | name | languageFrom | category | briefing | options | activity | textmasters |
| product | {} | PROJECT-1 | en | C054 | Nothing | {"language_level": "premium"} | copywriting | [] |
| finder | filter | name | languageFrom | category | briefing | options | activity | useMyTextmasters |
| product | {} | PROJECT-1 | en | C054 | Nothing | {"language_level": "premium"} | copywriting | false |
Then I should have "2" translatables with job for class "Worldia\Bundle\ProductTestBundle\Entity\Product" and locale en
Then I should have the following jobs:
| id | translatable | project | document | status | locale |
| 1 | 1 | PROJECT-1 | en-copywriting-1 | validated | en |
| 2 | 2 | PROJECT-1 | en-copywriting-2 | validated | en |
When I generate a translation batch with the following parameters:
| finder | filter | name | languageFrom | category | briefing | options | activity | textmasters |
| product | {} | PROJECT-1 | de | C054 | Nothing | {"language_level": "premium"} | copywriting | [] |
| finder | filter | name | languageFrom | category | briefing | options | activity | useMyTextmasters |
| product | {} | PROJECT-1 | de | C054 | Nothing | {"language_level": "premium"} | copywriting | false |
Then I should have "2" translatables with job for class "Worldia\Bundle\ProductTestBundle\Entity\Product" and locale de
12 changes: 6 additions & 6 deletions Features/translation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Feature: Translation management
| Hello NYC | NYC is the big apple | en |
Then I should have "0" translatables with job for class "Worldia\Bundle\ProductTestBundle\Entity\Product" and locale fr
When I generate a translation batch with the following parameters:
| finder | filter | name | languageFrom | languageTo | category | briefing | options | activity | textmasters |
| product | {} | PROJECT-1 | en | fr | C054 | Nothing | {"language_level": "premium"} | translation | ["55c3763e656462000b000027"] |
| finder | filter | name | languageFrom | languageTo | category | briefing | options | activity | useMyTextmasters |
| product | {} | PROJECT-1 | en | fr | C054 | Nothing | {"language_level": "premium"} | translation | true |
Then I should have "2" translatables with job for class "Worldia\Bundle\ProductTestBundle\Entity\Product" and locale fr
When I receive the request '{ "id": "PROJECT-1", "name": "PROJECT-1", "status": "in_progress"}'
Then I should have the following jobs:
Expand All @@ -35,14 +35,14 @@ Feature: Translation management
| Hello NYC | NYC is the big apple | en |
| Bonjour NYC | NYC est la grosse pomme | fr |
When I generate a translation batch with the following parameters:
| finder | filter | name | languageFrom | languageTo | category | briefing | options | activity | textmasters |
| product | {} | PROJECT-2 | en | fr | C054 | Nothing | {"language_level": "premium"} | translation | ["55c3763e656462000b000027"] |
| finder | filter | name | languageFrom | languageTo | category | briefing | options | activity | useMyTextmasters |
| product | {} | PROJECT-2 | en | fr | C054 | Nothing | {"language_level": "premium"} | translation | true |
Then I should have the following jobs:
| id | translatable | project | document | status | locale |
| 1 | 1 | PROJECT-1 | en-fr-1 | validated | fr |
| 2 | 2 | PROJECT-1 | en-fr-2 | validated | fr |
When I generate a translation batch with the following parameters:
| finder | filter | name | languageFrom | languageTo | category | briefing | options | activity | textmasters |
| product | {} | PROJECT-1 | en | de | C054 | Nothing | {"language_level": "premium"} | translation | ["55c3763e656462000b000027"] |
| finder | filter | name | languageFrom | languageTo | category | briefing | options | activity | useMyTextmasters |
| product | {} | PROJECT-1 | en | de | C054 | Nothing | {"language_level": "premium"} | translation | true |
Then I should have "2" translatables with job for class "Worldia\Bundle\ProductTestBundle\Entity\Product" and locale de
Then I should have "2" translatables with job for class "Worldia\Bundle\ProductTestBundle\Entity\Product" and locale fr
4 changes: 4 additions & 0 deletions Tests/Fixtures/Project/app/config/config_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ services:
class: Worldia\Bundle\ProductTestBundle\Service\ProjectApi
arguments: ['@worldia.textmaster.api.client', '@worldia.textmaster.document.api']

worldia.textmaster.project_author.api:
class: Worldia\Bundle\ProductTestBundle\Service\Project\AuthorApi
arguments: ['@worldia.textmaster.api.client', 1]

worldia.textmaster.document.api:
class: Worldia\Bundle\ProductTestBundle\Service\DocumentApi
arguments: ['@worldia.textmaster.api.client']
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Worldia\Bundle\ProductTestBundle\Service\Project;

use Textmaster\Client;

class Author
{
protected $client;
protected $page;
protected $projectId;

public function __construct(Client $client, $projectId)
{
$this->client = $client;
$this->projectId = $projectId;
}

public function all($status = null)
{
return [
'total_pages' => 1,
'count' => 1,
'page' => 1,
'per_page' => 20,
'previous_page' => null,
'next_page' => null,
'my_authors' => [
[
'status' => 'my_textmaster',
'id' => '58f9febce27d6b5dd2b0b4ec',
'author_id' => '55c3763e656462000b000027',
]
]
];
}

public function setPage($page)
{
$this->page = (null === $page ? $page : (int)$page);

return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Textmaster\Client;
use Textmaster\Model\Project;
use Worldia\Bundle\ProductTestBundle\Service\Project\Author as ProjectAuthors;

class ProjectApi
{
Expand Down Expand Up @@ -54,4 +55,9 @@ public function updateProject(array $params)
{
$this->projects[$params['id']] = array_merge($this->projects[$params['id']], $params);
}

public function authors($projectId)
{
return new ProjectAuthors($this->client, $projectId);
}
}
11 changes: 11 additions & 0 deletions Tests/Units/Translation/TranslationManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function shouldCreateProject()
$projectMock = $this->getMockBuilder('Textmaster\Model\Project')->disableOriginalConstructor()->getMock();
$translatableMock = $this->getMock('TranslatableInterface', ['getId']);
$documentMock = $this->getMock('Textmaster\Model\DocumentInterface');
$authorMock = $this->getMock('Textmaster\Model\AuthorInterface');

$textmasterManagerMock->expects($this->once())
->method('getProject')
Expand Down Expand Up @@ -56,6 +57,10 @@ public function shouldCreateProject()
$projectMock->expects($this->once())
->method('save')
->willReturn($projectMock);
$projectMock->expects($this->once())
->method('getPotentialAuthors')
->with('my_textmaster')
->willReturn([$authorMock]);

$routerMock->expects($this->exactly(4))
->method('generate')
Expand All @@ -75,6 +80,7 @@ public function shouldCreateProject()
$this->assertTrue(in_array('Textmaster\Model\ProjectInterface', class_implements($project)));
$this->assertSame($projectMock, $project);
}

/**
* @test
*/
Expand All @@ -87,6 +93,7 @@ public function shouldCreateProjectWithTranslationMemory()
$projectMock = $this->getMockBuilder('Textmaster\Model\Project')->disableOriginalConstructor()->getMock();
$translatableMock = $this->getMock('TranslatableInterface', ['getId']);
$documentMock = $this->getMock('Textmaster\Model\DocumentInterface');
$authorMock = $this->getMock('Textmaster\Model\AuthorInterface');

$textmasterManagerMock->expects($this->once())
->method('getProject')
Expand Down Expand Up @@ -122,6 +129,10 @@ public function shouldCreateProjectWithTranslationMemory()
$projectMock->expects($this->exactly(2))
->method('save')
->willReturn($projectMock);
$projectMock->expects($this->once())
->method('getPotentialAuthors')
->with('my_textmaster')
->willReturn([$authorMock]);

$routerMock->expects($this->exactly(4))
->method('generate')
Expand Down
4 changes: 2 additions & 2 deletions Translation/TranslationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function generate(
array $options = [],
$activity = ProjectInterface::ACTIVITY_TRANSLATION,
$workTemplate = null,
$textmasters = []
$useMyTextmasters = true
) {
if (null === $locale = $languageTo) {
$locale = $languageFrom;
Expand All @@ -61,7 +61,7 @@ public function generate(
return;
}

$project = $this->translationManager->create($translatables, $name, $languageFrom, $category, $briefing, $languageTo, $options, $activity, $workTemplate, $textmasters);
$project = $this->translationManager->create($translatables, $name, $languageFrom, $category, $briefing, $languageTo, $options, $activity, $workTemplate, $useMyTextmasters);

if (!array_key_exists('translation_memory', $project->getOptions())) {
$project->launch();
Expand Down
24 changes: 12 additions & 12 deletions Translation/TranslationGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ interface TranslationGeneratorInterface
/**
* Generate a textmaster project with documents for eligible objects.
*
* @param string $finderCode translatable finder code
* @param string $languageFrom source language identifier (ex: fr, en, de...)
* @param array $filter array of parameters to filter the list of objects
* @param string $name textmaster project name
* @param string $category textmaster project category
* @param string $briefing textmaster project briefing
* @param string $languageTo destination language identifier (ex: fr, en, de...)
* @param array $options textmaster project options
* @param string $activity textmaster project activity
* @param string $workTemplate textmaster project work template
* @param array $textmasters ids of the authors
* @param string $finderCode translatable finder code
* @param string $languageFrom source language identifier (ex: fr, en, de...)
* @param array $filter array of parameters to filter the list of objects
* @param string $name textmaster project name
* @param string $category textmaster project category
* @param string $briefing textmaster project briefing
* @param string $languageTo destination language identifier (ex: fr, en, de...)
* @param array $options textmaster project options
* @param string $activity textmaster project activity
* @param string $workTemplate textmaster project work template
* @param bool $useMyTextmasters use my favorite authors for the project
*
* @return ProjectInterface|null
*/
Expand All @@ -34,6 +34,6 @@ public function generate(
array $options = [],
$activity,
$workTemplate = null,
$textmasters = []
$useMyTextmasters = true
);
}
15 changes: 13 additions & 2 deletions Translation/TranslationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Textmaster\Manager;
use Textmaster\Model\Author;
use Textmaster\Model\DocumentInterface;
use Textmaster\Model\ProjectInterface;
use Textmaster\Translator\TranslatorInterface;
Expand Down Expand Up @@ -63,7 +64,7 @@ public function create(
array $options = [],
$activity = ProjectInterface::ACTIVITY_TRANSLATION,
$workTemplate = null,
$textmasters = []
$useMyTextmasters = true
) {
$translationMemory = false;
if (array_key_exists('translation_memory', $options)) {
Expand All @@ -82,10 +83,20 @@ public function create(
->setOptions($options)
->setWorkTemplate($workTemplate)
->setCallback($this->generateProjectCallback())
->setTextmasters($textmasters)
;

$project->save();

if ($useMyTextmasters) {
$authors = $project->getPotentialAuthors('my_textmaster');

$ids = array_map(function ($author) {
return $author->getAuthorId();
}, $authors);

$project->setTextmasters($ids);
}

$project->addDocuments($this->generateDocuments($project, $translatable));

if ($translationMemory) {
Expand Down
3 changes: 2 additions & 1 deletion Translation/TranslationManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface TranslationManagerInterface
* @param array $options
* @param string $activity
* @param string $workTemplate
* @param bool $useMyTextmasters
*
* @return ProjectInterface
*/
Expand All @@ -32,7 +33,7 @@ public function create(
array $options = [],
$activity = ProjectInterface::ACTIVITY_TRANSLATION,
$workTemplate = null,
$textmasters = []
$useMyTextmasters = true
);

/**
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"require": {
"php": ">=5.6.0",
"worldia/textmaster-api": "^0.5",
"worldia/textmaster-api": "^0.6",
"symfony/framework-bundle": "^3.2",
"symfony/property-access": "^3.2",
"symfony/validator": "^3.2",
Expand Down

0 comments on commit cf5cad1

Please sign in to comment.