Esempio n. 1
0
 /**
  * Test the sGetWholeCategoryTree method.
  * This should now only return children when all parents are active
  * @ticket SW-5098
  */
 public function testGetWholeCategoryTree()
 {
     //set Category "Tees und Zubehör" to inactive so the childs should not be displayed
     $sql = "UPDATE `s_categories` SET `active` = '0' WHERE `id` =11";
     Shopware()->Db()->exec($sql);
     $allCategories = $this->module->sGetWholeCategoryTree(3, 3);
     //get "Genusswelten" this category should not have the inactive category "Tees and Zubehör" as subcategory
     $category = $this->getCategoryById($allCategories, 5);
     //search for Tees und Zubehör
     $result = $this->getCategoryById($category["sub"], 11);
     $this->assertEmpty($result);
     //if the parent category is inactive the child's should not be displayed
     //category = "Genusswelten" the active child "Tees" and "Tees und Zubehör" should not be return because the father ist inactive
     $result = $this->getCategoryById($category["sub"], 12);
     $this->assertEmpty($result);
     $result = $this->getCategoryById($category["sub"], 13);
     $this->assertEmpty($result);
     //set Category "Tees und Zubehör" to inactive so the childs should not be displayed
     $sql = "UPDATE `s_categories` SET `active` = '1' WHERE `id` = 11";
     Shopware()->Db()->exec($sql);
 }
 /**
  * @covers sCategories::sGetWholeCategoryTree
  */
 public function testsGetWholeCategoryTree()
 {
     // Calling on leaf node should return empty array
     $this->assertCount(0, $this->module->sGetWholeCategoryTree(21));
     // Default arguments should work
     $this->assertEquals($this->module->sGetWholeCategoryTree(), $this->module->sGetWholeCategoryTree(Shopware()->Shop()->get('parentID')));
     // Calling on root node should return a complete tree
     $categoryTree = $this->module->sGetWholeCategoryTree(1);
     foreach ($categoryTree as $category) {
         $this->assertArrayHasKey('id', $category);
         $this->assertArrayHasKey('sub', $category);
         $this->assertGreaterThan(0, count($category['sub']));
         $this->validateCategory($category, 'sub');
     }
     // Inactive categories are not loaded
     $inactive = Shopware()->Db()->fetchOne("SELECT parent FROM s_categories WHERE active = 0");
     $inactiveParentCategory = $this->module->sGetWholeCategoryTree($inactive);
     foreach ($inactiveParentCategory as $category) {
         $this->validateCategory($category, 'sub');
         $this->assertNotEquals($inactive, $category['id']);
     }
     // Depth argument should work as intended
     $categoryTree = $this->module->sGetWholeCategoryTree(1, 2);
     foreach ($categoryTree as $category) {
         $this->assertArrayHasKey('id', $category);
         $this->assertArrayHasKey('sub', $category);
         foreach ($category['sub'] as $subcategory) {
             $this->assertArrayHasKey('id', $subcategory);
             $this->assertArrayNotHasKey('sub', $subcategory);
         }
     }
     $categoryTree = $this->module->sGetWholeCategoryTree(1, 1);
     foreach ($categoryTree as $category) {
         $this->assertArrayHasKey('id', $category);
         $this->assertArrayNotHasKey('sub', $category);
     }
 }
Esempio n. 3
0
 /**
  * Returns a category tree.
  *
  * @param int $category
  * @param int $depth
  * @return array
  */
 public function getCategoryTree($category, $depth = null)
 {
     return $this->module->sGetWholeCategoryTree($category, $depth);
 }