Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InvoiceIdentityTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Sales\Model\Order\Email\Container\InvoiceIdentity;
9 
10 class InvoiceIdentityTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $identity;
16 
20  protected $storeManagerMock;
21 
26 
30  protected $storeMock;
31 
32  protected $storeId;
33 
34  protected function setUp()
35  {
36  $this->scopeConfigInterfaceMock = $this->getMockForAbstractClass(
37  \Magento\Framework\App\Config\ScopeConfigInterface::class
38  );
39  $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
40 
41  $this->storeMock = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getStoreId', '__wakeup']);
42 
43  $this->storeId = 999999999999;
44  $this->storeMock->expects($this->any())
45  ->method('getStoreId')
46  ->will($this->returnValue($this->storeId));
47 
48  $this->identity = new InvoiceIdentity($this->scopeConfigInterfaceMock, $this->storeManagerMock);
49  }
50 
51  public function testIsEnabledTrue()
52  {
53  $this->scopeConfigInterfaceMock->expects($this->once())
54  ->method('isSetFlag')
55  ->with(
57  $this->equalTo(\Magento\Store\Model\ScopeInterface::SCOPE_STORE),
58  $this->equalTo($this->storeId)
59  )
60  ->will($this->returnValue(true));
61  $this->identity->setStore($this->storeMock);
62  $result = $this->identity->isEnabled();
63  $this->assertTrue($result);
64  }
65 
66  public function testGetEmailCopyTo()
67  {
68  $this->scopeConfigInterfaceMock->expects($this->once())
69  ->method('getValue')
70  ->with(
72  $this->equalTo(\Magento\Store\Model\ScopeInterface::SCOPE_STORE),
73  $this->equalTo($this->storeId)
74  )
75  ->will($this->returnValue('test_value,test_value2'));
76  $this->identity->setStore($this->storeMock);
77  $result = $this->identity->getEmailCopyTo();
78  $this->assertEquals(['test_value', 'test_value2'], $result);
79  }
80 
82  {
83  $this->scopeConfigInterfaceMock->expects($this->once())
84  ->method('getValue')
85  ->with(
87  $this->equalTo(\Magento\Store\Model\ScopeInterface::SCOPE_STORE),
88  $this->equalTo($this->storeId)
89  )
90  ->will($this->returnValue(null));
91  $this->identity->setStore($this->storeMock);
92  $result = $this->identity->getEmailCopyTo();
93  $this->assertFalse($result);
94  }
95 
96  public function testCopyMethod()
97  {
98  $this->scopeConfigInterfaceMock->expects($this->once())
99  ->method('getValue')
100  ->with(
102  $this->equalTo(\Magento\Store\Model\ScopeInterface::SCOPE_STORE),
103  $this->equalTo($this->storeId)
104  )
105  ->will($this->returnValue('copy_method'));
106 
107  $this->identity->setStore($this->storeMock);
108  $result = $this->identity->getCopyMethod();
109  $this->assertEquals('copy_method', $result);
110  }
111 
112  public function testGuestTemplateId()
113  {
114  $this->scopeConfigInterfaceMock->expects($this->once())
115  ->method('getValue')
116  ->with(
118  $this->equalTo(\Magento\Store\Model\ScopeInterface::SCOPE_STORE),
119  $this->equalTo($this->storeId)
120  )
121  ->will($this->returnValue('template_id'));
122 
123  $this->identity->setStore($this->storeMock);
124  $result = $this->identity->getGuestTemplateId();
125  $this->assertEquals('template_id', $result);
126  }
127 
128  public function testTemplateId()
129  {
130  $this->scopeConfigInterfaceMock->expects($this->once())
131  ->method('getValue')
132  ->with(
134  $this->equalTo(\Magento\Store\Model\ScopeInterface::SCOPE_STORE),
135  $this->equalTo($this->storeId)
136  )
137  ->will($this->returnValue('template_id'));
138 
139  $this->identity->setStore($this->storeMock);
140  $result = $this->identity->getTemplateId();
141  $this->assertEquals('template_id', $result);
142  }
143 
144  public function testSetStore()
145  {
146  $this->identity->setStore($this->storeMock);
147  $result = $this->identity->getStore();
148  $this->assertEquals($this->storeMock, $result);
149  }
150 
152  {
153  $this->storeManagerMock->expects($this->once())
154  ->method('getStore')
155  ->will($this->returnValue($this->storeMock));
156  $result = $this->identity->getStore();
157  $this->assertEquals($this->storeMock, $result);
158  }
159 
160  public function testSetCustomerEmail()
161  {
162  $this->identity->setCustomerEmail('email');
163  $result = $this->identity->getCustomerEmail();
164  $this->assertEquals('email', $result);
165  }
166 
167  public function testSetCustomerName()
168  {
169  $this->identity->setCustomerName('name');
170  $result = $this->identity->getCustomerName();
171  $this->assertEquals('name', $result);
172  }
173 
174  public function testGetEmailIdentity()
175  {
176  $emailIdentity = '[email protected]';
177  $this->scopeConfigInterfaceMock->expects($this->once())
178  ->method('getValue')
179  ->with(
181  $this->equalTo(\Magento\Store\Model\ScopeInterface::SCOPE_STORE),
182  $this->equalTo($this->storeId)
183  )
184  ->will($this->returnValue($emailIdentity));
185 
186  $this->identity->setStore($this->storeMock);
187  $result = $this->identity->getEmailIdentity();
188  $this->assertEquals($emailIdentity, $result);
189  }
190 }