Skip to content

Commit 1754907

Browse files
LaetitiaRiffaudPierre Ducoudray
authored andcommitted
Add textmasters parameters in create project (#95)
1 parent dec7c31 commit 1754907

5 files changed

Lines changed: 131 additions & 12 deletions

File tree

lib/Textmaster/Model/Project.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Project extends AbstractObject implements ProjectInterface
4141
'options',
4242
'callback',
4343
'work_template',
44+
'textmasters',
4445
];
4546

4647
/**
@@ -139,6 +140,22 @@ public function setOptions(array $options)
139140
return $this->setProperty('options', $options);
140141
}
141142

143+
/**
144+
* {@inheritdoc}
145+
*/
146+
public function getTextmasters()
147+
{
148+
return $this->getProperty('textmasters');
149+
}
150+
151+
/**
152+
* {@inheritdoc}
153+
*/
154+
public function setTextmasters(array $textmasters)
155+
{
156+
return $this->setProperty('textmasters', $textmasters);
157+
}
158+
142159
/**
143160
* {@inheritdoc}
144161
*/
@@ -207,6 +224,8 @@ public function setCallback(array $callback)
207224
}
208225

209226
$this->data['callback'] = $callback;
227+
228+
return $this;
210229
}
211230

212231
/**

lib/Textmaster/Model/ProjectInterface.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,24 @@ public function getOptions();
181181
*/
182182
public function setOptions(array $options);
183183

184+
/**
185+
* Get textmasters.
186+
*
187+
* @return array
188+
*/
189+
public function getTextmasters();
190+
191+
/**
192+
* Set textmasters.
193+
*
194+
* @param array $textmasters
195+
*
196+
* @return ProjectInterface
197+
*
198+
* @throws ObjectImmutableException If project was already launched
199+
*/
200+
public function setTextmasters(array $textmasters);
201+
184202
/**
185203
* Get list of all allowed callbacks.
186204
*
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Textmaster Api v1 client package.
5+
*
6+
* (c) Christian Daguerre <christian@daguer.re>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Textmaster\Functional\Api;
13+
14+
use Textmaster\Api\Author;
15+
use Textmaster\Client;
16+
use Textmaster\HttpClient\HttpClient;
17+
18+
class AuthorTest extends \PHPUnit_Framework_TestCase
19+
{
20+
/**
21+
* Wait time between calls because the sandbox environment is not as fast as prod.
22+
*/
23+
const WAIT_TIME = 3;
24+
25+
/**
26+
* Author api.
27+
*
28+
* @var Author
29+
*/
30+
protected $api;
31+
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
public function setUp()
36+
{
37+
parent::setUp();
38+
39+
$httpClient = new HttpClient('GFHunwb2DHw', 'gqvE7aZS_JM',
40+
['base_uri' => 'http://api.sandbox.textmaster.com/%s']);
41+
$client = new Client($httpClient);
42+
$this->api = $client->author();
43+
}
44+
45+
/**
46+
* @test
47+
*/
48+
public function shouldShowAuthors()
49+
{
50+
$result = $this->api->mine()->all();
51+
52+
$this->assertGreaterThan(0, $result['count']);
53+
}
54+
55+
/**
56+
* @test
57+
*/
58+
public function shouldShowAuthorsFiltered()
59+
{
60+
$status = 'my_textmaster';
61+
62+
$result = $this->api->mine()->all($status);
63+
64+
$this->assertGreaterThan(0, $result['count']);
65+
66+
foreach ($result['my_authors'] as $author) {
67+
$this->assertSame($author['status'], $status);
68+
}
69+
}
70+
}

test/Textmaster/Functional/Api/ProjectTest.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,25 +125,29 @@ public function shouldCreateProject()
125125
'options' => [
126126
'language_level' => 'premium',
127127
],
128-
'language_from' => 'en',
129-
'language_to' => 'fr',
128+
'language_from' => 'fr',
129+
'language_to' => 'en',
130130
'category' => 'C021',
131131
'project_briefing' => 'This project is only for testing purpose',
132132
'work_template' => '1_title_2_paragraphs',
133+
'textmasters' => [
134+
'55c3763e656462000b000027'
135+
],
133136
];
134137

135138
$result = $this->api->create($params);
136139

137140
$this->assertSame('Created project for functional test', $result['name']);
138141
$this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
139142
$this->assertSame('premium', $result['options']['language_level']);
140-
$this->assertSame('en', $result['language_from']);
141-
$this->assertSame('fr', $result['language_to']);
143+
$this->assertSame('fr', $result['language_from']);
144+
$this->assertSame('en', $result['language_to']);
142145
$this->assertSame('C021', $result['category']);
143146
$this->assertSame('This project is only for testing purpose', $result['project_briefing']);
144147
$this->assertSame(ProjectInterface::STATUS_IN_CREATION, $result['status']);
145148
$this->assertSame('api', $result['creation_channel']);
146149
$this->assertSame('1_title_2_paragraphs', $result['work_template']['name']);
150+
$this->assertSame(['55c3763e656462000b000027'], $result['textmasters']);
147151

148152
return $result['id'];
149153
}
@@ -189,8 +193,8 @@ public function shouldUpdateProject($projectId)
189193
$this->assertSame(self::$testId, $result['name']);
190194
$this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
191195
$this->assertSame('premium', $result['options']['language_level']);
192-
$this->assertSame('en', $result['language_from']);
193-
$this->assertSame('fr', $result['language_to']);
196+
$this->assertSame('fr', $result['language_from']);
197+
$this->assertSame('en', $result['language_to']);
194198
$this->assertSame('C021', $result['category']);
195199
$this->assertSame('This project is only for testing purpose', $result['project_briefing']);
196200
$this->assertSame(ProjectInterface::STATUS_IN_CREATION, $result['status']);
@@ -214,8 +218,8 @@ public function shouldShowProject($projectId)
214218
$this->assertSame(self::$testId, $result['name']);
215219
$this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
216220
$this->assertSame('premium', $result['options']['language_level']);
217-
$this->assertSame('en', $result['language_from']);
218-
$this->assertSame('fr', $result['language_to']);
221+
$this->assertSame('fr', $result['language_from']);
222+
$this->assertSame('en', $result['language_to']);
219223
$this->assertSame('C021', $result['category']);
220224
$this->assertSame('This project is only for testing purpose', $result['project_briefing']);
221225
$this->assertSame(ProjectInterface::STATUS_IN_CREATION, $result['status']);
@@ -267,8 +271,8 @@ public function shouldLaunchProject($projectId)
267271
$this->assertSame(self::$testId, $result['name']);
268272
$this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
269273
$this->assertSame('premium', $result['options']['language_level']);
270-
$this->assertSame('en', $result['language_from']);
271-
$this->assertSame('fr', $result['language_to']);
274+
$this->assertSame('fr', $result['language_from']);
275+
$this->assertSame('en', $result['language_to']);
272276
$this->assertSame('C021', $result['category']);
273277
$this->assertSame('This project is only for testing purpose', $result['project_briefing']);
274278
$this->assertSame(ProjectInterface::STATUS_IN_CREATION, $result['status']);
@@ -332,8 +336,8 @@ public function shouldCancelProject($projectId)
332336
$this->assertSame(self::$testId, $result['name']);
333337
$this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
334338
$this->assertSame('premium', $result['options']['language_level']);
335-
$this->assertSame('en', $result['language_from']);
336-
$this->assertSame('fr', $result['language_to']);
339+
$this->assertSame('fr', $result['language_from']);
340+
$this->assertSame('en', $result['language_to']);
337341
$this->assertSame('C021', $result['category']);
338342
$this->assertSame('This project is only for testing purpose', $result['project_briefing']);
339343
$this->assertSame(ProjectInterface::STATUS_CANCELED, $result['status']);

test/Textmaster/Unit/Model/ProjectTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function setUp()
3434
'category' => 'C014',
3535
'project_briefing' => 'Lorem ipsum...',
3636
'options' => ['language_level' => 'premium'],
37+
'textmasters' => ['A-3727-TM'],
3738
];
3839
$updateValues = [
3940
'id' => '123456',
@@ -45,6 +46,7 @@ public function setUp()
4546
'category' => 'C014',
4647
'project_briefing' => 'Lorem ipsum...',
4748
'options' => ['language_level' => 'premium'],
49+
'textmasters' => ['A-3727-TM'],
4850
];
4951

5052
$clientMock = $this->getMockBuilder('Textmaster\Client')->setMethods(['api'])->disableOriginalConstructor()->getMock();
@@ -81,6 +83,7 @@ public function shouldCreateEmpty()
8183
$briefing = 'Lorem ipsum...';
8284
$options = ['language_level' => 'premium'];
8385
$callback = [ProjectInterface::CALLBACK_PROJECT_IN_PROGRESS => 'http://callback.url'];
86+
$textmasters = ['53d7bf7c53ecaaf8aa000514'];
8487

8588
$project = new Project($this->clientMock);
8689
$project
@@ -92,6 +95,7 @@ public function shouldCreateEmpty()
9295
->setBriefing($briefing)
9396
->setOptions($options)
9497
->setCallback($callback)
98+
->setTextmasters($textmasters)
9599
;
96100

97101
$this->assertNull($project->getId());
@@ -104,6 +108,7 @@ public function shouldCreateEmpty()
104108
$this->assertSame($briefing, $project->getBriefing());
105109
$this->assertSame($options, $project->getOptions());
106110
$this->assertSame($callback, $project->getCallback());
111+
$this->assertSame($textmasters, $project->getTextmasters());
107112
}
108113

109114
/**
@@ -120,6 +125,7 @@ public function shouldCreateFromValues()
120125
$category = 'C014';
121126
$briefing = 'Lorem ipsum...';
122127
$options = ['language_level' => 'premium'];
128+
$textmasters = ['A-3727-TM'];
123129

124130
$values = [
125131
'id' => $id,
@@ -131,6 +137,7 @@ public function shouldCreateFromValues()
131137
'category' => $category,
132138
'project_briefing' => $briefing,
133139
'options' => $options,
140+
'textmasters' => $textmasters,
134141
];
135142

136143
$project = new Project($this->clientMock, $values);
@@ -144,6 +151,7 @@ public function shouldCreateFromValues()
144151
$this->assertSame($category, $project->getCategory());
145152
$this->assertSame($briefing, $project->getBriefing());
146153
$this->assertSame($options, $project->getOptions());
154+
$this->assertSame($textmasters, $project->getTextmasters());
147155
}
148156

149157
/**

0 commit comments

Comments
 (0)