8 class CodeTest extends \PHPUnit\Framework\TestCase
22 $this->_codeModelMock = $this->createMock(\
Magento\GoogleOptimizer\Model\Code::class);
24 $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
25 $this->_helper = $objectManagerHelper->getObject(
26 \
Magento\GoogleOptimizer\Helper\Code::class,
27 [
'code' => $this->_codeModelMock]
33 $categoryMock = $this->createMock(\
Magento\Catalog\Model\Category::class);
38 $categoryMock->expects($this->exactly(2))->method(
'getId')->will($this->returnValue($categoryId));
39 $categoryMock->expects($this->once())->method(
'getStoreId')->will($this->returnValue(
$storeId));
40 $this->_codeModelMock->expects(
43 'loadByEntityIdAndType' 46 \
Magento\GoogleOptimizer\Model\Code::ENTITY_TYPE_CATEGORY,
51 $this->_codeModelMock,
52 $this->_helper->getCodeObjectByEntity(
54 \
Magento\GoogleOptimizer\Model\Code::ENTITY_TYPE_CATEGORY
61 $productMock = $this->createMock(\
Magento\Catalog\Model\Product::class);
66 $productMock->expects($this->exactly(2))->method(
'getId')->will($this->returnValue($categoryId));
67 $productMock->expects($this->once())->method(
'getStoreId')->will($this->returnValue(
$storeId));
68 $this->_codeModelMock->expects(
71 'loadByEntityIdAndType' 74 \
Magento\GoogleOptimizer\Model\Code::ENTITY_TYPE_PRODUCT,
79 $this->_codeModelMock,
80 $this->_helper->getCodeObjectByEntity(
82 \
Magento\GoogleOptimizer\Model\Code::ENTITY_TYPE_PRODUCT
89 $pageMock = $this->createMock(\
Magento\Cms\Model\Page::class);
93 $pageMock->expects($this->exactly(2))->method(
'getId')->will($this->returnValue($categoryId));
94 $this->_codeModelMock->expects(
97 'loadByEntityIdAndType' 100 \
Magento\GoogleOptimizer\Model\Code::ENTITY_TYPE_PAGE
104 $this->_codeModelMock,
105 $this->_helper->getCodeObjectByEntity($pageMock, \
Magento\GoogleOptimizer\Model\Code::ENTITY_TYPE_PAGE)
119 $entity->expects($this->exactly(2))->method(
'getId')->will($this->returnValue($entityId));
120 $this->_codeModelMock->expects($this->never())->method(
'loadByEntityIdAndType');
123 $this->_codeModelMock,
124 $this->_helper->getCodeObjectByEntity(
$entity, \
Magento\GoogleOptimizer\Model\Code::ENTITY_TYPE_PAGE)
138 $entity->expects($this->exactly(1))->method(
'getId')->will($this->returnValue($entityId));
139 $this->_codeModelMock->expects($this->never())->method(
'loadByEntityIdAndType');
142 $this->_codeModelMock,
143 $this->_helper->getCodeObjectByEntity(
$entity, \
Magento\GoogleOptimizer\Model\Code::ENTITY_TYPE_PAGE)
testLoadingCodeForProductEntity()
testExceptionNotValidEntityType()
testLoadingCodeForPageEntity()
testLoadingCodeForCategoryEntity()
testExceptionEmptyEntity()