Category PHP Class Code Examples

This page contains top rated real world PHP examples of class Category extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: LoadCategoryData.php Project: sidczak-tti/blog
0
 public function load(ObjectManager $em)
 {
     $forum = new Category();
     $forum->setName('Forum tutorial');
     $forum->setDescription('Forum Description');
     $forum->setImage('forum.jpg');
     $forum->setIsActive(1);
     $blog = new Category();
     $blog->setName('Blog tutorial');
     $blog->setDescription('Blog Description');
     $blog->setImage('blog.jpg');
     $blog->setIsActive(1);
     $shop = new Category();
     $shop->setName('Shop tutorial');
     $shop->setDescription('Shop Description');
     $shop->setImage('shop.jpg');
     $shop->setIsActive(1);
     $em->persist($forum);
     $em->persist($blog);
     $em->persist($shop);
     $em->flush();
     $this->addReference('category-forum', $forum);
     $this->addReference('category-blog', $blog);
     $this->addReference('category-shop', $shop);
 }
Example #2
Show file File: shopimporter.php Project: toufikadfab/PrestaShop-1.5
0
 private function updateCat()
 {
     $moduleName = Tools::getValue('moduleName');
     Db::getInstance()->execute('UPDATE
						' . _DB_PREFIX_ . 'category c
						INNER JOIN
						' . _DB_PREFIX_ . 'category c2
						ON
						c.id_parent = c2.`id_category_' . bqSQL($moduleName) . '`
						SET
						c.id_parent = c2.id_category
						WHERE c.`id_category_' . bqSQL($moduleName) . '` != 0
						AND c.`id_parent` != 0');
     // get PS home category
     Db::getInstance()->execute('UPDATE ' . _DB_PREFIX_ . 'category c
						SET c.id_parent = ' . Configuration::get('PS_HOME_CATEGORY') . '
						WHERE c.`id_category_' . bqSQL($moduleName) . '` != 0
						AND c.`id_parent` = 0');
     $category = new Category();
     $cats = $category->getSimpleCategories((int) Configuration::get('PS_LANG_DEFAULT'));
     foreach ($cats as $cat) {
         $cat = new Category((int) $cat['id_category']);
         $cat->level_depth = $cat->calcLevelDepth();
         $cat->update();
     }
 }
Example #3
Show file File: Issue827Test.php Project: saberyounis/Sonata-Project
0
 /**
  * @test
  * @group issue827
  */
 public function handlePersistedSlugsForForeignKeyUniqueBased()
 {
     // Creating categories
     $testCat1 = new Category();
     $testCat1->setTitle('Category1');
     $this->em->persist($testCat1);
     $testCat11 = new Category();
     $testCat11->setTitle('Category1');
     $this->em->persist($testCat11);
     $testCat2 = new Category();
     $testCat2->setTitle('Category2');
     $this->em->persist($testCat2);
     // Creating articles
     $test = new Article();
     $test->setTitle('Unique to category 1');
     $test->setCategory($testCat1);
     $this->em->persist($test);
     $test2 = new Article();
     $test2->setTitle('Unique to category 2');
     $test2->setCategory($testCat2);
     $this->em->persist($test2);
     $test3 = new Article();
     $test3->setTitle('Unique to category 1');
     $test3->setCategory($testCat1);
     $this->em->persist($test3);
     $this->em->flush();
     $this->assertEquals('category1', $testCat1->getSlug());
     $this->assertEquals('category1-1', $testCat11->getSlug());
     $this->assertEquals('category2', $testCat2->getSlug());
     $this->assertEquals('unique-to-category-1', $test->getSlug());
     $this->assertEquals('unique-to-category-2', $test2->getSlug());
     $this->assertEquals('unique-to-category-1-1', $test3->getSlug());
 }
Example #4
Show file File: LoadCategoryData.php Project: sidczak-tti/blog2.8
0
 public function load(ObjectManager $em)
 {
     $no_category = new Category();
     $no_category->setName('No category');
     $no_category->setDescription('Desktops No category');
     $no_category->setImage('no-category.jpg');
     $no_category->setIsActive(1);
     $blog = new Category();
     $blog->setName('Blog');
     $blog->setDescription('Blog Description');
     $blog->setImage('blog.jpg');
     $blog->setIsActive(1);
     $shop = new Category();
     $shop->setName('Shop');
     $shop->setDescription('Shop Description');
     $shop->setImage('shop.jpg');
     $shop->setIsActive(1);
     $em->persist($no_category);
     $em->persist($blog);
     $em->persist($shop);
     $em->flush();
     $this->addReference('category-no_category', $no_category);
     $this->addReference('category-blog', $blog);
     $this->addReference('category-shop', $shop);
 }
Example #5
Show file File: Category.php Project: shabbirvividads/magento2
0
 /**
  * Move category to another parent node
  *
  * @param \Magento\Catalog\Model\Category $category
  * @param \Magento\Catalog\Model\Category $newParent
  * @param null|int $afterCategoryId
  * @return $this
  */
 public function changeParent(\Magento\Catalog\Model\Category $category, \Magento\Catalog\Model\Category $newParent, $afterCategoryId = null)
 {
     $childrenCount = $this->getChildrenCount($category->getId()) + 1;
     $table = $this->getEntityTable();
     $adapter = $this->_getWriteAdapter();
     $levelFiled = $adapter->quoteIdentifier('level');
     $pathField = $adapter->quoteIdentifier('path');
     /**
      * Decrease children count for all old category parent categories
      */
     $adapter->update($table, ['children_count' => new \Zend_Db_Expr('children_count - ' . $childrenCount)], ['entity_id IN(?)' => $category->getParentIds()]);
     /**
      * Increase children count for new category parents
      */
     $adapter->update($table, ['children_count' => new \Zend_Db_Expr('children_count + ' . $childrenCount)], ['entity_id IN(?)' => $newParent->getPathIds()]);
     $position = $this->_processPositions($category, $newParent, $afterCategoryId);
     $newPath = sprintf('%s/%s', $newParent->getPath(), $category->getId());
     $newLevel = $newParent->getLevel() + 1;
     $levelDisposition = $newLevel - $category->getLevel();
     /**
      * Update children nodes path
      */
     $adapter->update($table, ['path' => new \Zend_Db_Expr('REPLACE(' . $pathField . ',' . $adapter->quote($category->getPath() . '/') . ', ' . $adapter->quote($newPath . '/') . ')'), 'level' => new \Zend_Db_Expr($levelFiled . ' + ' . $levelDisposition)], [$pathField . ' LIKE ?' => $category->getPath() . '/%']);
     /**
      * Update moved category data
      */
     $data = ['path' => $newPath, 'level' => $newLevel, 'position' => $position, 'parent_id' => $newParent->getId()];
     $adapter->update($table, $data, ['entity_id = ?' => $category->getId()]);
     // Update category object to new data
     $category->addData($data);
     $category->unsetData('path_ids');
     return $this;
 }
Example #6
Show file File: CartContainsCategoriesTest.php Project: margery/thelia
0
 /**
  * Generate adapter stub
  *
  * @param int    $cartTotalPrice   Cart total price
  * @param string $checkoutCurrency Checkout currency
  * @param string $i18nOutput       Output from each translation
  *
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
 {
     $stubFacade = $this->getMockBuilder('\\Thelia\\Coupon\\BaseFacade')->disableOriginalConstructor()->getMock();
     $stubFacade->expects($this->any())->method('getCartTotalPrice')->will($this->returnValue($cartTotalPrice));
     $stubFacade->expects($this->any())->method('getCheckoutCurrency')->will($this->returnValue($checkoutCurrency));
     $stubFacade->expects($this->any())->method('getConditionEvaluator')->will($this->returnValue(new ConditionEvaluator()));
     $stubTranslator = $this->getMockBuilder('\\Thelia\\Core\\Translation\\Translator')->disableOriginalConstructor()->getMock();
     $stubTranslator->expects($this->any())->method('trans')->will($this->returnValue($i18nOutput));
     $stubFacade->expects($this->any())->method('getTranslator')->will($this->returnValue($stubTranslator));
     $category1 = new Category();
     $category1->setId(10);
     $category2 = new Category();
     $category2->setId(20);
     $category3 = new Category();
     $category3->setId(30);
     $product1 = new Product();
     $product1->addCategory($category1)->addCategory($category2);
     $product2 = new Product();
     $product2->addCategory($category3);
     $cartItem1Stub = $this->getMockBuilder('\\Thelia\\Model\\CartItem')->disableOriginalConstructor()->getMock();
     $cartItem1Stub->expects($this->any())->method('getProduct')->will($this->returnValue($product1));
     $cartItem1Stub->expects($this->any())->method('getQuantity')->will($this->returnValue(1));
     $cartItem2Stub = $this->getMockBuilder('\\Thelia\\Model\\CartItem')->disableOriginalConstructor()->getMock();
     $cartItem2Stub->expects($this->any())->method('getProduct')->will($this->returnValue($product2));
     $cartItem2Stub->expects($this->any())->method('getQuantity')->will($this->returnValue(2));
     $cartStub = $this->getMockBuilder('\\Thelia\\Model\\Cart')->disableOriginalConstructor()->getMock();
     $cartStub->expects($this->any())->method('getCartItems')->will($this->returnValue([$cartItem1Stub, $cartItem2Stub]));
     $stubFacade->expects($this->any())->method('getCart')->will($this->returnValue($cartStub));
     return $stubFacade;
 }
Example #7
Show file File: EntityObjectNormalizerTest.php Project: Maksold/platform
0
 /**
  * @return Entity\Product
  */
 protected function createProductEntity()
 {
     $product = new Entity\Product();
     $product->setId(123);
     $product->setName('product_name');
     $product->setUpdatedAt(new \DateTime('2015-12-01 10:20:30', new \DateTimeZone('UTC')));
     $category = new Entity\Category();
     $category->setName('category_name');
     $category->setLabel('category_label');
     $product->setCategory($category);
     $owner = new Entity\User();
     $owner->setId(456);
     $owner->setName('user_name');
     $ownerCategory = new Entity\Category();
     $ownerCategory->setName('owner_category_name');
     $ownerCategory->setLabel('owner_category_label');
     $owner->setCategory($ownerCategory);
     $ownerGroup1 = new Entity\Group();
     $ownerGroup1->setId(11);
     $ownerGroup1->setName('owner_group1');
     $owner->addGroup($ownerGroup1);
     $ownerGroup2 = new Entity\Group();
     $ownerGroup2->setId(22);
     $ownerGroup2->setName('owner_group2');
     $owner->addGroup($ownerGroup2);
     $owner->addProduct($product);
     return $product;
 }
Example #8
Show file File: AdminShopController.php Project: toufikadfab/PrestaShop-1.5
0
 public function initCategoriesAssociation($id_root = null)
 {
     if (is_null($id_root)) {
         $id_root = Configuration::get('PS_ROOT_CATEGORY');
     }
     $id_shop = (int) Tools::getValue('id_shop');
     $shop = new Shop($id_shop);
     $selected_cat = Shop::getCategories($id_shop);
     if (empty($selected_cat)) {
         // get first category root and preselect all these children
         $root_categories = Category::getRootCategories();
         $root_category = new Category($root_categories[0]['id_category']);
         $children = $root_category->getAllChildren($this->context->language->id);
         $selected_cat[] = $root_categories[0]['id_category'];
         foreach ($children as $child) {
             $selected_cat[] = $child->id;
         }
     }
     if (Shop::getContext() == Shop::CONTEXT_SHOP && Tools::isSubmit('id_shop')) {
         $root_category = new Category($shop->id_category);
     } else {
         $root_category = new Category($id_root);
     }
     $root_category = array('id_category' => $root_category->id, 'name' => $root_category->name[$this->context->language->id]);
     $helper = new Helper();
     return $helper->renderCategoryTree($root_category, $selected_cat, 'categoryBox', false, true);
 }
Example #9
Show file File: UpdateCategoryEntityTest.php Project: pradeep-wagento/magento2
0
 /**
  * Test for update category
  *
  * @param Category $category
  * @param Category $initialCategory
  * @return void
  */
 public function test(Category $category, Category $initialCategory)
 {
     $this->catalogCategoryIndex->open();
     $this->catalogCategoryIndex->getTreeCategories()->selectCategory($initialCategory);
     $this->catalogCategoryEdit->getEditForm()->fill($category);
     $this->catalogCategoryEdit->getFormPageActions()->save();
 }
Example #10
Show file File: InstallController.php Project: Brother-Simon/easyii-shop
0
 public function insertCatalog()
 {
     if (catalog\models\Category::find()->count()) {
         return '`<b>' . catalog\models\Category::tableName() . '</b>` table is not empty, skipping...';
     }
     $this->db->createCommand('TRUNCATE TABLE `' . catalog\models\Category::tableName() . '`')->query();
     $fields = [['name' => 'brand', 'title' => 'Brand', 'type' => 'select', 'options' => ['Samsung', 'Apple', 'Nokia']], ['name' => 'storage', 'title' => 'Storage', 'type' => 'string', 'options' => ''], ['name' => 'touchscreen', 'title' => 'Touchscreen', 'type' => 'boolean', 'options' => ''], ['name' => 'cpu', 'title' => 'CPU cores', 'type' => 'select', 'options' => ['1', '2', '4', '8']], ['name' => 'features', 'title' => 'Features', 'type' => 'checkbox', 'options' => ['Wi-fi', '4G', 'GPS']], ['name' => 'color', 'title' => 'Color', 'type' => 'checkbox', 'options' => ['White', 'Black', 'Red', 'Blue']]];
     $root = new catalog\models\Category(['title' => 'Gadgets', 'fields' => $fields]);
     $root->makeRoot();
     $cat1 = new catalog\models\Category(['title' => 'Smartphones', 'fields' => $fields]);
     $cat1->appendTo($root);
     $this->attachSeo($cat1, 'Smartphones H1', 'Extended smartphones title');
     $cat2 = new catalog\models\Category(['title' => 'Tablets', 'fields' => $fields]);
     $cat2->appendTo($root);
     $this->attachSeo($cat2, 'Tablets H1', 'Extended tablets title');
     if (catalog\models\Item::find()->count()) {
         return '`<b>' . catalog\models\Item::tableName() . '</b>` table is not empty, skipping...';
     }
     $time = time();
     $item1 = new catalog\models\Item(['category_id' => $cat1->primaryKey, 'title' => 'Nokia 3310', 'description' => '<h3>The legend</h3><p>The Nokia 3310 is a GSMmobile phone announced on September 1, 2000, and released in the fourth quarter of the year, replacing the popular Nokia 3210. The phone sold extremely well, being one of the most successful phones with 126 million units sold worldwide.&nbsp;The phone has since received a cult status and is still widely acclaimed today.</p><p>The 3310 was developed at the Copenhagen Nokia site in Denmark. It is a compact and sturdy phone featuring an 84 × 48 pixel pure monochrome display. It has a lighter 115 g battery variant which has fewer features; for example the 133 g battery version has the start-up image of two hands touching while the 115 g version does not. It is a slightly rounded rectangular unit that is typically held in the palm of a hand, with the buttons operated with the thumb. The blue button is the main button for selecting options, with "C" button as a "back" or "undo" button. Up and down buttons are used for navigation purposes. The on/off/profile button is a stiff black button located on the top of the phone.</p>', 'available' => 5, 'discount' => 0, 'price' => 100, 'data' => ['brand' => 'Nokia', 'storage' => '1', 'touchscreen' => '0', 'cpu' => 1, 'color' => ['White', 'Red', 'Blue']], 'image' => '/uploads/catalog/3310.jpg', 'time' => $time]);
     $item1->save();
     $this->attachPhotos($item1, ['/uploads/photos/3310-1.jpg', '/uploads/photos/3310-2.jpg']);
     $this->attachSeo($item1, 'Nokia 3310');
     $item2 = new catalog\models\Item(['category_id' => $cat1->primaryKey, 'title' => 'Galaxy S6', 'description' => '<h3>Next is beautifully crafted</h3><p>With their slim, seamless, full metal and glass construction, the sleek, ultra thin edged Galaxy S6 and unique, dual curved Galaxy S6 edge are crafted from the finest materials.</p><p>And while they may be the thinnest smartphones we`ve ever created, when it comes to cutting-edge technology and flagship Galaxy experience, these 5.1" QHD Super AMOLED smartphones are certainly no lightweights.</p>', 'available' => 1, 'discount' => 10, 'price' => 1000, 'data' => ['brand' => 'Samsung', 'storage' => '32', 'touchscreen' => '1', 'cpu' => 8, 'features' => ['Wi-fi', 'GPS']], 'image' => '/uploads/catalog/galaxy.jpg', 'time' => $time - 86400]);
     $item2->save();
     $this->attachPhotos($item2, ['/uploads/photos/galaxy-1.jpg', '/uploads/photos/galaxy-2.jpg', '/uploads/photos/galaxy-3.jpg', '/uploads/photos/galaxy-4.jpg']);
     $this->attachSeo($item2, 'Samsung Galaxy S6');
     $item3 = new catalog\models\Item(['category_id' => $cat1->primaryKey, 'title' => 'Iphone 6', 'description' => '<h3>Next is beautifully crafted</h3><p>With their slim, seamless, full metal and glass construction, the sleek, ultra thin edged Galaxy S6 and unique, dual curved Galaxy S6 edge are crafted from the finest materials.</p><p>And while they may be the thinnest smartphones we`ve ever created, when it comes to cutting-edge technology and flagship Galaxy experience, these 5.1" QHD Super AMOLED smartphones are certainly no lightweights.</p>', 'available' => 0, 'discount' => 10, 'price' => 1100, 'data' => ['brand' => 'Apple', 'storage' => '64', 'touchscreen' => '1', 'cpu' => 4, 'features' => ['Wi-fi', '4G', 'GPS']], 'image' => '/uploads/catalog/iphone.jpg', 'time' => $time - 86400 * 2]);
     $item3->save();
     $this->attachPhotos($item3, ['/uploads/photos/iphone-1.jpg', '/uploads/photos/iphone-2.jpg', '/uploads/photos/iphone-3.jpg', '/uploads/photos/iphone-4.jpg']);
     $this->attachSeo($item3, 'Apple Iphone 6');
     return 'Catalog data inserted.';
 }
Example #11
Show file File: InstallController.php Project: Brother-Simon/easyii-shop
0
 public function insertArticles()
 {
     if (article\models\Category::find()->count()) {
         return '`<b>' . article\models\Category::tableName() . '</b>` table is not empty, skipping...';
     }
     $this->db->createCommand('TRUNCATE TABLE `' . article\models\Category::tableName() . '`')->query();
     $root1 = new article\models\Category(['title' => 'Articles category 1', 'order_num' => 2]);
     $root1->makeRoot();
     $this->attachSeo($root1, 'Articles category 1 H1', 'Extended category 1 title');
     $root2 = new article\models\Category(['title' => 'Articles category 2', 'order_num' => 1]);
     $root2->makeRoot();
     $subcat1 = new article\models\Category(['title' => 'Subcategory 1', 'order_num' => 1]);
     $subcat1->appendTo($root2);
     $this->attachSeo($subcat1, 'Subcategory 1 H1', 'Extended subcategory 1 title');
     $subcat2 = new article\models\Category(['title' => 'Subcategory 1', 'order_num' => 1]);
     $subcat2->appendTo($root2);
     $this->attachSeo($subcat2, 'Subcategory 2 H1', 'Extended subcategory 2 title');
     if (article\models\Item::find()->count()) {
         return '`<b>' . article\models\Item::tableName() . '</b>` table is not empty, skipping...';
     }
     $this->db->createCommand('TRUNCATE TABLE `' . article\models\Item::tableName() . '`')->query();
     $time = time();
     $article1 = new article\models\Item(['category_id' => $root1->primaryKey, 'title' => 'First article title', 'image' => '/uploads/article/article-1.jpg', 'short' => 'At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt molliti', 'text' => '<p><strong>Sed ut perspiciatis</strong>, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos, qui ratione voluptatem sequi nesciunt, neque porro quisquam est, qui dolorem ipsum, quia dolor sit, amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt, ut labore et dolore magnam aliquam quaerat voluptatem.&nbsp;</p><ul><li>item 1</li><li>item 2</li><li>item 3</li></ul><p>ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur?</p>', 'tagNames' => 'php, css, bootstrap', 'time' => $time]);
     $article1->save();
     $this->attachPhotos($article1, ['/uploads/photos/article-1-1.jpg', '/uploads/photos/article-1-2.jpg', '/uploads/photos/article-1-3.jpg', '/uploads/photos/news-1-4.jpg']);
     $this->attachSeo($article1, 'First article H1');
     $article2 = new article\models\Item(['category_id' => $root1->primaryKey, 'title' => 'Second article title', 'image' => '/uploads/article/article-2.jpg', 'short' => 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip', 'text' => '<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p><ol> <li>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. </li><li>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</li></ol>', 'tagNames' => 'yii2, jquery, ajax', 'time' => $time - 86400]);
     $article2->save();
     $this->attachSeo($article2, 'Second article H1');
     $article3 = new article\models\Item(['category_id' => $root1->primaryKey, 'title' => 'Third article title', 'image' => '/uploads/article/article-3.jpg', 'short' => 'At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt molliti', 'text' => '<p>At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.</p>', 'time' => $time - 86400 * 2]);
     $article3->save();
     $this->attachSeo($article3, 'Third article H1');
     return 'Articles data inserted.';
 }
Example #12
Show file File: ResourceDeletionTest.php Project: gbelmm/ACL
0
 /**
  * Here we delete a resource which had no direct roles associated. However it had authorizations
  * because of a parent resource.
  *
  * @link https://github.com/myclabs/ACL/issues/12
  */
 public function testDeletionWithCascade()
 {
     $category = new Category();
     $this->em->persist($category);
     $subCategory = new Category($category);
     $this->em->persist($subCategory);
     $user = new User();
     $this->em->persist($user);
     $this->em->flush();
     // We apply a role on the parent resource, authorizations will cascade to the sub-resource
     $this->acl->grant($user, new CategoryManagerRole($user, $category));
     $this->assertTrue($this->acl->isAllowed($user, Actions::VIEW, $category));
     $this->assertTrue($this->acl->isAllowed($user, Actions::VIEW, $subCategory));
     // We need to reload the resource because the role hasn't been added automatically to
     // the role collection in Category
     $this->em->refresh($category);
     // Now we delete the sub-resource
     $this->em->remove($subCategory);
     $this->em->flush();
     // We check that the authorization is deleted (there should be 1 left: the one for the parent category)
     $query = $this->em->createQuery('SELECT COUNT(a.id) FROM MyCLabs\\ACL\\Model\\Authorization a');
     $this->assertEquals(1, $query->getSingleScalarResult(), "The child authorization wasn't deleted");
     // We check that the role is not deleted
     $query = $this->em->createQuery('SELECT COUNT(r.id) FROM Tests\\MyCLabs\\ACL\\Integration\\Model\\CategoryManagerRole r');
     $this->assertEquals(1, $query->getSingleScalarResult());
     // We check that isAllowed still works with the parent resource (which wasn't deleted)
     $this->assertTrue($this->acl->isAllowed($user, Actions::VIEW, $category));
 }
Frequently Used Methods