public function setUp() { parent::setUp(); $this->product = Product::getNewInstance($this->rootCategory, 'test'); $this->product->save(); $this->group = ProductFileGroup::getNewInstance($this->product); $this->group->save(); // create temporary file file_put_contents($this->tmpFilePath, $this->fileBody); }
public function testGetProductGroups() { // new product $product = Product::getNewInstance($this->rootCategory, 'test'); $product->save(); $groups = array(); foreach (range(1, 3) as $i) { $groups[$i] = ProductFileGroup::getNewInstance($product); $groups[$i]->position->set($i); $groups[$i]->setValueByLang('name', 'en', 'TEST_GROUP_' . $i); $groups[$i]->save(); } $this->assertEqual(count($groups), ProductFileGroup::getProductGroups($product)->getTotalRecordCount()); $i = 1; foreach (ProductFileGroup::getProductGroups($product) as $group) { $this->assertTrue($groups[$i] === $group); $i++; } }
public function testMergeGroupsWithFIlters() { // create groups $productGroup = array(); foreach (range(1, 3) as $i) { $productGroup[$i] = ProductFileGroup::getNewInstance($this->product); $productGroup[$i]->save(); } // create files $productFile = array(); $productFiles = array(); $dir = ClassLoader::getRealPath('cache') . '/'; foreach (range(1, 2) as $i) { file_put_contents($productFiles[$i] = $dir . md5($i), "file {$i}"); $productFile[$i] = ProductFile::getNewInstance($this->product, $productFiles[$i], "test_file_{$i}.txt"); $productFile[$i]->save(); } $productFile[1]->productFileGroup->set($productGroup[2]); $productFile[1]->save(); $this->assertEqual($this->product->getFileGroups()->getTotalRecordCount(), 3); $this->assertEqual($this->product->getFiles()->getTotalRecordCount(), 2); $filesMergedWithGroups = $this->product->getFilesMergedWithGroupsArray(); $this->assertEqual(count($filesMergedWithGroups), 4); // Check files without group $this->assertTrue(isset($filesMergedWithGroups[1]['ID'])); $this->assertEqual($filesMergedWithGroups[1]['ID'], $productFile[2]->getID()); $this->assertFalse(isset($filesMergedWithGroups[1]['ProductFileGroup']['ID'])); // Check first group $this->assertFalse(isset($filesMergedWithGroups[2]['ID'])); $this->assertTrue(isset($filesMergedWithGroups[2]['ProductFileGroup']['ID'])); $this->assertEqual($filesMergedWithGroups[2]['ProductFileGroup']['ID'], $productGroup[1]->getID()); // Check second group $this->assertTrue(isset($filesMergedWithGroups[3]['ID'])); $this->assertEqual($filesMergedWithGroups[3]['ID'], $productFile[1]->getID()); $this->assertTrue(isset($filesMergedWithGroups[3]['ProductFileGroup']['ID'])); $this->assertEqual($filesMergedWithGroups[3]['ProductFileGroup']['ID'], $productGroup[2]->getID()); // Check second group $this->assertFalse(isset($filesMergedWithGroups[4]['ID'])); $this->assertTrue(isset($filesMergedWithGroups[4]['ProductFileGroup']['ID'])); $this->assertEqual($filesMergedWithGroups[4]['ProductFileGroup']['ID'], $productGroup[3]->getID()); foreach ($productFiles as $fileName) { unlink($fileName); } foreach ($productFile as $file) { $file->delete(); } }
/** * @role update */ public function create() { $product = Product::getInstanceByID((int) $this->request->get('productID')); $fileGroup = ProductFileGroup::getNewInstance($product); return $this->save($fileGroup); }