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

Public Member Functions

 testGetQuoteNotInitializedCustomerSet ()
 
 testGetQuoteNotInitializedCustomerLoggedIn ()
 
 testLoadCustomerQuoteCustomerWithoutQuote ()
 

Protected Member Functions

 setUp ()
 
 _validateCustomerDataInQuote ($quote)
 

Detailed Description

Class SessionTest

Definition at line 21 of file SessionTest.php.

Member Function Documentation

◆ _validateCustomerDataInQuote()

_validateCustomerDataInQuote (   $quote)
protected

Ensure that quote has customer data specified in customer fixture.

Parameters
\Magento\Quote\Model\Quote$quote

Definition at line 189 of file SessionTest.php.

190  {
192  $customerEmailFromFixture = '[email protected]';
193  $customerFirstNameFromFixture = 'John';
194  $this->assertEquals(
195  $customerEmailFromFixture,
196  $quote->getCustomerEmail(),
197  'Customer email was not set to Quote correctly.'
198  );
199  $this->assertEquals(
201  $quote->getCustomerId(),
202  'Customer ID was not set to Quote correctly.'
203  );
204  $this->assertEquals(
205  $customerFirstNameFromFixture,
206  $quote->getCustomerFirstname(),
207  'Customer first name was not set to Quote correctly.'
208  );
209  }
$quote
$customerIdFromFixture

◆ setUp()

setUp ( )
protected
Returns
void

Definition at line 46 of file SessionTest.php.

47  {
48  $this->objectManager = Bootstrap::getObjectManager();
49  $this->customerRepository = $this->objectManager->create(CustomerRepositoryInterface::class);
50  $this->customerSession = $this->objectManager->get(CustomerSession::class);
51  $this->checkoutSession = $this->objectManager->create(Session::class);
52  }

◆ testGetQuoteNotInitializedCustomerLoggedIn()

testGetQuoteNotInitializedCustomerLoggedIn ( )

Test covers case when quote is not yet initialized and customer data is set to customer session model.

Expected result - quote object should be loaded and customer data should be set to it.

@magentoDataFixture Magento/Sales/_files/quote_with_customer.php @magentoAppIsolation enabled

Execute SUT

Definition at line 79 of file SessionTest.php.

80  {
81  $customer = $this->customerRepository->getById(1);
82  $this->customerSession->setCustomerDataObject($customer);
83 
85  $quote = $this->checkoutSession->getQuote();
87  }
$customer
Definition: customers.php:11
$quote

◆ testGetQuoteNotInitializedCustomerSet()

testGetQuoteNotInitializedCustomerSet ( )

Test covers case when quote is not yet initialized and customer data is set to checkout session model.

Expected result - quote object should be loaded and customer data should be set to it.

@magentoDataFixture Magento/Sales/_files/quote_with_customer.php

Execute SUT

Definition at line 61 of file SessionTest.php.

62  {
63  $customer = $this->customerRepository->getById(1);
64  $this->checkoutSession->setCustomerData($customer);
65 
67  $quote = $this->checkoutSession->getQuote();
69  }
$customer
Definition: customers.php:11
$quote

◆ testLoadCustomerQuoteCustomerWithoutQuote()

testLoadCustomerQuoteCustomerWithoutQuote ( )

Tes merging of customer data into initialized quote object.

Conditions:

  1. Quote without customer data is set to checkout session
  2. Customer without associated quote is set to checkout session

Expected result: Quote which is set to checkout session should contain customer data

@magentoDataFixture Magento/Customer/_files/customer.php @magentoAppIsolation enabled

Ensure that customer data is still unavailable before SUT invocation

Execute SUT

Definition at line 102 of file SessionTest.php.

103  {
104  $quote = $this->checkoutSession->getQuote();
105  $this->assertEmpty($quote->getCustomerId(), 'Precondition failed: Customer data must not be set to quote');
106  $this->assertEmpty($quote->getCustomerEmail(), 'Precondition failed: Customer data must not be set to quote');
107 
108  $customer = $this->customerRepository->getById(1);
109  $this->customerSession->setCustomerDataObject($customer);
110 
112  $quote = $this->checkoutSession->getQuote();
113  $this->assertEmpty($quote->getCustomerEmail(), 'Precondition failed: Customer data must not be set to quote');
114 
116  $this->checkoutSession->loadCustomerQuote();
117  $quote = $this->checkoutSession->getQuote();
119  }
$customer
Definition: customers.php:11
$quote

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