Пример #1
0
 public static function addDemoAssets()
 {
     foreach (ConfigurationProvider::processFromPath() as $section => $entities) {
         foreach ($entities as $properties) {
             try {
                 $valuesToInsert = EntityFactory::createFromValues($section, $properties);
                 Db::getInstance()->insert('demonstration', $valuesToInsert);
             } catch (Exception $e) {
                 throw new PrestaShopException($e->getMessage());
             }
         }
     }
     return true;
 }
 public function testCreateFromValuesWithCategories()
 {
     /* create Parent category */
     $fixturesImgPath = __DIR__ . '/../fixtures/assets/';
     $returnProperties = EntityFactory::createFromValues('categories', $this->fakeCategoryData(), $fixturesImgPath);
     $this->assertInternalType('array', $returnProperties);
     $this->assertTrue(Category::existsInDatabase($returnProperties['id'], $returnProperties['table_name']));
     /* obviously, populate the demonstration table */
     Db::getInstance()->insert('demonstration', $returnProperties);
     $parentCategory = new Category($returnProperties['id']);
     /* create children category */
     $returnProperties2 = EntityFactory::createFromValues('categories', $this->fakeCategoryChildData(), $fixturesImgPath);
     $this->assertInternalType('array', $returnProperties2);
     $this->assertTrue(Category::existsInDatabase($returnProperties2['id'], $returnProperties2['table_name']));
     $childCategory = new Category($returnProperties['id']);
     $this->assertInstanceOf('Category', $parentCategory, sprintf(self::NOTICE . ' Category creation fails: expected Category, received %', gettype($childCategory)));
     $nbParents = count($childCategory->getAllParents());
     $this->assertSame(2, $nbParents, sprintf(self::NOTICE . ' Category creation fails: expected 2 parents (root & fixture one), received %', $nbParents));
     $parentCategory->delete();
     /* and remove entry from demonstration table */
     Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'demonstration` WHERE id =' . $parentCategory->id);
 }