27 $this->category = $this->getMockBuilder(\
Magento\Catalog\Model\Category::class)
28 ->disableOriginalConstructor()
29 ->setMethods([
'getPath',
'getResourceCollection',
'getResource',
'getLevel',
'__wakeup',
'isObjectNew'])
33 )->disableOriginalConstructor()->setMethods([
'addAttributeToSelect',
'addIdFilter'])->getMock();
34 $this->category->expects($this->any())->method(
'getPath')->willReturn(
'category-path');
35 $this->category->expects($this->any())->method(
'getResourceCollection')->willReturn(
$categoryCollection);
36 $categoryCollection->expects($this->any())->method(
'addAttributeToSelect')->willReturnSelf();
37 $categoryCollection->expects($this->any())->method(
'addIdFilter')->with([
'id'])->willReturnSelf();
38 $this->select = $this->getMockBuilder(\
Magento\Framework\DB\Select::class)
39 ->disableOriginalConstructor()->setMethods([
'from',
'where',
'deleteFromSelect'])->getMock();
40 $this->connection = $this->createMock(\
Magento\Framework\DB\Adapter\AdapterInterface::class);
42 ->disableOriginalConstructor()->getMock();
43 $this->category->expects($this->any())->method(
'getResource')->willReturn($categoryResource);
44 $categoryResource->expects($this->any())->method(
'getConnection')->willReturn($this->connection);
45 $this->connection->expects($this->any())->method(
'select')->willReturn($this->select);
46 $this->connection->expects($this->any())->method(
'quoteIdentifier')->willReturnArgument(0);
47 $this->select->expects($this->any())->method(
'from')->willReturnSelf();
49 $this->childrenCategoriesProvider = (
new ObjectManager($this))->getObject(
50 \
Magento\CatalogUrlRewrite\Model\
Category\ChildrenCategoriesProvider::class
56 $bind = [
'c_path' =>
'category-path/%'];
57 $this->category->expects($this->once())->method(
'isObjectNew')->willReturn(
false);
58 $this->select->expects($this->any())->method(
'where')->with(
'path LIKE :c_path')->willReturnSelf();
59 $this->connection->expects($this->any())->method(
'fetchCol')->with($this->select, $bind)->willReturn([
'id']);
60 $this->childrenCategoriesProvider->getChildren($this->category,
true);
65 $this->category->expects($this->once())->method(
'isObjectNew')->willReturn(
true);
66 $this->assertEquals([], $this->childrenCategoriesProvider->getChildren($this->category));
72 $this->select->expects($this->at(1))->method(
'where')->with(
'path LIKE :c_path')->willReturnSelf();
73 $this->select->expects($this->at(2))->method(
'where')->with(
'level <= :c_level')->willReturnSelf();
74 $this->category->expects($this->once())->method(
'isObjectNew')->willReturn(
false);
75 $this->category->expects($this->once())->method(
'getLevel')->willReturn($categoryLevel);
76 $bind = [
'c_path' =>
'category-path/%',
'c_level' => $categoryLevel + 1];
77 $this->connection->expects($this->any())->method(
'fetchCol')->with($this->select, $bind)->willReturn([
'id']);
79 $this->childrenCategoriesProvider->getChildren($this->category,
false);
testGetChildrenForNewCategory()
testGetChildrenRecursive()
$childrenCategoriesProvider