Exemple #1
0
 /**
  * This test is designed to execute all code paths of Form\Register::getFormData() when testing the
  * Form\Register::restoreSessionData() method.
  */
 public function testRestoreSessionData()
 {
     $data = new \Magento\Framework\Object();
     $data->setRegionId(self::REGION_ID_ATTRIBUTE_VALUE);
     $data->setCustomerData(1);
     $data[self::REGION_ID_ATTRIBUTE_CODE] = (int) self::REGION_ID_ATTRIBUTE_VALUE;
     $customerFormData = array(self::REGION_ID_ATTRIBUTE_CODE => self::REGION_ID_ATTRIBUTE_VALUE);
     $this->_customerSession->expects($this->once())->method('getCustomerFormData')->will($this->returnValue($customerFormData));
     $form = $this->getMock('Magento\\Customer\\Model\\Metadata\\Form', array(), array(), '', false);
     $request = $this->getMockForAbstractClass('Magento\\Framework\\App\\RequestInterface', array(), '', false);
     $formData = $this->_block->getFormData();
     $form->expects($this->once())->method('prepareRequest')->with($formData->getData())->will($this->returnValue($request));
     $form->expects($this->once())->method('extractData')->with($request, null, false)->will($this->returnValue($customerFormData));
     $form->expects($this->once())->method('restoreData')->will($this->returnValue($customerFormData));
     $block = $this->_block->restoreSessionData($form, null, false);
     $this->assertSame($this->_block, $block);
     $this->assertEquals($data, $block->getData(self::FORM_DATA));
 }
 /**
  * Retrieve form data
  *
  * @return mixed
  */
 public function getFormData()
 {
     $data = $this->getData('form_data');
     if ($data === null) {
         $formData = $this->_customerSession->getCustomerFormData(true);
         $data = new \Magento\Framework\Object();
         if ($formData) {
             $data->addData($formData);
             $data->setCustomerData(1);
         }
         if (isset($data['region_id'])) {
             $data['region_id'] = (int) $data['region_id'];
         }
         $this->setData('form_data', $data);
     }
     return $data;
 }