Example #1
0
 public function testDictionaryLoadedFromIncludedTemplate()
 {
     $this->view->loadFile(__DIR__ . '/resources/DictionaryTestParent.xml');
     $this->view->setTranslationPath(__DIR__ . '/resources/dict');
     $this->view->setLanguage('fr');
     $output = trim($this->view->render());
     $output = preg_replace('#^[ \\t]+#m', '', $output);
     $output = preg_replace('#[ \\t]+$#m', '', $output);
     $output = preg_replace('#\\n+#', ';', $output);
     $this->assertEquals('key1-child;Ma chaƮne traduite;key1-parent;key1-parent', $output);
     // Now check that the key1-parent has been cached, because used twice
     // But because the $cache array is private in Dictionary class,
     // we use Reflection to break into it.
     $reflector = new ReflectionClass(get_class($dict = $this->view->getRootNode()->getCurrentFile()->getDictionary('inParent')));
     $cacheProp = $reflector->getProperty('cache');
     $cacheProp->setAccessible(true);
     $cache = $cacheProp->getValue($dict);
     // And I know for a fact that it translates twice the "key1" key.
     $this->assertEquals('key1-parent', $cache['key1']);
 }