/** * Test translation with a loaded translator * * @return void */ public function testTranslateWithTranslator() { $translate = new Translate(); $translator = $this->getMock('Zend\\I18n\\Translator\\TranslatorInterface'); $translator->expects($this->once())->method('translate')->with($this->equalTo('foo'))->will($this->returnValue('%%token%%')); $translate->setTranslator($translator); // Simple case that tests default values and tokens in a single pass: $this->assertEquals('baz', $translate->__invoke('foo', ['%%token%%' => 'baz'], 'failure')); }
/** * Test translation with a loaded translator and a text domain * * @return void */ public function testTranslateTextDomainWithTranslator() { $translate = new Translate(); $translate->setTranslator($this->getMockTranslator(['zap' => ['foo' => '%%token%%']])); // This one will work -- TextDomain defined above $this->assertEquals('baz', $translate->__invoke('zap::foo', ['%%token%%' => 'baz'], 'failure')); // This one will use incoming string -- TextDomain undefined $this->assertEquals('failure', $translate->__invoke('undefined::foo', ['%%token%%' => 'baz'], 'failure')); }