53 private $identityContainerMock;
58 private $storeManagerMock;
64 $this->emailSender = $this->createPartialMock(\
Magento\Sales\Model\
Order\Email\Sender::class, [
'send']);
66 $this->entityResource = $this->getMockForAbstractClass(
76 $this->entityCollection = $this->getMockForAbstractClass(
83 [
'addFieldToFilter',
'getItems',
'addAttributeToSelect',
'getSelect']
86 $this->globalConfig = $this->createMock(\
Magento\Framework\
App\Config::class);
88 $this->identityContainerMock = $this->createMock(
89 \
Magento\Sales\Model\
Order\Email\Container\IdentityInterface::class
92 $this->storeManagerMock = $this->createMock(
93 \
Magento\Store\Model\StoreManagerInterface::class
97 \
Magento\Sales\Model\EmailSenderHandler::class,
99 'emailSender' => $this->emailSender,
100 'entityResource' => $this->entityResource,
101 'entityCollection' => $this->entityCollection,
102 'globalConfig' => $this->globalConfig,
103 'identityContainer' => $this->identityContainerMock,
104 'storeManager' => $this->storeManagerMock,
116 public function testExecute($configValue, $collectionItems, $emailSendingResult)
118 $path =
'sales_email/general/async_sending';
121 ->expects($this->at(0))
124 ->willReturn($configValue);
127 $this->entityCollection
128 ->expects($this->at(0))
129 ->method(
'addFieldToFilter')
130 ->with(
'send_email', [
'eq' => 1]);
132 $this->entityCollection
133 ->expects($this->at(1))
134 ->method(
'addFieldToFilter')
135 ->with(
'email_sent', [
'null' =>
true]);
137 $this->entityCollection
138 ->expects($this->any())
139 ->method(
'addAttributeToSelect')
143 $selectMock = $this->createMock(\
Magento\Framework\DB\Select::class);
146 ->expects($this->atLeastOnce())
151 $this->entityCollection
152 ->expects($this->any())
153 ->method(
'getSelect')
154 ->willReturn($selectMock);
156 $this->entityCollection
157 ->expects($this->any())
159 ->willReturn($collectionItems);
161 if ($collectionItems) {
164 $collectionItem = $collectionItems[0];
167 ->expects($this->once())
169 ->with($collectionItem,
true)
170 ->willReturn($emailSendingResult);
172 $storeMock = $this->createMock(\
Magento\Store\Model\Store::class);
174 $this->storeManagerMock
175 ->expects($this->any())
177 ->willReturn($storeMock);
179 $this->identityContainerMock
180 ->expects($this->any())
184 $this->identityContainerMock
185 ->expects($this->any())
186 ->method(
'isEnabled')
189 if ($emailSendingResult) {
191 ->expects($this->once())
192 ->method(
'setEmailSent')
194 ->willReturn($collectionItem);
196 $this->entityResource
197 ->expects($this->once())
199 ->with($collectionItem);
204 $this->
object->sendEmails();
213 \
Magento\Sales\Model\AbstractModel::class,
219 [
'setEmailSent',
'getOrder']
226 'emailSendingResult' =>
true,
231 'emailSendingResult' =>
false,
235 'collectionItems' => [],
236 'emailSendingResult' =>
null,
240 'collectionItems' =>
null,
241 'emailSendingResult' =>
null,