Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
ObserverTest Class Reference
Inheritance diagram for ObserverTest:

Public Member Functions

 setUp ()
 
 testEmulateWelcomeBlock ()
 

Protected Attributes

 $_customerViewHelper
 
 $_escaper
 
 $customerRepository
 
 $_persistentSessionHelper
 
 $_objectManager
 
 $_observer
 
 $_customerSession
 
 $_checkoutSession
 

Detailed Description

@magentoDataFixture Magento/Persistent/_files/persistent.php @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 15 of file ObserverTest.php.

Member Function Documentation

◆ setUp()

setUp ( )

Definition at line 57 of file ObserverTest.php.

58  {
60 
61  $this->_customerSession = $this->_objectManager->get(\Magento\Customer\Model\Session::class);
62 
63  $this->_customerViewHelper = $this->_objectManager->create(
64  \Magento\Customer\Helper\View::class
65  );
66  $this->_escaper = $this->_objectManager->create(
67  \Magento\Framework\Escaper::class
68  );
69 
70  $this->customerRepository = $this->_objectManager->create(
71  \Magento\Customer\Api\CustomerRepositoryInterface::class
72  );
73 
74  $this->_checkoutSession = $this->getMockBuilder(
75  \Magento\Checkout\Model\Session::class
76  )->disableOriginalConstructor()->setMethods([])->getMock();
77 
78  $this->_persistentSessionHelper = $this->_objectManager->create(\Magento\Persistent\Helper\Session::class);
79 
80  $this->_observer = $this->_objectManager->create(
81  \Magento\Persistent\Model\Observer::class,
82  [
83  'escaper' => $this->_escaper,
84  'customerViewHelper' => $this->_customerViewHelper,
85  'customerRepository' => $this->customerRepository,
86  'checkoutSession' => $this->_checkoutSession
87  ]
88  );
89  }

◆ testEmulateWelcomeBlock()

testEmulateWelcomeBlock ( )

@magentoConfigFixture current_store persistent/options/enabled 1 @magentoConfigFixture current_store persistent/options/remember_enabled 1 @magentoConfigFixture current_store persistent/options/remember_default 1 @magentoAppArea frontend @magentoAppIsolation enabled

Definition at line 98 of file ObserverTest.php.

99  {
100  $this->_customerSession->loginById(1);
101 
102  $httpContext = new \Magento\Framework\App\Http\Context();
103  $httpContext->setValue(Context::CONTEXT_AUTH, 1, 1);
104  $block = $this->_objectManager->create(
105  \Magento\Sales\Block\Reorder\Sidebar::class,
106  [
107  'httpContext' => $httpContext
108  ]
109  );
110  $this->_observer->emulateWelcomeBlock($block);
111  $customerName = $this->_escaper->escapeHtml(
112  $this->_customerViewHelper->getCustomerName(
113  $this->customerRepository->getById(
114  $this->_persistentSessionHelper->getSession()->getCustomerId()
115  )
116  )
117  );
118  $translation = __('Welcome, %1!', $customerName)->__toString();
119  $this->assertStringMatchesFormat('%A' . $translation . '%A', $block->getWelcome()->__toString());
120  $this->_customerSession->logout();
121  }
__()
Definition: __.php:13
$block
Definition: block.php:8

Field Documentation

◆ $_checkoutSession

$_checkoutSession
protected

Definition at line 55 of file ObserverTest.php.

◆ $_customerSession

$_customerSession
protected

Definition at line 50 of file ObserverTest.php.

◆ $_customerViewHelper

$_customerViewHelper
protected

Definition at line 20 of file ObserverTest.php.

◆ $_escaper

$_escaper
protected

Definition at line 25 of file ObserverTest.php.

◆ $_objectManager

$_objectManager
protected

Definition at line 40 of file ObserverTest.php.

◆ $_observer

$_observer
protected

Definition at line 45 of file ObserverTest.php.

◆ $_persistentSessionHelper

$_persistentSessionHelper
protected

Definition at line 35 of file ObserverTest.php.

◆ $customerRepository

$customerRepository
protected

Definition at line 30 of file ObserverTest.php.


The documentation for this class was generated from the following file: