Exemplo n.º 1
0
 public function testForTest()
 {
     TranslateAbility::setLanguageId(1);
     $brand = new \Brand(array('title' => 'Apple'));
     $this->assertEquals('Apple', $brand->title, 'Accessor after creating');
     $brand->save();
     $this->assertEquals('Apple', $brand->title, 'Accessor after saving');
     $brand = \Brand::loadOne(1);
     $this->assertEquals('Apple', $brand->title, 'Accessor after loading');
     $this->assertEquals(array('id_language' => 1, 'id_object' => 1, 'title' => 'Apple'), QC::create('brands_translate')->executeOne(), 'Data stored in DB after saving');
     TranslateAbility::setLanguageId(2);
     $brand->title = 'Яблоко';
     $brand->save();
     $this->assertEquals('Яблоко', $brand->title, 'Accessor after loading');
     $this->assertEquals(array('id_language' => 2, 'id_object' => 1, 'title' => 'Яблоко'), QC::create('brands_translate')->where('id_language = :d', 2)->executeOne(), 'Data stored in DB after saving');
     $brand->loadTranslation(1);
     $this->assertEquals('Apple', $brand->title, 'loadTranslation works');
     $this->assertEquals(array('id' => 1, 'id_object' => 1, 'id_language' => 2, 'title' => 'Яблоко'), $brand->getTranslationForLanguage(2), 'getTranslationForLanguage');
     TranslateAbility::setLanguageId(1);
     $brand2 = new \Brand();
     $brand2->title = 'Samsung';
     $brand2->save();
     $brand2->loadTranslation(2);
     $this->assertEmpty($brand2->title, 'Empty data for not translated item');
     $brands = \Brand::loadList();
     $this->assertEquals(array('Apple', 'Samsung'), $brands->getFieldArray('title'), 'Loaded two translated items');
     $brands->loadTranslation(2);
     $this->assertEquals(array('Яблоко', null), $brands->getFieldArray('title'), 'Loaded two not fully translated items');
     $this->assertEquals(array(1 => array('id' => 1, 'id_object' => 1, 'id_language' => 1, 'title' => 'Apple'), 2 => array('id' => 1, 'id_object' => 1, 'id_language' => 2, 'title' => 'Яблоко')), $brand->getAllTranslations(), 'getAllTranslations()');
 }
Exemplo n.º 2
0
 public function testBasic()
 {
     $brand = new \Brand(array('title' => 'Apple'));
     $brand->save();
     $brand = \Brand::loadOne(1);
     $brand->attachFileFromPath('logo', __DIR__ . '/../README.md');
     $this->assertEquals('01/1/logo/README.md', $brand->logo[0]['link'], 'original file name');
     $brand->attachFileFromPath('logo', __DIR__ . '/../README.md');
     $this->assertEquals('01/1/logo/README_1.md', $brand->logo[1]['link'], 'duplicate of original file name');
     $brand = \Brand::loadOne(1);
     $this->assertEquals(2, count($brand->logo), 'loaded two files on demand');
     $brand->delete();
     $this->assertEmpty(FSService::getInstance()->in(__DIR__ . '/upload/01/')->find(), 'No files left after deleting');
     $brand = new \Brand(array('title' => 'Apple'));
     $_FILES['logo'] = array('tmp_name' => __DIR__ . '/../README.md', 'name' => 'readme.md');
     $_FILES['info_file'] = array('tmp_name' => __DIR__ . '/../README.md', 'name' => 'readme.md');
     $brand->setFieldNameForAlias('info', 'info_file');
     $brand->save();
     $this->assertEquals(2, count(FSService::getInstance()->in(__DIR__ . '/upload/02/2')->find()), 'Two files saved to object');
     $brand->delete();
     $brand = new \Brand(array('title' => 'Apple'));
     $_FILES['logo'] = array('tmp_name' => __DIR__ . '/../README.md', 'name' => 'readme.md');
     $_FILES['info'] = array('tmp_name' => __DIR__ . '/../README.md', 'name' => 'readme.md');
     $brand->skipFileAliasForSave('logo');
     $brand->save();
     $this->assertEquals(1, count(FSService::getInstance()->in(__DIR__ . '/upload/03/3')->find()), 'Skipped logo');
     $brand->delete();
 }