public function testSuccessfulTranslate()
 {
     $client = new Client();
     $content = Stream::factory('{"access_token":"123"}');
     $mock = new Mock([new Response(200, [], $content), new Response(200, [], Stream::factory($this->xmlResponse))]);
     $client->getEmitter()->attach($mock);
     $translator = new \badams\MicrosoftTranslator\MicrosoftTranslator($client);
     $translator->setClient('client_id', 'client_secret');
     $results = $translator->getTranslationsArray(['Hello', 'World'], 'de', 'en');
     $this->assertTrue(is_array($results));
     $this->assertEquals(2, count($results));
     $this->assertInstanceOf('\\badams\\MicrosoftTranslator\\Responses\\GetTranslationsResponse', $results[0]);
     $this->assertInstanceOf('\\badams\\MicrosoftTranslator\\Language', $results[0]->getFrom());
     $this->assertEquals('en', (string) $results[0]->getFrom());
     $translations = $results[0]->getTranslations();
     $this->assertEquals(2, count($translations));
     $this->assertInstanceOf('\\badams\\MicrosoftTranslator\\Responses\\TranslationMatch', $translations[0]);
     $this->assertEquals('Hallo', $translations[0]->getTranslatedText());
     $this->assertEquals(5, $translations[0]->getRating());
     $this->assertEquals(100, $translations[0]->getMatchDegree());
     $this->assertEquals(null, $translations[0]->getError());
     $this->assertEquals(0, $translations[0]->getCount());
     $this->assertEquals('', $translations[0]->getMatchedOriginalText());
     $this->assertEquals('Hello', $translations[1]->getTranslatedText());
     $this->assertEquals(4, $translations[1]->getRating());
     $this->assertEquals(70, $translations[1]->getMatchDegree());
     $this->assertEquals(null, $translations[1]->getError());
     $this->assertEquals(1, $translations[1]->getCount());
     $this->assertEquals('Hello', $translations[1]->getMatchedOriginalText());
 }
 public function testSuccessfulTranslateHtml()
 {
     $client = new Client();
     $content = Stream::factory('{"access_token":"123"}');
     $mock = new Mock([new Response(200, [], $content), new Response(200, [], Stream::factory('<string>&lt;p&gt;Bonjour &lt;em&gt;monde!&lt;/em&gt;&lt;/p&gt;</string>'))]);
     $client->getEmitter()->attach($mock);
     $translator = new \badams\MicrosoftTranslator\MicrosoftTranslator($client);
     $translator->setClient('client_id', 'client_secret');
     $result = $translator->translate('<p>Hello <em>world!</em></p>', 'fr', 'en', Translate::CONTENT_TYPE_HTML);
     $this->assertEquals('<p>Bonjour <em>monde!</em></p>', $result);
 }
 public function testSuccessfuSpeak()
 {
     $client = new Client();
     $content = Stream::factory('{"access_token":"123"}');
     $mock = new Mock([new Response(200, [], $content), new Response(200, [], Stream::factory('AUDIO_DATA'))]);
     $client->getEmitter()->attach($mock);
     $translator = new \badams\MicrosoftTranslator\MicrosoftTranslator($client);
     $translator->setClient('client_id', 'client_secret');
     $output = base64_decode($translator->speak('Hello', 'en'));
     $this->assertEquals('AUDIO_DATA', $output);
 }
 public function testCustomOptions()
 {
     $client = new Client();
     $content = Stream::factory('{"access_token":"123"}');
     $mock = new Mock([new Response(200, [], $content), new Response(200, [], Stream::factory($this->xmlResponse))]);
     $client->getEmitter()->attach($mock);
     $translator = new \badams\MicrosoftTranslator\MicrosoftTranslator($client);
     $translator->setClient('client_id', 'client_secret');
     $options = new TranslateOptions('general', TranslateOptions::CONTENT_TYPE_PLAIN, 'Foo');
     $results = $translator->getTranslations('Hello', 'de', 'en', 5, $options);
     $this->assertEquals('Foo', $results->getState());
 }
 public function testSuccessfulDetect()
 {
     $client = new Client();
     $content = Stream::factory('{"access_token":"123"}');
     $mock = new Mock([new Response(200, [], $content), new Response(200, [], Stream::factory('<string>en</string>'))]);
     $client->getEmitter()->attach($mock);
     $translator = new \badams\MicrosoftTranslator\MicrosoftTranslator($client);
     $translator->setClient('client_id', 'client_secret');
     $result = $translator->detect('Hello');
     $this->assertInstanceOf('\\badams\\MicrosoftTranslator\\Language', $result);
     $this->assertEquals('en', (string) $result);
     $this->assertEquals('English', $result->getEnglishName());
 }
 public function testInvalidLanguageCode()
 {
     $client = new Client();
     $content = Stream::factory('{"access_token":"123"}');
     $xml = '<ArrayOfstring xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><string></string></ArrayOfstring>';
     $mock = new Mock([new Response(200, [], $content), new Response(200, [], Stream::factory($xml))]);
     $client->getEmitter()->attach($mock);
     $translator = new \badams\MicrosoftTranslator\MicrosoftTranslator($client);
     $translator->setClient('client_id', 'client_secret');
     $languages = $translator->getLanguageNames(['invalid_language']);
     $this->assertTrue(is_array($languages));
     $this->assertTrue(empty($languages));
 }
 public function testGetLanguagesForSpeak()
 {
     $client = new Client();
     $content = Stream::factory('{"access_token":"123"}');
     $mock = new Mock([new Response(200, [], $content), new Response(200, [], Stream::factory($this->xmlRepsonse))]);
     $client->getEmitter()->attach($mock);
     $translator = new \badams\MicrosoftTranslator\MicrosoftTranslator($client);
     $translator->setClient('client_id', 'client_secret');
     $languages = $translator->getLanguagesForSpeak();
     $this->assertTrue(is_array($languages));
     $this->assertEquals('en', $languages[0]);
     $this->assertEquals('de', $languages[1]);
     $this->assertEquals('fr', $languages[2]);
 }