/** * Callback for save method in mocked model * * @throws Magento_Exception */ public function saveModelAndFailOnUpdate() { if (!$this->_model->getId()) { $this->saveModelSuccessfully(); } else { throw new Magento_Exception('Synthetic model update failure.'); } }
/** * Callback for save method in mocked model * * @throws \Magento\Framework\Exception\LocalizedException */ public function saveModelAndFailOnUpdate() { if (!$this->_model->getId()) { $this->saveModelSuccessfully(); } else { throw new \Magento\Framework\Exception\LocalizedException(__('Synthetic model update failure.')); } }
public function testSetAndGetId() { $this->mockModel(); $testId = 9999; $this->model->setId($testId); $this->assertEquals($testId, $this->model->getId()); }
/** * @param \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product * @param array $modelData * @return \Magento\Downloadable\Model\Sample|\PHPUnit_Framework_MockObject_MockObject */ private function createSampleModel($product, array $modelData) { $sample = $this->getMockBuilder('\\Magento\\Downloadable\\Model\\Sample')->disableOriginalConstructor()->setMethods(['setData', 'setSampleType', 'setProductId', 'setStoreId', 'setProductWebsiteIds', 'setNumberOfDownloads', 'setSampleUrl', 'setLinkFile', 'setSampleFile', 'save'])->getMock(); $sample->expects($this->once())->method('setData')->with($modelData)->will($this->returnSelf()); $sample->expects($this->once())->method('setSampleType')->with($modelData['type'])->will($this->returnSelf()); $sample->expects($this->once())->method('setProductId')->with($product->getId())->will($this->returnSelf()); $sample->expects($this->once())->method('setStoreId')->with($product->getStoreId())->will($this->returnSelf()); return $sample; }
/** * @covers ::getInfo */ public function testGetInfo() { $token_info = array('types' => array('foo' => array('name' => $this->randomMachineName()))); $this->language->expects($this->atLeastOnce())->method('getId')->will($this->returnValue($this->randomMachineName())); $this->languageManager->expects($this->once())->method('getCurrentLanguage')->with(LanguageInterface::TYPE_CONTENT)->will($this->returnValue($this->language)); // The persistent cache must only be hit once, after which the info is // cached statically. $this->cache->expects($this->once())->method('get'); $this->cache->expects($this->once())->method('set')->with('token_info:' . $this->language->getId(), $token_info); $this->moduleHandler->expects($this->once())->method('invokeAll')->with('token_info')->will($this->returnValue($token_info)); $this->moduleHandler->expects($this->once())->method('alter')->with('token_info', $token_info); // Get the information for the first time. The cache should be checked, the // hooks invoked, and the info should be set to the cache should. $this->token->getInfo(); // Get the information for the second time. The data must be returned from // the static cache, so the persistent cache must not be accessed and the // hooks must not be invoked. $this->token->getInfo(); }
/** * @param bool $isChangedUrlKey * @param bool $isChangedVisibility * @param bool $isChangedWebsites * @param bool $isChangedCategories * @param bool $visibilityResult * @param int $expectedDeleteCount * @param int $expectedReplaceCount * * @dataProvider testUrlKeyDataProvider */ public function testExecuteUrlKey($isChangedUrlKey, $isChangedVisibility, $isChangedWebsites, $isChangedCategories, $visibilityResult, $expectedDeleteCount, $expectedReplaceCount) { $this->product->expects($this->any())->method('getStoreId')->will($this->returnValue(12)); $this->product->expects($this->any())->method('dataHasChangedFor')->will($this->returnValueMap([['visibility', $isChangedVisibility], ['url_key', $isChangedUrlKey]])); $this->product->expects($this->any())->method('getIsChangedWebsites')->will($this->returnValue($isChangedWebsites)); $this->product->expects($this->any())->method('getIsChangedCategories')->will($this->returnValue($isChangedCategories)); $this->urlPersist->expects($this->exactly($expectedDeleteCount))->method('deleteByData')->with([UrlRewrite::ENTITY_ID => $this->product->getId(), UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE, UrlRewrite::REDIRECT_TYPE => 0, UrlRewrite::STORE_ID => $this->product->getStoreId()]); $this->product->expects($this->any())->method('isVisibleInSiteVisibility')->will($this->returnValue($visibilityResult)); $this->urlPersist->expects($this->exactly($expectedReplaceCount))->method('replace')->with([3 => 'rewrite']); $this->model->execute($this->observer); }
/** * Test loading invalid layout */ public function testLoadWithInvalidLayout() { $this->_model->addPageHandles(array('default')); $this->_appState->expects($this->any())->method('getMode')->will($this->returnValue('developer')); $this->_layoutValidator->expects($this->any())->method('getMessages')->will($this->returnValue(array('testMessage1', 'testMessage2'))); $this->_layoutValidator->expects($this->any())->method('isValid')->will($this->returnValue(false)); $suffix = md5(implode('|', $this->_model->getHandles())); $cacheId = "LAYOUT_{$this->_theme->getArea()}_STORE{$this->_store->getId()}_{$this->_theme->getId()}{$suffix}"; $messages = $this->_layoutValidator->getMessages(); // Testing error message is logged with logger $this->_logger->expects($this->once())->method('log')->with('Cache file with merged layout: ' . $cacheId . ': ' . array_shift($messages), \Zend_Log::ERR); $this->_model->load(); }
/** * @param \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product * @param array $modelData * @param bool $isUnlimited * @return \Magento\Downloadable\Model\Link|\PHPUnit_Framework_MockObject_MockObject */ private function createLinkkModel($product, array $modelData, $isUnlimited) { $link = $this->getMockBuilder('\\Magento\\Downloadable\\Model\\Link')->disableOriginalConstructor()->setMethods(['setData', 'setLinkType', 'setProductId', 'setStoreId', 'setWebsiteId', 'setProductWebsiteIds', 'setPrice', 'setNumberOfDownloads', 'setSampleUrl', 'setSampleType', 'setLinkFile', 'setSampleFile', 'save', 'getIsUnlimited'])->getMock(); $link->expects($this->once())->method('setData')->with($modelData)->will($this->returnSelf()); $link->expects($this->once())->method('setLinkType')->with($modelData['type'])->will($this->returnSelf()); $link->expects($this->once())->method('setProductId')->with($product->getId())->will($this->returnSelf()); $link->expects($this->once())->method('setStoreId')->with($product->getStoreId())->will($this->returnSelf()); $link->expects($this->once())->method('setWebsiteId')->with($product->getStore()->getWebsiteId())->will($this->returnSelf()); $link->expects($this->once())->method('setPrice')->with(0); $link->expects($this->any())->method('setNumberOfDownloads')->with(0); $link->expects($this->once())->method('getIsUnlimited')->will($this->returnValue($isUnlimited)); return $link; }
/** * @return \Magento\Framework\Phrase|string */ protected function getTitle() { return $this->blockMock->getId() ? $this->blockMock->getTitle() : __('New Block'); }
public function testSendTransactional() { $this->_model->sendTransactional('customer_create_account_email_template', array('name' => 'Sender Name', 'email' => '*****@*****.**'), '*****@*****.**', 'Recipient Name'); $this->assertEquals('customer_create_account_email_template', $this->_model->getId()); $this->assertTrue($this->_model->getSentSuccess()); }
/** * Test the getId() method from the Chromosome class * * @uses \bcGen\MainBundle\Entity\Chromosome::getId() */ public function testGetId() { echo "\n********************Test GetId()*********************************************************\n"; $this->stubedChromosome->method('getId')->willReturn(1); $this->assertEquals(1, $this->stubedChromosome->getId()); }
/** * @param $loadId * @param $expectedId * @dataProvider loadDataProvider */ public function testLoad($loadId, $expectedId) { $this->model->load($loadId); $this->assertEquals($expectedId, $this->model->getId()); }
/** * @return \Magento\Framework\Phrase|string */ protected function getTitle() { return $this->pageMock->getId() ? $this->pageMock->getTitle() : __('New Page'); }
public function testEntityMethods() { $this->assertNull($this->entity->getId()); }
/** * @param \PHPUnit_Framework_MockObject_MockObject $criteria * @return \PHPUnit_Framework_MockObject_MockObject * * @depends testImplementCriteriaInterface * @covers Sellsy\Criteria\Generic\GetOneCriteria::setId */ public function testSetId(\PHPUnit_Framework_MockObject_MockObject $criteria) { $criteria->setId(12); $this->assertEquals(12, $criteria->getId()); return $criteria; }