65 $this->templateFilter = $this->getMockBuilder(\
Magento\Newsletter\Model\Template\Filter::class)
66 ->disableOriginalConstructor()
67 ->setMethods([
'create'])
69 $this->date = $this->getMockBuilder(\
Magento\Framework\Stdlib\DateTime\DateTime::class)
70 ->disableOriginalConstructor()
72 $this->templateFactory = $this->getMockBuilder(\
Magento\Newsletter\Model\TemplateFactory::class)
73 ->disableOriginalConstructor()
74 ->setMethods([
'create',
'load'])
76 $this->problemFactory = $this->getMockBuilder(\
Magento\Newsletter\Model\ProblemFactory::class)
77 ->disableOriginalConstructor()
79 $this->transportBuilder = $this->getMockBuilder(\
Magento\Newsletter\Model\
Queue\TransportBuilder::class)
80 ->disableOriginalConstructor()
82 [
'setTemplateData',
'setTemplateOptions',
'setTemplateVars',
'setFrom',
'addTo',
'getTransport']
85 $this->subscribersCollection =
87 ->disableOriginalConstructor()
90 ->disableOriginalConstructor()
92 $this->subscribersCollectionFactory = $this->getMockBuilder(
95 ->disableOriginalConstructor()
96 ->setMethods([
'create'])
98 $this->subscribersCollectionFactory->expects($this->any())->method(
'create')->willReturn(
99 $this->subscribersCollection
102 $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
104 $this->queue = $this->objectManager->getObject(
105 \
Magento\Newsletter\Model\Queue::class,
107 'templateFilter' => $this->templateFilter,
108 'date' => $this->date,
109 'templateFactory' => $this->templateFactory,
110 'problemFactory' => $this->problemFactory,
111 'subscriberCollectionFactory' => $this->subscribersCollectionFactory,
112 'transportBuilder' => $this->transportBuilder,
113 'resource' => $this->resource
120 $this->queue->setQueueStatus(2);
121 $this->queue->setQueueStartAt(1);
123 $this->assertEquals($this->queue, $this->queue->sendPerSubscriber());
128 $this->queue->setQueueStatus(1);
129 $this->queue->setQueueStartAt(1);
130 $this->subscribersCollection->expects($this->once())->method(
'getQueueJoinedFlag')->willReturn(
false);
131 $this->subscribersCollection->expects($this->once())->method(
'useQueue')->with($this->queue)->willReturnSelf();
132 $this->subscribersCollection->expects($this->once())->method(
'getSize')->willReturn(0);
133 $this->date->expects($this->once())->method(
'gmtDate')->willReturn(
'any_date');
135 $this->assertEquals($this->queue, $this->queue->sendPerSubscriber());
140 $this->queue->setQueueStatus(1);
141 $this->queue->setQueueStartAt(1);
143 ->disableOriginalConstructor()
144 ->setMethods([
'getItems'])
146 $item = $this->getMockBuilder(\
Magento\Newsletter\Model\Subscriber::class)
147 ->disableOriginalConstructor()
148 ->setMethods([
'getStoreId',
'getSubscriberEmail',
'getSubscriberFullName',
'received'])
150 $transport = $this->createMock(\
Magento\Framework\Mail\TransportInterface::class);
151 $this->subscribersCollection->expects($this->once())->method(
'getQueueJoinedFlag')->willReturn(
false);
152 $this->subscribersCollection->expects($this->once())->method(
'useQueue')->with($this->queue)->willReturnSelf();
153 $this->subscribersCollection->expects($this->once())->method(
'getSize')->willReturn(5);
154 $this->subscribersCollection->expects($this->once())->method(
'useOnlyUnsent')->willReturnSelf();
155 $this->subscribersCollection->expects($this->once())->method(
'showCustomerInfo')->willReturnSelf();
156 $this->subscribersCollection->expects($this->once())->method(
'setPageSize')->willReturnSelf();
157 $this->subscribersCollection->expects($this->once())->method(
'setCurPage')->willReturnSelf();
158 $this->subscribersCollection->expects($this->once())->method(
'load')->willReturn(
$collection);
159 $this->transportBuilder->expects($this->once())->method(
'setTemplateData')->willReturnSelf();
160 $collection->expects($this->atLeastOnce())->method(
'getItems')->willReturn([
$item]);
161 $item->expects($this->once())->method(
'getStoreId')->willReturn(
'store_id');
162 $item->expects($this->once())->method(
'getSubscriberEmail')->willReturn(
'email');
163 $item->expects($this->once())->method(
'getSubscriberFullName')->willReturn(
'full_name');
164 $this->transportBuilder->expects($this->once())->method(
'setTemplateOptions')->willReturnSelf();
165 $this->transportBuilder->expects($this->once())->method(
'setTemplateVars')->willReturnSelf();
166 $this->transportBuilder->expects($this->once())->method(
'setFrom')->willReturnSelf();
167 $this->transportBuilder->expects($this->once())->method(
'addTo')->willReturnSelf();
168 $this->transportBuilder->expects($this->once())->method(
'getTransport')->willReturn($transport);
169 $item->expects($this->once())->method(
'received')->with($this->queue)->willReturnSelf();
171 $this->assertEquals($this->queue, $this->queue->sendPerSubscriber());
177 'template_id' =>
'id',
178 'queue_status' =>
'status',
179 'queue_start_at' =>
'start_at',
180 'queue_finish_at' =>
'finish_at' 182 $this->queue->setTemplateId(
'id');
183 $this->queue->setQueueStatus(
'status');
184 $this->queue->setQueueStartAt(
'start_at');
185 $this->queue->setQueueFinishAt(
'finish_at');
187 $this->assertEquals(
$result, $this->queue->getDataForSave());
192 $template = $this->getMockBuilder(\
Magento\Newsletter\Model\Template::class)
193 ->disableOriginalConstructor()
195 $this->queue->setTemplateId(2);
196 $this->templateFactory->expects($this->once())->method(
'create')->willReturn(
$template);
197 $template->expects($this->once())->method(
'load')->with(2)->willReturnSelf();
199 $this->assertEquals(
$template, $this->queue->getTemplate());
205 $this->resource->expects($this->once())->method(
'getStores')->willReturn(
$stores);
207 $this->assertEquals(
$stores, $this->queue->getStores());
testSendPerSubscriberZeroSize()
$subscribersCollectionFactory