/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage The model is empty */ public function testExceptionEmptyEntity() { $entity = $this->getMock('Magento\\Cms\\Model\\Block', [], [], '', false); $entityId = 0; $entity->expects($this->exactly(1))->method('getId')->will($this->returnValue($entityId)); $this->_codeModelMock->expects($this->never())->method('loadByEntityIdAndType'); $this->assertEquals($this->_codeModelMock, $this->_helper->getCodeObjectByEntity($entity, \Magento\GoogleOptimizer\Model\Code::ENTITY_TYPE_PAGE)); }
/** * Get google experiment code model * * @return \Magento\GoogleOptimizer\Model\Code|null * @throws \RuntimeException */ protected function _getGoogleExperiment() { $category = $this->_getCategory(); if ($category->getId()) { return $this->_codeHelper->getCodeObjectByEntity($category); } return null; }
/** * Get Code model * * @return \Magento\GoogleOptimizer\Model\Code|null */ protected function getCodeModel() { if ($this->locator->getProduct()->getId()) { return $this->codeHelper->getCodeObjectByEntity($this->locator->getProduct()); } return null; }
/** * @param int|null $productId * @param string $experimentScript * @param string $codeId * @param int $expectedCalls * @return void * @dataProvider getDataGoogleExperimentEnabledDataProvider */ public function testGetDataGoogleExperimentEnabled($productId, $experimentScript, $codeId, $expectedCalls) { $expectedResult[$productId]['google_experiment'] = ['experiment_script' => $experimentScript, 'code_id' => $codeId]; $this->canShowPanel(true); /** @var \Magento\GoogleOptimizer\Model\Code|MockObject $codeModelMock */ $codeModelMock = $this->getMock('Magento\\GoogleOptimizer\\Model\\Code', ['getExperimentScript', 'getCodeId'], [], '', false, false); $codeModelMock->expects($this->exactly($expectedCalls))->method('getExperimentScript')->willReturn($experimentScript); $codeModelMock->expects($this->exactly($expectedCalls))->method('getCodeId')->willReturn($codeId); $this->codeHelperMock->expects($this->exactly($expectedCalls))->method('getCodeObjectByEntity')->with($this->productMock)->willReturn($codeModelMock); $this->productMock->expects($this->atLeastOnce())->method('getId')->willReturn($productId); $this->assertEquals($expectedResult, $this->googleOptimizer->modifyData([])); }
/** * Get google experiment code model * * @return \Magento\GoogleOptimizer\Model\Code * @throws \RuntimeException */ protected function _getGoogleExperiment() { return $this->_codeHelper->getCodeObjectByEntity($this->_getEntity()); }