6 declare(strict_types=1);
24 use PHPUnit_Framework_MockObject_MockObject as MockObject;
35 private $objectManager;
45 private $quoteSession;
52 $this->objectManager = Bootstrap::getObjectManager();
54 $this->quoteSession = $this->getMockBuilder(QuoteSession::class)
55 ->disableOriginalConstructor()
56 ->setMethods([
'getCustomerId',
'getStore',
'getStoreId',
'getQuote'])
59 $this->block = $this->objectManager->create(
61 [
'sessionQuote' => $this->quoteSession]
72 $website = $this->getWebsite(
'base');
75 $this->quoteSession->method(
'getCustomerId')
78 $actual = $this->block->getAddressCollection();
79 self::assertNotEmpty($actual);
90 $website = $this->getWebsite(
'test');
94 $this->quoteSession->method(
'getStore')
96 $this->quoteSession->method(
'getCustomerId')
101 'firstname' =>
false,
106 'country_id' =>
'US',
108 'region_id' =>
false,
110 'telephone' =>
false,
114 'firstname' =>
'John',
115 'lastname' =>
'Smith',
117 'street' =>
'Green str, 67',
118 'city' =>
'Culver City',
119 'country_id' =>
'US',
120 'region' =>
'California',
122 'postcode' =>
'90230',
123 'telephone' =>
'3468676',
127 'telephone' =>
'845454465',
128 'postcode' =>
'10178',
129 'country_id' =>
'DE',
131 'street' =>
'Tunnel Alexanderpl',
132 'firstname' =>
'John',
133 'lastname' =>
'Smith',
141 $actual = json_decode($this->block->getAddressCollectionJson(),
true);
142 self::assertEquals($expected, $actual);
151 'firstname' =>
'John',
152 'lastname' =>
'Smith',
153 'company' =>
'Test Company',
154 'street' =>
'Green str, 67',
155 'city' =>
'Culver City',
156 'country_id' =>
'US',
157 'region' =>
'California',
159 'postcode' =>
'90230',
160 'telephone' =>
'3468676',
162 $address = $this->objectManager->create(AddressInterface::class, [
'data' =>
$data]);
163 $expected =
'John Smith, Green str, 67, Culver City, California 90230, United States';
164 self::assertEquals($expected, $this->block->getAddressAsString(
$address));
167 public function testGetForm()
187 $form = $this->block->getForm();
188 self::assertEquals(1, $form->getElements()->count(),
'Form has invalid number of fieldsets');
191 $fieldset = $form->getElements()[0];
193 count($expectedFields),
194 $fieldset->getElements()->count(),
195 'Form has invalid number of fields' 199 foreach ($fieldset->getElements() as
$element) {
201 in_array(
$element->getId(), $expectedFields),
202 sprintf(
'Unexpected field "%s" in form.',
$element->getId())
207 $countryIdField = $fieldset->getElements()->searchById(
'country_id');
208 $actual = Xpath::getElementsCountForXpath(
'//option', $countryIdField->getElementHtml());
209 self::assertEquals($this->getNumberOfCountryOptions(), $actual);
224 $repository = $this->objectManager->get(CustomerRepositoryInterface::class);
235 private function getWebsite(
string $code): WebsiteInterface
238 $repository = $this->objectManager->get(WebsiteRepositoryInterface::class);
252 $repository = $this->objectManager->get(StoreRepositoryInterface::class);
259 private function getNumberOfCountryOptions()
262 $countryCollection = $this->objectManager->create(Collection::class);
263 return count($countryCollection->toOptionArray());