public function testUpdateUrlPathForChildren()
 {
     $this->category->expects($this->once())->method('getUrlKey')->willReturn('category');
     $this->category->expects($this->once())->method('setUrlKey')->willReturnSelf();
     $this->category->expects($this->once())->method('setUrlPath')->willReturnSelf();
     $this->category->expects($this->once())->method('isObjectNew')->willReturn(false);
     $this->category->expects($this->once())->method('dataHasChangedFor')->with('url_path')->willReturn(true);
     $categoryResource = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Category')->disableOriginalConstructor()->getMock();
     $this->category->expects($this->once())->method('getResource')->willReturn($categoryResource);
     $categoryResource->expects($this->once())->method('saveAttribute')->with($this->category, 'url_path');
     $childCategory = $this->getMockBuilder('Magento\\Catalog\\Model\\Category')->setMethods(['getUrlPath', 'setUrlPath', 'getResource', 'unsUrlPath'])->disableOriginalConstructor()->getMock();
     $this->childrenCategoriesProvider->expects($this->once())->method('getChildren')->willReturn([$childCategory]);
     $childCategoryResource = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Category')->disableOriginalConstructor()->getMock();
     $childCategory->expects($this->once())->method('unsUrlPath')->willReturnSelf();
     $childCategory->expects($this->once())->method('getResource')->willReturn($childCategoryResource);
     $childCategoryResource->expects($this->once())->method('saveAttribute')->with($childCategory, 'url_path');
     $childCategory->expects($this->once())->method('setUrlPath')->with('category-url_path')->willReturnSelf();
     $this->categoryUrlPathGenerator->expects($this->any())->method('getUrlPath')->willReturn('category-url_path');
     $this->categoryUrlPathAutogeneratorObserver->execute($this->observer);
 }
 public function testChildrenUrlPathAttributeUpdatingForSpecificStore()
 {
     $this->categoryUrlPathGenerator->expects($this->any())->method('getUrlKey')->willReturn('generated_url_key');
     $this->categoryUrlPathGenerator->expects($this->any())->method('getUrlPath')->willReturn('generated_url_path');
     $this->category->expects($this->any())->method('getUrlKey')->willReturn('not_formatted_url_key');
     $this->category->expects($this->any())->method('setUrlKey')->willReturnSelf();
     $this->category->expects($this->any())->method('setUrlPath')->willReturnSelf();
     $this->category->expects($this->any())->method('isObjectNew')->willReturn(false);
     $this->category->expects($this->any())->method('dataHasChangedFor')->willReturn(true);
     // only for specific store
     $this->category->expects($this->atLeastOnce())->method('getStoreId')->willReturn(1);
     $childCategoryResource = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Category')->disableOriginalConstructor()->getMock();
     $childCategory = $this->getMockBuilder('Magento\\Catalog\\Model\\Category')->setMethods(['getUrlPath', 'setUrlPath', 'getResource', 'getStore', 'getStoreId', 'setStoreId'])->disableOriginalConstructor()->getMock();
     $childCategory->expects($this->any())->method('getResource')->willReturn($childCategoryResource);
     $childCategory->expects($this->once())->method('setStoreId')->with(1);
     $this->childrenCategoriesProvider->expects($this->once())->method('getChildren')->willReturn([$childCategory]);
     $childCategory->expects($this->once())->method('setUrlPath')->with('generated_url_path')->willReturnSelf();
     $childCategoryResource->expects($this->once())->method('saveAttribute')->with($childCategory, 'url_path');
     $this->categoryUrlPathAutogeneratorObserver->execute($this->observer);
 }