public function testGetRegionCodeRegionFailure() { $this->address->setData(['region' => 1, 'region_id' => 1, 'country_id' => 1]); $this->regionFactoryMock->expects($this->once())->method('create')->willReturn($this->regionMock); $this->regionMock->expects($this->once())->method('load')->with(1)->willReturn($this->regionMock); $this->regionMock->expects($this->once())->method('getCountryId')->willReturn(2); $this->regionMock->expects($this->never())->method('getCode'); $this->assertEquals(null, $this->address->getRegionCode()); }
public function testBeforeSave() { $regionId = '23'; $countryId = '67'; $this->object->expects($this->once())->method('getData')->with('region')->willReturn($regionId); $this->object->expects($this->once())->method('getCountryId')->willReturn($countryId); $this->regionFactory->expects($this->once())->method('create')->willReturn($this->region); $this->region->expects($this->once())->method('load')->with($regionId)->willReturnSelf(); $this->region->expects($this->atLeastOnce())->method('getId')->willReturn($regionId); $this->region->expects($this->once())->method('getCountryId')->willReturn($countryId); $this->object->expects($this->once())->method('setRegionId')->with($regionId)->willReturnSelf(); $this->region->expects($this->once())->method('getName')->willReturn('Region name'); $this->object->expects($this->once())->method('setRegion')->with('Region name'); $this->model->beforeSave($this->object); }
/** * @param $countryId */ protected function prepareGetRegionCode($countryId, $regionCode = 'UK') { $region = $this->getMock('Magento\\Directory\\Model\\Region', ['getCountryId', 'getCode', '__wakeup', 'load'], [], '', false); $region->expects($this->once())->method('getCode')->will($this->returnValue($regionCode)); $region->expects($this->once())->method('getCountryId')->will($this->returnValue($countryId)); $this->regionFactoryMock->expects($this->once())->method('create')->will($this->returnValue($region)); }
/** * @param \Magento\Framework\DataObject $paymentObject * @param int $storeId * @return array * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function setupPaymentObject(\Magento\Framework\DataObject $paymentObject, $storeId) { $customerId = '12'; $customerEmail = '*****@*****.**'; $company = 'NA'; $phone = '3316655'; $fax = '3316677'; $orderId = '100000024'; $street = '1201 N 1st Stree'; $street2 = 'build 45'; $city = 'San Jose'; $region = 'California'; $regionCode = 'CA'; $regionId = 65; $postcode = '63241'; $countryId = 'US'; $addressData = ['firstname' => self::FNAME, 'lastname' => self::LNAME, 'company' => $company, 'telephone' => $phone, 'fax' => $fax, 'street' => [$street, $street2], 'city' => $city, 'region' => $region, 'region_id' => $regionId, 'postcode' => $postcode, 'country_id' => $countryId, 'address_type' => 'billing']; $billingAddress = new \Magento\Framework\DataObject($addressData); $addressData['address_type'] = 'shipping'; $shippingAddress = new \Magento\Framework\DataObject($addressData); $order = $this->setupOrderMock($billingAddress, $shippingAddress, $customerEmail, $orderId, $customerId, $storeId); $paymentObject->setOrder($order); $this->helperMock->expects($this->once())->method('generateCustomerId')->with($customerId, $customerEmail)->willReturn(self::CUSTOMER_ID); $regionMock = $this->getMockBuilder('Magento\\Directory\\Model\\Region')->disableOriginalConstructor()->setMethods(['getId', 'getCode', 'load'])->getMock(); $regionMock->expects($this->any())->method('getId')->willReturn($regionId); $regionMock->expects($this->any())->method('getCode')->willReturn($regionCode); $regionMock->expects($this->any())->method('load')->with($regionId)->willReturnSelf(); $this->regionFactoryMock->expects($this->any())->method('create')->willReturn($regionMock); $braintreeAddressData = ['firstName' => self::FNAME, 'lastName' => self::LNAME, 'company' => $company, 'streetAddress' => $street, 'extendedAddress' => $street2, 'locality' => $city, 'region' => $regionCode, 'postalCode' => $postcode, 'countryCodeAlpha2' => $countryId]; return ['channel' => self::CHANNEL, 'orderId' => $orderId, 'customer' => ['firstName' => self::FNAME, 'lastName' => self::LNAME, 'company' => $company, 'phone' => $phone, 'fax' => $fax, 'email' => $customerEmail], 'billing' => $braintreeAddressData, 'shipping' => $braintreeAddressData]; }
/** * Init mocks for tests */ protected function setUp() { $mockData = $this->mockConfigData = [Information::XML_PATH_STORE_INFO_NAME => 'Country Furnishings', Information::XML_PATH_STORE_INFO_PHONE => '000-000-0000', Information::XML_PATH_STORE_INFO_HOURS => '9 AM to 5 PM', Information::XML_PATH_STORE_INFO_STREET_LINE1 => '1234 Example Ct', Information::XML_PATH_STORE_INFO_STREET_LINE2 => 'Suite A', Information::XML_PATH_STORE_INFO_CITY => 'Aldburg', Information::XML_PATH_STORE_INFO_POSTCODE => '65804', Information::XML_PATH_STORE_INFO_REGION_CODE => 1989, Information::XML_PATH_STORE_INFO_COUNTRY_CODE => 'ED', Information::XML_PATH_STORE_INFO_VAT_NUMBER => '123456789']; $this->store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); $this->store->expects($this->any())->method('getConfig')->willReturnCallback(function ($path) use($mockData) { return isset($mockData[$path]) ? $mockData[$path] : null; }); $this->renderer = $this->getMockBuilder('Magento\\Store\\Model\\Address\\Renderer')->disableOriginalConstructor()->setMethods(['format'])->getMock(); $this->renderer->expects($this->once())->method('format')->willReturnCallback(function ($storeInfo) { return implode("\n", $storeInfo->getData()); }); $region = $this->getMock('Magento\\Framework\\DataObject', ['load', 'getName']); $region->expects($this->once())->method('load')->willReturnSelf(); $region->expects($this->once())->method('getName')->willReturn('Rohan'); $this->regionFactory = $this->getMock('Magento\\Directory\\Model\\RegionFactory', [], [], '', false); $this->regionFactory->expects($this->once())->method('create')->willReturn($region); $country = $this->getMock('Magento\\Framework\\DataObject', ['loadByCode', 'getName']); $country->expects($this->once())->method('loadByCode')->with('ED')->willReturnSelf(); $country->expects($this->once())->method('getName')->willReturn('Edoras'); $this->countryFactory = $this->getMock('Magento\\Directory\\Model\\CountryFactory', [], [], '', false); $this->countryFactory->expects($this->once())->method('create')->willReturn($country); $this->model = new Information($this->renderer, $this->regionFactory, $this->countryFactory); }