<commit_before><?php

require_once __DIR__ . '/../../../TestCase.php';

class CM_Model_LanguageTest extends TestCase {

	/** @var CM_Model_Language $_language */
	protected $_language;

	public function setUp() {
		$languageId = CM_Mysql::insert(TBL_CM_LANGUAGE, array('name' => 'English', 'abbreviation' => 'EN', 'enabled' => 1));
		$this->_language = new CM_Model_Language($languageId);
	}

	public function tearDown() {
		TH::clearEnv();
	}

	public function testSetGetTranslation() {

		// Test adding languageKey by getTranslation()
		$this->assertSame('keyFirst', $this->_language->getTranslation('keyFirst', true));
		$this->assertSame(array('keyFirst' => null), $this->_language->getTranslations()->getAssociativeArray());

		// Test adding languageKey by setTranslation()
		$this->_language->setTranslation('keyFirst', 'abc');
		$this->assertSame('abc', $this->_language->getTranslation('keyFirst', true));
		$this->assertSame(array('keyFirst' => 'abc'), $this->_language->getTranslations()->getAssociativeArray());
	}

	public function testCreate() {
		/** @var CM_Model_Language $language */
		$language = CM_Model_Language::create(array('name' => 'Deutsch', 'abbreviation' => 'de', 'enabled' => true));

		$this->assertInstanceOf('CM_Model_Language', $language);
		$this->assertSame('Deutsch', $language->getName());
		$this->assertSame('de', $language->getAbbreviation());
		$this->assertTrue($language->getEnabled());
		$this->assertNull($language->getBackup());
	}

	public function testCreateWithoutName() {
		try {
			CM_Model_Language::create(array('abbreviation' => 'de',));<commit_msg>t257: Adjust getTranslation() test with and without APC usage<commit_after><?php

require_once __DIR__ . '/../../../TestCase.php';

class CM_Model_LanguageTest extends TestCase {

	/** @var CM_Model_Language $_language */
	protected $_language;

	public function setUp() {
		$languageId = CM_Mysql::insert(TBL_CM_LANGUAGE, array('name' => 'English', 'abbreviation' => 'EN', 'enabled' => 1));
		$this->_language = new CM_Model_Language($languageId);
	}

	public function tearDown() {
		TH::clearEnv();
	}

	public function testSetGetTranslation() {
		$this->assertSame('keyFirst', $this->_language->getTranslation('keyFirst'));
		$this->assertSame(array('keyFirst' => null), $this->_language->getTranslations()->getAssociativeArray());

		$this->_language->getTranslation('keyFirst');	// Fill APC
		$this->_language->setTranslation('keyFirst', 'abc');
		$this->assertSame('keyFirst', $this->_language->getTranslation('keyFirst'));
		$this->assertSame(array('keyFirst' => 'abc'), $this->_language->getTranslations()->getAssociativeArray());
	}

	public function testSetGetTranslationWithoutLocalCache() {
		$this->assertSame('keyFirst', $this->_language->getTranslation('keyFirst', true));
		$this->assertSame(array('keyFirst' => null), $this->_language->getTranslations()->getAssociativeArray());

		$this->_language->getTranslation('keyFirst');	// Fill APC
		$this->_language->setTranslation('keyFirst', 'abc');
		$this->assertSame('abc', $this->_language->getTranslation('keyFirst', true));
		$this->assertSame(array('keyFirst' => 'abc'), $this->_language->getTranslations()->getAssociativeArray());
	}

	public function testCreate() {
		/** @var CM_Model_Language $language */
		$language = CM_Model_Language::create(array('name' => 'Deutsch', 'abbreviation' => 'de', 'enabled' => true));

		$this->assertInstanceOf('CM_Model_Language', $language);
		$this->assertSame('Deutsch', $language->getName());
		$this->assertSame('de', $language->getAbbreviation());
		$this->assertTrue($language->getEnabled());
		$this->assertNull($language->getBackup());
	}

	public function testCreateWithoutName() {
		try {
			CM_Model_Language::create(array('abbreviation' => 'de',));
{'fraction_non_alphanumeric': 0.19554848966613672, 'fraction_numerical': 0.0013248542660307366, 'mean_word_length': 6.565130260521042, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 95, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7473391', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1139, 'n_words': 188}