9
9
10
10
namespace Magento \Catalog \Test \Unit \Model ;
11
11
12
+ use Magento \Catalog \Api \Data \ProductAttributeInterface ;
13
+ use Magento \Catalog \Api \Data \ProductAttributeSearchResultsInterface ;
14
+ use Magento \Catalog \Model \ResourceModel \Product \Collection ;
12
15
use Magento \Framework \Api \Data \ImageContentInterface ;
16
+ use Magento \Framework \Api \ExtensionAttribute \JoinProcessorInterface ;
13
17
use Magento \Framework \Api \SortOrder ;
14
18
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
15
19
use Magento \Store \Api \Data \StoreInterface ;
@@ -154,6 +158,11 @@ class ProductRepositoryTest extends \PHPUnit_Framework_TestCase
154
158
*/
155
159
private $ optionConverterMock ;
156
160
161
+ /**
162
+ * @var JoinProcessorInterface|\PHPUnit_Framework_MockObject_MockObject
163
+ */
164
+ private $ extensionAttributesJoinProcessor ;
165
+
157
166
/**
158
167
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
159
168
*/
@@ -323,6 +332,9 @@ protected function setUp()
323
332
$ this ->optionConverterMock = $ this ->getMockBuilder (\Magento \Catalog \Model \Product \Option \Converter::class)
324
333
->disableOriginalConstructor ()
325
334
->getMock ();
335
+ $ this ->extensionAttributesJoinProcessor = $ this ->getMockBuilder (JoinProcessorInterface::class)
336
+ ->disableOriginalConstructor ()
337
+ ->getMock ();
326
338
327
339
$ this ->model = $ this ->objectManager ->getObject (
328
340
\Magento \Catalog \Model \ProductRepository::class,
@@ -348,6 +360,7 @@ protected function setUp()
348
360
'imageProcessor ' => $ this ->imageProcessorMock ,
349
361
'extensionAttributesJoinProcessor ' => $ this ->extensionAttributesJoinProcessorMock ,
350
362
'mediaGalleryProcessor ' => $ this ->mediaGalleryProcessor ,
363
+ 'extensionAttributesJoinProcessor ' => $ this ->extensionAttributesJoinProcessor ,
351
364
]
352
365
);
353
366
}
@@ -672,85 +685,95 @@ public function testDeleteById()
672
685
*/
673
686
public function testGetList ($ fieldName )
674
687
{
675
- $ searchCriteriaMock = $ this ->getMock (\Magento \Framework \Api \SearchCriteriaInterface::class, [], [], '' , false );
676
688
$ attributeCode = 'attribute_code ' ;
677
- $ collectionMock = $ this ->getMock (
678
- \Magento \Catalog \Model \ResourceModel \Product \Collection::class,
679
- [],
680
- [],
681
- '' ,
682
- false
683
- );
684
- $ extendedSearchCriteriaMock = $ this ->getMock (\Magento \Framework \Api \SearchCriteria::class, [], [], '' , false );
685
- $ productAttributeSearchResultsMock = $ this ->getMock (
686
- \Magento \Framework \Api \SearchResults::class,
687
- [],
688
- [],
689
- '' ,
690
- false
691
- );
692
- $ productAttributeMock = $ this ->getMock (
693
- \Magento \Catalog \Api \Data \ProductAttributeInterface::class,
694
- [],
695
- [],
696
- '' ,
697
- false
698
- );
699
- $ filterGroupMock = $ this ->getMock (\Magento \Framework \Api \Search \FilterGroup::class, [], [], '' , false );
700
- $ filterGroupFilterMock = $ this ->getMock (\Magento \Framework \Api \Filter::class, [], [], '' , false );
701
- $ sortOrderMock = $ this ->getMock (\Magento \Framework \Api \SortOrder::class, [], [], '' , false );
702
- $ itemsMock = $ this ->getMock (\Magento \Framework \DataObject::class, [], [], '' , false );
703
689
704
- $ this ->collectionFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ collectionMock );
705
- $ this ->searchCriteriaBuilderMock
706
- ->expects ($ this ->once ())
707
- ->method ('create ' )
708
- ->willReturn ($ extendedSearchCriteriaMock );
709
- $ this ->metadataServiceMock
710
- ->expects ($ this ->once ())
711
- ->method ('getList ' )
712
- ->with ($ extendedSearchCriteriaMock )
713
- ->willReturn ($ productAttributeSearchResultsMock );
714
- $ productAttributeSearchResultsMock ->expects ($ this ->once ())
715
- ->method ('getItems ' )
716
- ->willReturn ([$ productAttributeMock ]);
717
- $ productAttributeMock ->expects ($ this ->once ())->method ('getAttributeCode ' )->willReturn ($ attributeCode );
718
- $ collectionMock ->expects ($ this ->once ())->method ('addAttributeToSelect ' )->with ($ attributeCode );
719
- $ collectionMock ->expects ($ this ->exactly (2 ))
720
- ->method ('joinAttribute ' )
690
+ $ filterGroupFilterMock = $ this ->getMockBuilder (\Magento \Framework \Api \Filter::class)
691
+ ->disableOriginalConstructor ()
692
+ ->getMock ();
693
+ $ filterGroupFilterMock ->expects (self ::exactly (2 ))->method ('getConditionType ' )->willReturn ('eq ' );
694
+ $ filterGroupFilterMock ->expects (self ::atLeastOnce ())->method ('getField ' )->willReturn ($ fieldName );
695
+ $ filterGroupFilterMock ->expects (self ::once ())->method ('getValue ' )->willReturn ('value ' );
696
+
697
+ $ filterGroupMock = $ this ->getMockBuilder (\Magento \Framework \Api \Search \FilterGroup::class)
698
+ ->disableOriginalConstructor ()
699
+ ->getMock ();
700
+ $ filterGroupMock ->expects (self ::once ())->method ('getFilters ' )->willReturn ([$ filterGroupFilterMock ]);
701
+
702
+ $ sortOrderMock = $ this ->getMockBuilder (\Magento \Framework \Api \SortOrder::class)
703
+ ->disableOriginalConstructor ()
704
+ ->getMock ();
705
+ $ sortOrderMock ->expects (self ::atLeastOnce ())->method ('getField ' )->willReturn ($ fieldName );
706
+ $ sortOrderMock ->expects (self ::once ())->method ('getDirection ' )->willReturn (SortOrder::SORT_ASC );
707
+
708
+ /** @var \Magento\Framework\Api\SearchCriteriaInterface|\PHPUnit_Framework_MockObject_MockObject $searchCriteriaMock */
709
+ $ searchCriteriaMock = $ this ->getMockBuilder (\Magento \Framework \Api \SearchCriteriaInterface::class)
710
+ ->disableOriginalConstructor ()
711
+ ->getMock ();
712
+ $ searchCriteriaMock ->expects (self ::once ())->method ('getFilterGroups ' )->willReturn ([$ filterGroupMock ]);
713
+ $ searchCriteriaMock ->expects (self ::once ())->method ('getCurrentPage ' )->willReturn (4 );
714
+ $ searchCriteriaMock ->expects (self ::once ())->method ('getPageSize ' )->willReturn (42 );
715
+ $ searchCriteriaMock ->expects (self ::once ())->method ('getSortOrders ' )->willReturn ([$ sortOrderMock ]);
716
+
717
+ $ itemsMock = $ this ->getMockBuilder (\Magento \Framework \DataObject::class)
718
+ ->disableOriginalConstructor ()
719
+ ->getMock ();
720
+
721
+ $ collectionMock = $ this ->getMockBuilder (Collection::class)
722
+ ->disableOriginalConstructor ()
723
+ ->getMock ();
724
+ $ collectionMock ->expects (self ::once ())->method ('addAttributeToSelect ' )->with ($ attributeCode );
725
+ $ collectionMock ->expects (self ::once ())->method ('setPageSize ' )->with (42 );
726
+ $ collectionMock ->expects (self ::once ())->method ('load ' );
727
+ $ collectionMock ->expects (self ::once ())->method ('addCategoryIds ' );
728
+ $ collectionMock ->expects (self ::once ())->method ('getItems ' )->willReturn ([$ itemsMock ]);
729
+ $ collectionMock ->expects (self ::once ())->method ('getSize ' )->willReturn (128 );
730
+ $ collectionMock ->expects (self ::once ())->method ('addOrder ' )->with ($ fieldName , 'ASC ' );
731
+ $ collectionMock ->expects (self ::once ())->method ('setCurPage ' )->with (4 );
732
+ $ collectionMock ->expects (self ::exactly (2 ))->method ('joinAttribute ' )
721
733
->withConsecutive (
722
734
['status ' , 'catalog_product/status ' , 'entity_id ' , null , 'inner ' ],
723
735
['visibility ' , 'catalog_product/visibility ' , 'entity_id ' , null , 'inner ' ]
724
- );
725
- $ searchCriteriaMock ->expects ($ this ->once ())->method ('getFilterGroups ' )->willReturn ([$ filterGroupMock ]);
726
- $ filterGroupMock ->expects ($ this ->once ())->method ('getFilters ' )->willReturn ([$ filterGroupFilterMock ]);
727
- $ filterGroupFilterMock ->expects ($ this ->exactly (2 ))->method ('getConditionType ' )->willReturn ('eq ' );
728
- $ filterGroupFilterMock ->expects ($ this ->atLeastOnce ())->method ('getField ' )->willReturn ($ fieldName );
729
- $ filterGroupFilterMock ->expects ($ this ->once ())->method ('getValue ' )->willReturn ('value ' );
736
+ );
737
+
738
+ $ productAttributeMock = $ this ->getMockBuilder (ProductAttributeInterface::class)
739
+ ->disableOriginalConstructor ()
740
+ ->getMock ();
741
+ $ productAttributeMock ->expects (self ::once ())->method ('getAttributeCode ' )->willReturn ($ attributeCode );
742
+
743
+ $ extendedSearchCriteriaMock = $ this ->getMockBuilder (\Magento \Framework \Api \SearchCriteria::class)
744
+ ->disableOriginalConstructor ()
745
+ ->getMock ();
746
+
747
+ $ productAttributeSearchResultsMock = $ this ->getMockBuilder (ProductAttributeSearchResultsInterface::class)
748
+ ->disableOriginalConstructor ()
749
+ ->setMethods (['getItems ' ])
750
+ ->getMockForAbstractClass ();
751
+ $ productAttributeSearchResultsMock ->expects (self ::once ())->method ('getItems ' )
752
+ ->willReturn ([$ productAttributeMock ]);
753
+
754
+ $ this ->collectionFactoryMock ->expects (self ::once ())
755
+ ->method ('create ' )
756
+ ->willReturn ($ collectionMock );
757
+
758
+ $ this ->extensionAttributesJoinProcessor ->expects (self ::once ())
759
+ ->method ('process ' )
760
+ ->with ($ collectionMock );
761
+
762
+ $ this ->metadataServiceMock ->expects (self ::once ())->method ('getList ' )->with ($ extendedSearchCriteriaMock )
763
+ ->willReturn ($ productAttributeSearchResultsMock );
764
+
765
+ $ this ->searchCriteriaBuilderMock ->expects (self ::once ())->method ('create ' )
766
+ ->willReturn ($ extendedSearchCriteriaMock );
767
+
730
768
$ this ->expectAddToFilter ($ fieldName , $ collectionMock );
731
- $ searchCriteriaMock ->expects ($ this ->once ())->method ('getSortOrders ' )->willReturn ([$ sortOrderMock ]);
732
- $ sortOrderMock ->expects ($ this ->atLeastOnce ())->method ('getField ' )->willReturn ($ fieldName );
733
- $ sortOrderMock ->expects ($ this ->once ())->method ('getDirection ' )->willReturn (SortOrder::SORT_ASC );
734
- $ collectionMock ->expects ($ this ->once ())->method ('addOrder ' )->with ($ fieldName , 'ASC ' );
735
- $ searchCriteriaMock ->expects ($ this ->once ())->method ('getCurrentPage ' )->willReturn (4 );
736
- $ collectionMock ->expects ($ this ->once ())->method ('setCurPage ' )->with (4 );
737
- $ searchCriteriaMock ->expects ($ this ->once ())->method ('getPageSize ' )->willReturn (42 );
738
- $ collectionMock ->expects ($ this ->once ())->method ('setPageSize ' )->with (42 );
739
- $ collectionMock ->expects ($ this ->once ())->method ('load ' );
740
- $ collectionMock ->expects ($ this ->once ())->method ('getItems ' )->willReturn ([$ itemsMock ]);
741
- $ collectionMock ->expects ($ this ->once ())->method ('getSize ' )->willReturn (128 );
742
- $ searchResultsMock = $ this ->getMock (
743
- \Magento \Catalog \Api \Data \ProductSearchResultsInterface::class,
744
- [],
745
- [],
746
- '' ,
747
- false
748
- );
749
- $ searchResultsMock ->expects ($ this ->once ())->method ('setSearchCriteria ' )->with ($ searchCriteriaMock );
750
- $ searchResultsMock ->expects ($ this ->once ())->method ('setItems ' )->with ([$ itemsMock ]);
751
- $ searchResultsMock ->expects ($ this ->once ())->method ('setTotalCount ' )->with (128 );
752
- $ this ->searchResultsFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ searchResultsMock );
753
769
770
+ $ searchResultsMock = $ this ->getMockBuilder (\Magento \Catalog \Api \Data \ProductSearchResultsInterface::class)
771
+ ->disableOriginalConstructor ()
772
+ ->getMock ();
773
+ $ searchResultsMock ->expects (self ::once ())->method ('setSearchCriteria ' )->with ($ searchCriteriaMock );
774
+ $ searchResultsMock ->expects (self ::once ())->method ('setItems ' )->with ([$ itemsMock ]);
775
+
776
+ $ this ->searchResultsFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ searchResultsMock );
754
777
$ this ->assertEquals ($ searchResultsMock , $ this ->model ->getList ($ searchCriteriaMock ));
755
778
}
756
779
0 commit comments