/** * @param \Magento\Newsletter\Model\Template $template * @param string $id * @return $this */ protected function loadTemplate(\Magento\Newsletter\Model\Template $template, $id) { /** @var \Magento\Newsletter\Model\Queue $queue */ $queue = $this->_queueFactory->create()->load($id); $template->setTemplateType($queue->getNewsletterType()); $template->setTemplateText($queue->getNewsletterText()); $template->setTemplateStyles($queue->getNewsletterStyles()); return $this; }
public function testToHtmlWithSubscriber() { $this->request->expects($this->any())->method('getParam')->willReturnMap([['id', null, 2], ['store', null, 1], ['subscriber', null, 3]]); $subscriber = $this->getMock('Magento\\Newsletter\\Model\\Subscriber', [], [], '', false); $subscriber->expects($this->atLeastOnce())->method('load')->with(3)->willReturnSelf(); $this->subscriberFactory->expects($this->atLeastOnce())->method('create')->willReturn($subscriber); $this->template->expects($this->atLeastOnce())->method('emulateDesign')->with(1); $this->template->expects($this->atLeastOnce())->method('revertDesign'); $this->appState->expects($this->atLeastOnce())->method('emulateAreaCode')->with(\Magento\Newsletter\Model\Template::DEFAULT_DESIGN_AREA, [$this->template, 'getProcessedTemplate'], [['subscriber' => $subscriber]])->willReturn('Processed Template'); $this->assertEquals('Processed Template', $this->preview->toHtml()); }
/** * Check usage of template code in other templates * * @param \Magento\Newsletter\Model\Template $template * @return boolean */ public function checkCodeUsage(\Magento\Newsletter\Model\Template $template) { if ($template->getTemplateActual() != 0 || is_null($template->getTemplateActual())) { $bind = ['template_id' => $template->getId(), 'template_code' => $template->getTemplateCode(), 'template_actual' => 1]; $select = $this->_getReadAdapter()->select()->from($this->getMainTable(), new \Zend_Db_Expr('COUNT(template_id)'))->where('template_id != :template_id')->where('template_code = :template_code')->where('template_actual = :template_actual'); $countOfCodes = $this->_getReadAdapter()->fetchOne($select, $bind); return $countOfCodes > 0; } else { return false; } }
public function testToHtmlWithId() { $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([['id', null, 1], ['store_id', null, 0]])); $this->queue->expects($this->once())->method('load')->will($this->returnSelf()); $this->template->expects($this->any())->method('isPlain')->will($this->returnValue(true)); /** @var \Magento\Store\Model\Store $store */ $this->storeManager->expects($this->once())->method('getDefaultStoreView')->will($this->returnValue(null)); $store = $this->getMock('Magento\\Store\\Model\\Store', ['getId'], [], '', false); $this->storeManager->expects($this->once())->method('getStores')->will($this->returnValue([0 => $store])); $result = $this->preview->toHtml(); $this->assertEquals('<pre></pre>', $result); }
/** * @magentoDataFixture Magento/Newsletter/_files/newsletter_sample.php * @magentoAppIsolation disabled */ public function testSaveActionQueueTemplateAndVerifySuccessMessage() { $postForQueue = ['sender_email' => '*****@*****.**', 'sender_name' => 'john doe', 'subject' => 'test subject', 'text' => 'newsletter text']; $this->getRequest()->setPostValue($postForQueue); $this->_model->loadByCode('some_unique_code'); $this->getRequest()->setParam('template_id', $this->_model->getId()); $this->dispatch('backend/newsletter/queue/save'); /** * Check that errors was generated and set to session */ $this->assertSessionMessages($this->isEmpty(), \Magento\Framework\Message\MessageInterface::TYPE_ERROR); /** * Check that success message is set */ $this->assertSessionMessages($this->equalTo(['The newsletter queue has been saved.']), \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS); }
/** * @magentoDataFixture Magento/Newsletter/_files/newsletter_sample.php * @magentoAppIsolation disabled */ public function testSaveActionQueueTemplateAndVerifySuccessMessage() { $postForQueue = ['sender_email' => '*****@*****.**', 'sender_name' => 'john doe', 'subject' => 'test subject', 'text' => 'newsletter text']; $this->getRequest()->setPostValue($postForQueue); // Loading by code, since ID will vary. template_code is not actually used to load anywhere else. $this->_model->load('some_unique_code', 'template_code'); // Ensure that template is actually loaded so as to prevent a false positive on saving a *new* template // instead of existing one. $this->assertEquals('some_unique_code', $this->_model->getTemplateCode()); $this->getRequest()->setParam('template_id', $this->_model->getId()); $this->dispatch('backend/newsletter/queue/save'); /** * Check that errors was generated and set to session */ $this->assertSessionMessages($this->isEmpty(), \Magento\Framework\Message\MessageInterface::TYPE_ERROR); /** * Check that success message is set */ $this->assertSessionMessages($this->equalTo(['You saved the newsletter queue.']), \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS); }
/** * @magentoAppIsolation enabled * @magentoDataFixture Magento/Newsletter/_files/newsletter_sample.php */ public function testDeleteActionTemplateAndVerifySuccessMessage() { $this->_model->loadByCode('some_unique_code'); $this->getRequest()->setParam('id', $this->_model->getId()); $this->dispatch('backend/newsletter/template/delete'); /** * Check that errors was generated and set to session */ $this->assertSessionMessages($this->isEmpty(), \Magento\Framework\Message\MessageInterface::TYPE_ERROR); /** * Check that success message is set */ $this->assertSessionMessages($this->equalTo(['The newsletter template has been deleted.']), \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS); }
/** * @magentoConfigFixture current_store system/smtp/disable 0 * @magentoAppIsolation enabled * @dataProvider isValidToSendDataProvider */ public function testIsValidToSend($senderEmail, $senderName, $subject, $isValid) { $this->_model->setTemplateSenderEmail($senderEmail)->setTemplateSenderName($senderName)->setTemplateSubject($subject); $this->assertSame($isValid, $this->_model->isValidForSend()); }
/** * @param \Magento\Newsletter\Model\Template $template * @param string $id * @return $this */ protected function loadTemplate(\Magento\Newsletter\Model\Template $template, $id) { $template->load($id); return $this; }