Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataTest.php
Go to the documentation of this file.
1 <?php
8 
12 class DataTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $helper;
18 
22  protected $scopeConfigMock;
23 
27  protected $storeMock;
28 
32  protected function setUp()
33  {
34  $this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
35  ->disableOriginalConstructor()
36  ->getMock();
37  $contextMock = $this->getMockBuilder(\Magento\Framework\App\Helper\Context::class)
38  ->disableOriginalConstructor()
39  ->getMock();
40  $contextMock->expects($this->any())
41  ->method('getScopeConfig')
42  ->willReturn($this->scopeConfigMock);
43 
44  $storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
45  ->disableOriginalConstructor()
46  ->getMock();
47 
48  $appStateMock = $this->getMockBuilder(\Magento\Framework\App\State::class)
49  ->disableOriginalConstructor()
50  ->getMock();
51 
52  $pricingCurrencyMock = $this->getMockBuilder(\Magento\Framework\Pricing\PriceCurrencyInterface::class)
53  ->disableOriginalConstructor()
54  ->getMock();
55 
56  $this->helper = new \Magento\Sales\Helper\Data(
57  $contextMock,
58  $storeManagerMock,
59  $appStateMock,
60  $pricingCurrencyMock
61  );
62 
63  $this->storeMock = $this->getMockBuilder(\Magento\Sales\Model\Store::class)
64  ->disableOriginalConstructor()
65  ->getMock();
66  }
67 
71  public function testCanSendNewOrderConfirmationEmail($scopeConfigValue)
72  {
74  \Magento\Sales\Model\Order\Email\Container\OrderIdentity::XML_PATH_EMAIL_ENABLED,
75  $scopeConfigValue
76  );
77 
78  $this->assertEquals($scopeConfigValue, $this->helper->canSendNewOrderConfirmationEmail($this->storeMock));
79  }
80 
85  public function testCanSendNewOrderEmail($scopeConfigValue)
86  {
88  \Magento\Sales\Model\Order\Email\Container\OrderIdentity::XML_PATH_EMAIL_ENABLED,
89  $scopeConfigValue
90  );
91 
92  $this->assertEquals($scopeConfigValue, $this->helper->canSendNewOrderEmail($this->storeMock));
93  }
94 
99  public function testCanSendOrderCommentEmail($scopeConfigValue)
100  {
102  \Magento\Sales\Model\Order\Email\Container\OrderCommentIdentity::XML_PATH_EMAIL_ENABLED,
103  $scopeConfigValue
104  );
105 
106  $this->assertEquals($scopeConfigValue, $this->helper->canSendOrderCommentEmail($this->storeMock));
107  }
108 
113  public function testCanSendNewShipmentEmail($scopeConfigValue)
114  {
116  \Magento\Sales\Model\Order\Email\Container\ShipmentIdentity::XML_PATH_EMAIL_ENABLED,
117  $scopeConfigValue
118  );
119 
120  $this->assertEquals($scopeConfigValue, $this->helper->canSendNewShipmentEmail($this->storeMock));
121  }
122 
127  public function testCanSendShipmentCommentEmail($scopeConfigValue)
128  {
130  \Magento\Sales\Model\Order\Email\Container\ShipmentCommentIdentity::XML_PATH_EMAIL_ENABLED,
131  $scopeConfigValue
132  );
133 
134  $this->assertEquals($scopeConfigValue, $this->helper->canSendShipmentCommentEmail($this->storeMock));
135  }
136 
140  public function testCanSendNewInvoiceEmail($scopeConfigValue)
141  {
143  \Magento\Sales\Model\Order\Email\Container\InvoiceIdentity::XML_PATH_EMAIL_ENABLED,
144  $scopeConfigValue
145  );
146 
147  $this->assertEquals($scopeConfigValue, $this->helper->canSendNewInvoiceEmail($this->storeMock));
148  }
149 
153  public function testCanSendInvoiceCommentEmail($scopeConfigValue)
154  {
156  \Magento\Sales\Model\Order\Email\Container\InvoiceCommentIdentity::XML_PATH_EMAIL_ENABLED,
157  $scopeConfigValue
158  );
159 
160  $this->assertEquals($scopeConfigValue, $this->helper->canSendInvoiceCommentEmail($this->storeMock));
161  }
162 
167  public function testCanSendNewCreditmemoEmail($scopeConfigValue)
168  {
170  \Magento\Sales\Model\Order\Email\Container\CreditmemoIdentity::XML_PATH_EMAIL_ENABLED,
171  $scopeConfigValue
172  );
173 
174  $this->assertEquals($scopeConfigValue, $this->helper->canSendNewCreditmemoEmail($this->storeMock));
175  }
176 
181  public function testCanSendCreditmemoCommentEmail($scopeConfigValue)
182  {
184  \Magento\Sales\Model\Order\Email\Container\CreditmemoCommentIdentity::XML_PATH_EMAIL_ENABLED,
185  $scopeConfigValue
186  );
187 
188  $this->assertEquals($scopeConfigValue, $this->helper->canSendCreditmemoCommentEmail($this->storeMock));
189  }
190 
198  protected function setupScopeConfigIsSetFlag($flagName, $returnValue)
199  {
200  $this->scopeConfigMock->expects($this->once())
201  ->method('isSetFlag')
202  ->with(
203  $flagName,
204  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
205  $this->storeMock
206  )
207  ->will($this->returnValue($returnValue));
208  }
209 
213  public function getScopeConfigValue()
214  {
215  return [
216  [true],
217  [false]
218  ];
219  }
220 }
testCanSendCreditmemoCommentEmail($scopeConfigValue)
Definition: DataTest.php:181
testCanSendShipmentCommentEmail($scopeConfigValue)
Definition: DataTest.php:127
testCanSendNewCreditmemoEmail($scopeConfigValue)
Definition: DataTest.php:167
setupScopeConfigIsSetFlag($flagName, $returnValue)
Definition: DataTest.php:198
testCanSendNewOrderEmail($scopeConfigValue)
Definition: DataTest.php:85
testCanSendOrderCommentEmail($scopeConfigValue)
Definition: DataTest.php:99
testCanSendNewInvoiceEmail($scopeConfigValue)
Definition: DataTest.php:140
testCanSendInvoiceCommentEmail($scopeConfigValue)
Definition: DataTest.php:153
testCanSendNewShipmentEmail($scopeConfigValue)
Definition: DataTest.php:113
testCanSendNewOrderConfirmationEmail($scopeConfigValue)
Definition: DataTest.php:71