public function testChildProductCategories() { $childProductCategory = new ProductCategory(); $childProductCategory->name = "My Test Category Child"; $existingCats = ProductCategory::getByName('My Test Category'); $childProductCategory->productCategory = $existingCats[0]; $this->assertTrue($childProductCategory->save()); $id = $childProductCategory->id; unset($childProductCategory); $childProductCategory = ProductCategory::getById($id); $this->assertEquals("My Test Category Child", $childProductCategory->name); $this->assertEquals("My Test Category", $existingCats[0]->name); }
public function testSuperUserCreateAction() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); Yii::app()->user->userModel = $super; $this->resetGetArray(); $superCategoryId = self::getModelIdByModelNameAndName('ProductCategory', 'My Category 1'); $productCategory = array(); $productCategory['name'] = 'Red Widget'; $productCategoryParent = array('id' => $superCategoryId); $productCategory['productCategory'] = $productCategoryParent; $this->setPostArray(array('ProductCategory' => $productCategory)); $redirectUrl = $this->runControllerWithRedirectExceptionAndGetUrl('productTemplates/category/create'); $productCategories = ProductCategory::getByName('Red Widget'); $this->assertEquals(1, count($productCategories)); $this->assertTrue($productCategories[0]->id > 0); $this->assertEquals($superCategoryId, $productCategories[0]->productCategory->id); $compareRedirectUrl = Yii::app()->createUrl('productTemplates/category/details', array('id' => $productCategories[0]->id)); $this->assertEquals($compareRedirectUrl, $redirectUrl); }