public function testToOptionArray()
 {
     $matchingNamesCollection = $this->getCategoryCollectionMock([$this->getCategoryMock(['path' => '1/2']), $this->getCategoryMock(['path' => '1/3']), $this->getCategoryMock(['path' => '1/3/4']), $this->getCategoryMock(['path' => '1/2/5']), $this->getCategoryMock(['path' => '1/3/4/6']), $this->getCategoryMock(['path' => '1/7']), $this->getCategoryMock(['path' => '1/8']), $this->getCategoryMock(['path' => '1/7/9'])]);
     $collection = $this->getCategoryCollectionMock([$this->getCategoryMock(['id' => '2', 'parent_id' => '1', 'name' => 'Category 2', 'is_active' => '1']), $this->getCategoryMock(['id' => '3', 'parent_id' => '1', 'name' => 'Category 3', 'is_active' => '0']), $this->getCategoryMock(['id' => '4', 'parent_id' => '3', 'name' => 'Category 4', 'is_active' => '1']), $this->getCategoryMock(['id' => '5', 'parent_id' => '2', 'name' => 'Category 5', 'is_active' => '1']), $this->getCategoryMock(['id' => '6', 'parent_id' => '4', 'name' => 'Category 6', 'is_active' => '1']), $this->getCategoryMock(['id' => '7', 'parent_id' => '1', 'name' => 'Category 7', 'is_active' => '0']), $this->getCategoryMock(['id' => '8', 'parent_id' => '1', 'name' => 'Category 8', 'is_active' => '1']), $this->getCategoryMock(['id' => '9', 'parent_id' => '7', 'name' => 'Category 9', 'is_active' => '1'])]);
     $result = [['value' => '2', 'is_active' => '1', 'label' => 'Category 2', 'optgroup' => [['value' => '5', 'is_active' => '1', 'label' => 'Category 5']]], ['value' => '3', 'is_active' => '0', 'label' => 'Category 3', 'optgroup' => [['value' => '4', 'is_active' => '1', 'label' => 'Category 4', 'optgroup' => [['value' => '6', 'is_active' => '1', 'label' => 'Category 6']]]]], ['value' => '7', 'is_active' => '0', 'label' => 'Category 7', 'optgroup' => [['value' => '9', 'is_active' => '1', 'label' => 'Category 9']]], ['value' => '8', 'is_active' => '1', 'label' => 'Category 8']];
     $this->categoryCollectionFactoryMock->expects($this->any())->method('create')->willReturnOnConsecutiveCalls($matchingNamesCollection, $collection);
     $this->assertSame($result, $this->categoriesOptions->toOptionArray());
 }
 protected function setUp()
 {
     parent::setUp();
     $this->categoryCollectionFactoryMock = $this->getMockBuilder(CategoryCollectionFactory::class)->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->dbHelperMock = $this->getMockBuilder(DbHelper::class)->disableOriginalConstructor()->getMock();
     $this->urlBuilderMock = $this->getMockBuilder(UrlInterface::class)->getMockForAbstractClass();
     $this->storeMock = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock();
     $this->categoryCollectionMock = $this->getMockBuilder(CategoryCollection::class)->disableOriginalConstructor()->getMock();
     $this->categoryCollectionFactoryMock->expects($this->any())->method('create')->willReturn($this->categoryCollectionMock);
     $this->categoryCollectionMock->expects($this->any())->method('addAttributeToSelect')->willReturnSelf();
     $this->categoryCollectionMock->expects($this->any())->method('addAttributeToFilter')->willReturnSelf();
     $this->categoryCollectionMock->expects($this->any())->method('setStoreId')->willReturnSelf();
     $this->categoryCollectionMock->expects($this->any())->method('getIterator')->willReturn(new \ArrayIterator([]));
 }
 public function testGetCount()
 {
     $categoriesMock = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Category\\Collection', [], [], '', false);
     $this->categoriesFactoryMock->expects($this->once())->method('create')->willReturn($categoriesMock);
     $categoriesMock->expects($this->once())->method('addAttributeToFilter')->with('parent_id', ['gt' => 0])->willReturnSelf();
     $categoriesMock->expects($this->once())->method('getSize')->willReturn('expected');
     $this->assertEquals('expected', $this->model->getCount());
 }