Skip to content

Commit

Permalink
Tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
paazmaya committed Jan 16, 2014
1 parent 10ac67f commit 538c5c0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ public function getQueryParameters()
'text' => $this->text,
'from' => $this->from,
'to' => $this->to,
'maxTranslations' => $this->maxTranslations,
'options' => array(
'Category' => $this->category,
'ContentType' => 'text/plain'
)
'maxTranslations' => $this->maxTranslations
);
}

Expand Down
32 changes: 21 additions & 11 deletions tests/MatthiasNoback/MicrosoftTranslator/ApiCall/GetTranslationsTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ public function testValidatesLengthOfText()
new ApiCall\GetTranslations($text, 'nl');
}

public function testGetRequestToTranslateMethodWithNoRequestContent()
public function testPostRequestToGetTranslations()
{
$apiCall = new ApiCall\GetTranslations('text', 'nl');

$this->assertSame('GetTranslations', $apiCall->getApiMethodName());
$this->assertSame('POST', $apiCall->getHttpMethod());
$this->assertSame(null, $apiCall->getRequestContent());
}

public function testQueryParameters()
Expand All @@ -30,27 +29,38 @@ public function testQueryParameters()
$from = 'from';
$to = 'to';
$maxTranslations = 4;
$category = 'category';

$apiCall = new ApiCall\GetTranslations($text, $to, $from, $maxTranslations, $category);
$apiCall = new ApiCall\GetTranslations($text, $to, $from, $maxTranslations);
$this->assertEquals(array(
'text' => $text,
'from' => $from,
'to' => $to,
'maxTranslations' => $maxTranslations,
'options' => array(
'Category' => $category,
'ContentType' => 'text/plain',
)
'maxTranslations' => $maxTranslations
), $apiCall->getQueryParameters());
}

public function testParseResponse()
{
$apiCall = new ApiCall\GetTranslations('text', 'nl');

$response = '<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Dit is een test</string>';
$response =
<<<EOF
<GetTranslationsResponse xmlns="http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<From>en</From>
<State/>
<Translations>
<TranslationMatch>
<Count>0</Count>
<MatchDegree>100</MatchDegree>
<MatchedOriginalText/>
<Rating>5</Rating>
<TranslatedText>Dit is een test</TranslatedText>
</TranslationMatch>
</Translations>
</GetTranslationsResponse>
EOF;

$this->assertSame('Dit is een test', $apiCall->parseResponse($response));

$this->assertSame(array('Dit is een test'), $apiCall->parseResponse($response));
}
}
7 changes: 7 additions & 0 deletions tests/MatthiasNoback/MicrosoftTranslator/MicrosoftTranslatorFunctionalTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ public function testTranslateArray()
), $translatedTexts);
}

public function testGetTranslations()
{
$translated = $this->translator->getTranslations('This is a test', 'nl', 'en', 1);

$this->assertSame(array('Dit is een test'), $translated);
}

public function testDetect()
{
$text = 'This is a test';
Expand Down

0 comments on commit 538c5c0

Please sign in to comment.