/**
  * Basic test of add translations from a Symfony catalogue.
  */
 public function testAddCatalogueWorksAsExpected()
 {
     // Test data
     $bundle = 'bundle#1';
     $domain = 'domain#1';
     $locale = 'locales#1';
     $resource = 'resource#1';
     $translation = 'translation#1';
     $path = '/some/path';
     $filename = 'file.ext';
     // Mocks
     $catalogueMock = $this->getMockBuilder('Symfony\\Component\\Translation\\MessageCatalogueInterface')->disableOriginalConstructor()->getMock();
     $resourceMock = $this->getMockBuilder('Symfony\\Component\\Config\\Resource\\ResourceInterface')->disableOriginalConstructor()->getMock();
     $catalogueMock->expects($this->once())->method('getLocale')->will($this->returnValue($locale));
     $catalogueMock->expects($this->once())->method('getDomains')->will($this->returnValue(array($domain)));
     $catalogueMock->expects($this->once())->method('all')->will($this->returnValue(array($resource => $translation)));
     $catalogueMock->expects($this->once())->method('getResources')->will($this->returnValue(array($resourceMock)));
     $resourceMock->expects($this->once())->method('getResource')->will($this->returnValue($filename));
     // Run the test
     $translations = new Translations();
     $translations->addCatalogue($bundle, $path, $catalogueMock);
     // Expected result
     $bundles = array($bundle);
     $domains = array($domain);
     $locales = array($locale);
     $files = array($bundle => array($path => array($filename)));
     $messages = array($bundle => array($domain => array($locale => array($resource => $translation))));
     // Assertions
     $this->assertEquals($bundles, $this->getPrivateValue($translations, 'bundles'));
     $this->assertEquals($domains, $this->getPrivateValue($translations, 'domains'));
     $this->assertEquals($locales, $this->getPrivateValue($translations, 'locales'));
     $this->assertEquals($files, $this->getPrivateValue($translations, 'files'));
     $this->assertEquals($messages, $this->getPrivateValue($translations, 'messages'));
 }
Example #2
0
 /**
  * Scan for all the translations in a file (yml, xlf or php)
  *
  * @param string $bundleName
  * @param string $resourcesFolder
  * @param string $fileName
  * @return Translations
  * @throws NotImplementedException
  */
 protected function scanFile($bundleName, $resourcesFolder, $fileName)
 {
     $translations = new Translations();
     list($domain, $locale, $loader) = explode('.', $fileName);
     if ($domain && $locale && $loader) {
         $loaderObj = $this->getFileLoader($loader);
         $resource = $resourcesFolder . '/' . $fileName;
         /** @var MessageCatalogueInterface $catalogue */
         $catalogue = $loaderObj->load($resource, $locale, $domain);
         $translations->addCatalogue($bundleName, $resourcesFolder, $catalogue);
     }
     return $translations;
 }