Skip to content

Commit

Permalink
Add textmasters parameters in create project (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
LaetitiaRiffaud authored and Pierre Ducoudray committed Feb 6, 2017
1 parent dec7c31 commit 1754907
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 12 deletions.
19 changes: 19 additions & 0 deletions lib/Textmaster/Model/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Project extends AbstractObject implements ProjectInterface
'options',
'callback',
'work_template',
'textmasters',
];

/**
Expand Down Expand Up @@ -139,6 +140,22 @@ public function setOptions(array $options)
return $this->setProperty('options', $options);
}

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

/**
* {@inheritdoc}
*/
public function setTextmasters(array $textmasters)
{
return $this->setProperty('textmasters', $textmasters);
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -207,6 +224,8 @@ public function setCallback(array $callback)
}

$this->data['callback'] = $callback;

return $this;
}

/**
Expand Down
18 changes: 18 additions & 0 deletions lib/Textmaster/Model/ProjectInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,24 @@ public function getOptions();
*/
public function setOptions(array $options);

/**
* Get textmasters.
*
* @return array
*/
public function getTextmasters();

/**
* Set textmasters.
*
* @param array $textmasters
*
* @return ProjectInterface
*
* @throws ObjectImmutableException If project was already launched
*/
public function setTextmasters(array $textmasters);

/**
* Get list of all allowed callbacks.
*
Expand Down
70 changes: 70 additions & 0 deletions test/Textmaster/Functional/Api/AuthorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/*
* This file is part of the Textmaster Api v1 client package.
*
* (c) Christian Daguerre <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Textmaster\Functional\Api;

use Textmaster\Api\Author;
use Textmaster\Client;
use Textmaster\HttpClient\HttpClient;

class AuthorTest extends \PHPUnit_Framework_TestCase
{
/**
* Wait time between calls because the sandbox environment is not as fast as prod.
*/
const WAIT_TIME = 3;

/**
* Author api.
*
* @var Author
*/
protected $api;

/**
* {@inheritdoc}
*/
public function setUp()
{
parent::setUp();

$httpClient = new HttpClient('GFHunwb2DHw', 'gqvE7aZS_JM',
['base_uri' => 'http://api.sandbox.textmaster.com/%s']);
$client = new Client($httpClient);
$this->api = $client->author();
}

/**
* @test
*/
public function shouldShowAuthors()
{
$result = $this->api->mine()->all();

$this->assertGreaterThan(0, $result['count']);
}

/**
* @test
*/
public function shouldShowAuthorsFiltered()
{
$status = 'my_textmaster';

$result = $this->api->mine()->all($status);

$this->assertGreaterThan(0, $result['count']);

foreach ($result['my_authors'] as $author) {
$this->assertSame($author['status'], $status);
}
}
}
28 changes: 16 additions & 12 deletions test/Textmaster/Functional/Api/ProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,29 @@ public function shouldCreateProject()
'options' => [
'language_level' => 'premium',
],
'language_from' => 'en',
'language_to' => 'fr',
'language_from' => 'fr',
'language_to' => 'en',
'category' => 'C021',
'project_briefing' => 'This project is only for testing purpose',
'work_template' => '1_title_2_paragraphs',
'textmasters' => [
'55c3763e656462000b000027'
],
];

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

$this->assertSame('Created project for functional test', $result['name']);
$this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
$this->assertSame('premium', $result['options']['language_level']);
$this->assertSame('en', $result['language_from']);
$this->assertSame('fr', $result['language_to']);
$this->assertSame('fr', $result['language_from']);
$this->assertSame('en', $result['language_to']);
$this->assertSame('C021', $result['category']);
$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']);
$this->assertSame(['55c3763e656462000b000027'], $result['textmasters']);

return $result['id'];
}
Expand Down Expand Up @@ -189,8 +193,8 @@ public function shouldUpdateProject($projectId)
$this->assertSame(self::$testId, $result['name']);
$this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
$this->assertSame('premium', $result['options']['language_level']);
$this->assertSame('en', $result['language_from']);
$this->assertSame('fr', $result['language_to']);
$this->assertSame('fr', $result['language_from']);
$this->assertSame('en', $result['language_to']);
$this->assertSame('C021', $result['category']);
$this->assertSame('This project is only for testing purpose', $result['project_briefing']);
$this->assertSame(ProjectInterface::STATUS_IN_CREATION, $result['status']);
Expand All @@ -214,8 +218,8 @@ public function shouldShowProject($projectId)
$this->assertSame(self::$testId, $result['name']);
$this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
$this->assertSame('premium', $result['options']['language_level']);
$this->assertSame('en', $result['language_from']);
$this->assertSame('fr', $result['language_to']);
$this->assertSame('fr', $result['language_from']);
$this->assertSame('en', $result['language_to']);
$this->assertSame('C021', $result['category']);
$this->assertSame('This project is only for testing purpose', $result['project_briefing']);
$this->assertSame(ProjectInterface::STATUS_IN_CREATION, $result['status']);
Expand Down Expand Up @@ -267,8 +271,8 @@ public function shouldLaunchProject($projectId)
$this->assertSame(self::$testId, $result['name']);
$this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
$this->assertSame('premium', $result['options']['language_level']);
$this->assertSame('en', $result['language_from']);
$this->assertSame('fr', $result['language_to']);
$this->assertSame('fr', $result['language_from']);
$this->assertSame('en', $result['language_to']);
$this->assertSame('C021', $result['category']);
$this->assertSame('This project is only for testing purpose', $result['project_briefing']);
$this->assertSame(ProjectInterface::STATUS_IN_CREATION, $result['status']);
Expand Down Expand Up @@ -332,8 +336,8 @@ public function shouldCancelProject($projectId)
$this->assertSame(self::$testId, $result['name']);
$this->assertSame(ProjectInterface::ACTIVITY_TRANSLATION, $result['ctype']);
$this->assertSame('premium', $result['options']['language_level']);
$this->assertSame('en', $result['language_from']);
$this->assertSame('fr', $result['language_to']);
$this->assertSame('fr', $result['language_from']);
$this->assertSame('en', $result['language_to']);
$this->assertSame('C021', $result['category']);
$this->assertSame('This project is only for testing purpose', $result['project_briefing']);
$this->assertSame(ProjectInterface::STATUS_CANCELED, $result['status']);
Expand Down
8 changes: 8 additions & 0 deletions test/Textmaster/Unit/Model/ProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function setUp()
'category' => 'C014',
'project_briefing' => 'Lorem ipsum...',
'options' => ['language_level' => 'premium'],
'textmasters' => ['A-3727-TM'],
];
$updateValues = [
'id' => '123456',
Expand All @@ -45,6 +46,7 @@ public function setUp()
'category' => 'C014',
'project_briefing' => 'Lorem ipsum...',
'options' => ['language_level' => 'premium'],
'textmasters' => ['A-3727-TM'],
];

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

$project = new Project($this->clientMock);
$project
Expand All @@ -92,6 +95,7 @@ public function shouldCreateEmpty()
->setBriefing($briefing)
->setOptions($options)
->setCallback($callback)
->setTextmasters($textmasters)
;

$this->assertNull($project->getId());
Expand All @@ -104,6 +108,7 @@ public function shouldCreateEmpty()
$this->assertSame($briefing, $project->getBriefing());
$this->assertSame($options, $project->getOptions());
$this->assertSame($callback, $project->getCallback());
$this->assertSame($textmasters, $project->getTextmasters());
}

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

$values = [
'id' => $id,
Expand All @@ -131,6 +137,7 @@ public function shouldCreateFromValues()
'category' => $category,
'project_briefing' => $briefing,
'options' => $options,
'textmasters' => $textmasters,
];

$project = new Project($this->clientMock, $values);
Expand All @@ -144,6 +151,7 @@ public function shouldCreateFromValues()
$this->assertSame($category, $project->getCategory());
$this->assertSame($briefing, $project->getBriefing());
$this->assertSame($options, $project->getOptions());
$this->assertSame($textmasters, $project->getTextmasters());
}

/**
Expand Down

0 comments on commit 1754907

Please sign in to comment.