Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AsyncSendingTest.php
Go to the documentation of this file.
1 <?php
7 
9 
14 class AsyncSendingTest extends \PHPUnit\Framework\TestCase
15 {
19  protected $object;
20 
24  protected $config;
25 
29  protected $context;
30 
34  protected $eventManager;
35 
36  protected function setUp()
37  {
38  $objectManager = new ObjectManager($this);
39 
40  $this->config = $this->createMock(\Magento\Framework\App\Config::class);
41 
42  $this->eventManager = $this->createMock(\Magento\Framework\Event\Manager::class);
43 
44  $this->context = $this->createPartialMock(\Magento\Framework\Model\Context::class, ['getEventDispatcher']);
45  $this->context->expects($this->any())->method('getEventDispatcher')->willReturn($this->eventManager);
46 
47  $this->object = $objectManager->getObject(
48  \Magento\Sales\Model\Config\Backend\Email\AsyncSending::class,
49  [
50  'config' => $this->config,
51  'context' => $this->context
52  ]
53  );
54  }
55 
63  public function testAfterSave($value, $oldValue, $eventName)
64  {
65  $path = 'sales_email/general/async_sending';
66  $scope = \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT;
67 
68  $this->object->setData(['value' => $value, 'path' => $path, 'scope' => $scope]);
69 
70  $this->config->expects($this->once())->method('getValue')->with($path, $scope)->willReturn($oldValue);
71 
72  if ($value == $oldValue) {
73  $this->eventManager->expects($this->never())->method('dispatch');
74  } else {
75  $this->eventManager->expects($this->once())->method('dispatch')->with($eventName);
76  }
77 
78  $this->object->afterSave();
79  }
80 
84  public function afterSaveDataProvider()
85  {
86  return [
87  [0, 0, null],
88  [1, 1, null],
89  [0, 1, 'config_data_sales_email_general_async_sending_disabled'],
90  [1, 0, 'config_data_sales_email_general_async_sending_enabled']
91  ];
92  }
93 }
$objectManager
Definition: bootstrap.php:17
$value
Definition: gender.phtml:16