示例#1
0
 public function testCreate()
 {
     $categorySdo = $this->getMockBuilder('Magento\\Catalog\\Service\\V1\\Data\\Category')->disableOriginalConstructor()->getMock();
     $this->categoryMapper->expects($this->any())->method('toModel')->with($categorySdo)->will($this->returnValue($this->category));
     $this->category->expects($this->once())->method('validate')->will($this->returnValue([]));
     $this->category->expects($this->once())->method('save');
     $parentCategory = $this->getMockBuilder('Magento\\Catalog\\Model\\Category')->disableOriginalConstructor()->getMock();
     $parentCategory->expects($this->any())->method('load')->will($this->returnSelf());
     $parentCategory->expects($this->any())->method('__call')->with('getPath')->will($this->returnValue('1\\2'));
     $categoryFactory = $this->getMockBuilder('Magento\\Catalog\\Model\\CategoryFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $categoryFactory->expects($this->any())->method('create')->will($this->returnValue($parentCategory));
     $parentId = 1;
     $storeManager = $this->getMock('Magento\\Store\\Model\\StoreManager', [], [], '', false);
     $store = $this->getMock('Magento\\Store\\Model\\Store', ['getRootCategoryId', '__sleep', '__wakeup'], [], '', false);
     $store->expects($this->any())->method('getRootCategoryId')->will($this->returnValue($parentId));
     $storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
     $this->model = (new ObjectManager($this))->getObject('Magento\\Catalog\\Service\\V1\\Category\\WriteService', ['categoryFactory' => $categoryFactory, 'categoryMapper' => $this->categoryMapper, 'storeManager' => $storeManager]);
     $this->model->create($categorySdo);
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function update($categoryId, CategoryDataObject $category)
 {
     $model = $this->loadCategory($categoryId);
     try {
         $this->categoryMapper->toModel($category, $model);
         $this->validateCategory($model);
         $model->save();
     } catch (\Exception $e) {
         throw new CouldNotSaveException('Could not save category', [], $e);
     }
     return true;
 }