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

Public Member Functions

 testBeforeSavePaymentInformationAndPlaceOrder ()
 
 testBeforeSavePaymentInformationAndPlaceOrderIfAgreementsNotValid ()
 
 testBeforeSavePaymentInformation ()
 

Protected Member Functions

 setUp ()
 

Protected Attributes

 $model
 
 $agreementsValidatorMock
 
 $subjectMock
 
 $paymentMock
 
 $addressMock
 
 $extensionAttributesMock
 
 $scopeConfigMock
 

Detailed Description

Class ValidationTest @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 16 of file ValidationTest.php.

Member Function Documentation

◆ setUp()

setUp ( )
protected

Definition at line 63 of file ValidationTest.php.

64  {
65  $this->agreementsValidatorMock = $this->createMock(\Magento\Checkout\Api\AgreementsValidatorInterface::class);
66  $this->subjectMock = $this->createMock(\Magento\Checkout\Api\PaymentInformationManagementInterface::class);
67  $this->paymentMock = $this->createMock(\Magento\Quote\Api\Data\PaymentInterface::class);
68  $this->addressMock = $this->createMock(\Magento\Quote\Api\Data\AddressInterface::class);
69  $this->extensionAttributesMock = $this->createPartialMock(
70  \Magento\Quote\Api\Data\PaymentExtension::class,
71  ['getAgreementIds']
72  );
73  $this->scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
74  $this->checkoutAgreementsListMock = $this->createMock(
75  \Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface::class
76  );
77  $this->agreementsFilterMock = $this->createMock(
78  \Magento\CheckoutAgreements\Model\Api\SearchCriteria\ActiveStoreAgreementsFilter::class
79  );
80 
81  $this->model = new \Magento\CheckoutAgreements\Model\Checkout\Plugin\Validation(
82  $this->agreementsValidatorMock,
83  $this->scopeConfigMock,
84  $this->checkoutAgreementsListMock,
85  $this->agreementsFilterMock
86  );
87  }

◆ testBeforeSavePaymentInformation()

testBeforeSavePaymentInformation ( )

Definition at line 146 of file ValidationTest.php.

147  {
148  $cartId = 100;
149  $agreements = [1, 2, 3];
150  $this->scopeConfigMock
151  ->expects($this->once())
152  ->method('isSetFlag')
154  ->willReturn(true);
155  $searchCriteriaMock = $this->createMock(\Magento\Framework\Api\SearchCriteria::class);
156  $this->agreementsFilterMock->expects($this->once())
157  ->method('buildSearchCriteria')
158  ->willReturn($searchCriteriaMock);
159  $this->checkoutAgreementsListMock->expects($this->once())
160  ->method('getList')
161  ->with($searchCriteriaMock)
162  ->willReturn([1]);
163  $this->extensionAttributesMock->expects($this->once())->method('getAgreementIds')->willReturn($agreements);
164  $this->agreementsValidatorMock->expects($this->once())->method('isValid')->with($agreements)->willReturn(true);
165  $this->paymentMock->expects(static::atLeastOnce())
166  ->method('getExtensionAttributes')
167  ->willReturn($this->extensionAttributesMock);
168  $this->model->beforeSavePaymentInformation($this->subjectMock, $cartId, $this->paymentMock, $this->addressMock);
169  }
$cartId
Definition: quote.php:22

◆ testBeforeSavePaymentInformationAndPlaceOrder()

testBeforeSavePaymentInformationAndPlaceOrder ( )

Definition at line 89 of file ValidationTest.php.

90  {
91  $cartId = 100;
92  $agreements = [1, 2, 3];
93  $this->scopeConfigMock
94  ->expects($this->once())
95  ->method('isSetFlag')
97  ->willReturn(true);
98  $searchCriteriaMock = $this->createMock(\Magento\Framework\Api\SearchCriteria::class);
99  $this->agreementsFilterMock->expects($this->once())
100  ->method('buildSearchCriteria')
101  ->willReturn($searchCriteriaMock);
102  $this->checkoutAgreementsListMock->expects($this->once())
103  ->method('getList')
104  ->with($searchCriteriaMock)
105  ->willReturn([1]);
106  $this->extensionAttributesMock->expects($this->once())->method('getAgreementIds')->willReturn($agreements);
107  $this->agreementsValidatorMock->expects($this->once())->method('isValid')->with($agreements)->willReturn(true);
108  $this->paymentMock->expects(static::atLeastOnce())
109  ->method('getExtensionAttributes')
110  ->willReturn($this->extensionAttributesMock);
111  $this->model->beforeSavePaymentInformation($this->subjectMock, $cartId, $this->paymentMock, $this->addressMock);
112  }
$cartId
Definition: quote.php:22

◆ testBeforeSavePaymentInformationAndPlaceOrderIfAgreementsNotValid()

testBeforeSavePaymentInformationAndPlaceOrderIfAgreementsNotValid ( )

@expectedException \Magento\Framework\Exception\CouldNotSaveException

Definition at line 117 of file ValidationTest.php.

118  {
119  $cartId = 100;
120  $agreements = [1, 2, 3];
121  $this->scopeConfigMock
122  ->expects($this->once())
123  ->method('isSetFlag')
125  ->willReturn(true);
126  $searchCriteriaMock = $this->createMock(\Magento\Framework\Api\SearchCriteria::class);
127  $this->agreementsFilterMock->expects($this->once())
128  ->method('buildSearchCriteria')
129  ->willReturn($searchCriteriaMock);
130  $this->checkoutAgreementsListMock->expects($this->once())
131  ->method('getList')
132  ->with($searchCriteriaMock)
133  ->willReturn([1]);
134  $this->extensionAttributesMock->expects($this->once())->method('getAgreementIds')->willReturn($agreements);
135  $this->agreementsValidatorMock->expects($this->once())->method('isValid')->with($agreements)->willReturn(false);
136  $this->paymentMock->expects(static::atLeastOnce())
137  ->method('getExtensionAttributes')
138  ->willReturn($this->extensionAttributesMock);
139  $this->model->beforeSavePaymentInformation($this->subjectMock, $cartId, $this->paymentMock, $this->addressMock);
140 
141  $this->expectExceptionMessage(
142  "The order wasn't placed. First, agree to the terms and conditions, then try placing your order again."
143  );
144  }
$cartId
Definition: quote.php:22

Field Documentation

◆ $addressMock

$addressMock
protected

Definition at line 41 of file ValidationTest.php.

◆ $agreementsValidatorMock

$agreementsValidatorMock
protected

Definition at line 26 of file ValidationTest.php.

◆ $extensionAttributesMock

$extensionAttributesMock
protected

Definition at line 46 of file ValidationTest.php.

◆ $model

$model
protected

Definition at line 21 of file ValidationTest.php.

◆ $paymentMock

$paymentMock
protected

Definition at line 36 of file ValidationTest.php.

◆ $scopeConfigMock

$scopeConfigMock
protected

Definition at line 51 of file ValidationTest.php.

◆ $subjectMock

$subjectMock
protected

Definition at line 31 of file ValidationTest.php.


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