Files
luos/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/LanguageTest.php
davidcallizaya 3d82540339 HOR-3209
Web Entry 2.0 Rest - Languages EP
ACCEPTACE CRITERIA
1. The result should include the detailed fields.
2. The result should include the installed languages.
3. User should be logged.
2017-06-03 12:46:23 -04:00

99 lines
2.8 KiB
PHP

<?php
namespace ProcessMaker\BusinessModel;
/**
* Test the ProcessMaker\BusinessModel\Language class.
*/
class LanguageTest extends \WorkflowTestCase
{
/**
* @var Language
*/
protected $object;
private $translationEnv;
/**
* Sets up the unit tests.
*/
protected function setUp()
{
$this->setupDB();
$this->object = new Language;
$this->translationEnv = PATH_DATA."META-INF".PATH_SEP."translations.env";
file_exists($this->translationEnv) ? unlink($this->translationEnv) : false;
}
/**
* Tears down the unit tests.
*/
protected function tearDown()
{
$this->dropDB();
}
/**
* Test default languages
*
* @category HOR-3209:1
* @covers ProcessMaker\BusinessModel\Language::getLanguageList
*/
public function testGetLanguageList()
{
$list = $this->object->getLanguageList();
$this->assertCount(1, $list);
$this->assertEquals('en', $list[0]['LANG_ID']);
$this->assertEquals('English', $list[0]['LANG_NAME']);
}
/**
* Test installed languages
*
* @category HOR-3209:2
* @covers ProcessMaker\BusinessModel\Language::getLanguageList
*/
public function testGetLanguageListInstalled()
{
$this->installLanguage('es', __DIR__.'/processmaker.es.po');
$list = $this->object->getLanguageList();
$this->assertCount(2, $list);
$this->assertEquals('en', $list[0]['LANG_ID']);
$this->assertEquals('English', $list[0]['LANG_NAME']);
$this->assertEquals('es-ES', $list[1]['LANG_ID']);
$this->assertEquals('Spanish (Spain)', $list[1]['LANG_NAME']);
$this->uninstallLanguage('es', __DIR__.'/processmaker.es.po');
$list2 = $this->object->getLanguageList();
$this->assertCount(1, $list2);
}
/**
* Install a language to the system.
*
* @param type $lanId
* @param type $filename
*/
private function installLanguage($lanId, $filename)
{
copy($filename, PATH_CORE.'content/translations/'.basename($filename));
$language = \LanguagePeer::retrieveByPK($lanId);
$language->setLanEnabled(1);
$language->save();
file_exists($this->translationEnv) ? unlink($this->translationEnv) : false;
}
/**
* Uninstall a language from the system.
*
* @param type $lanId
* @param type $filename
*/
private function uninstallLanguage($lanId, $filename)
{
unlink(PATH_CORE.'content/translations/'.basename($filename));
$language = \LanguagePeer::retrieveByPK($lanId);
$language->setLanEnabled(0);
$language->save();
file_exists($this->translationEnv) ? unlink($this->translationEnv) : false;
}
}