Exemplo n.º 1
0
 public function testDelete()
 {
     $dbAdapter = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface');
     $this->resource->expects($this->once())->method('getConnection')->will($this->returnValue($dbAdapter));
     $customer = $this->getMock('Magento\\Customer\\Model\\Customer', ['__wakeup', 'load', 'getId', 'getStoreId', 'setGroupId', 'save'], [], '', false);
     $customerId = 1;
     $customer->expects($this->once())->method('getId')->will($this->returnValue($customerId));
     $customer->expects($this->once())->method('load')->with($customerId)->will($this->returnSelf());
     $defaultCustomerGroup = 1;
     $this->customerHelper->expects($this->once())->method('getDefaultCustomerGroupId')->will($this->returnValue($defaultCustomerGroup));
     $customer->expects($this->once())->method('setGroupId')->with($defaultCustomerGroup);
     $customerCollection = $this->getMock('Magento\\Customer\\Model\\Resource\\Customer\\Collection', [], [], '', false);
     $customerCollection->expects($this->once())->method('addAttributeToFilter')->will($this->returnSelf());
     $customerCollection->expects($this->once())->method('load')->will($this->returnValue([$customer]));
     $this->customersFactory->expects($this->once())->method('create')->will($this->returnValue($customerCollection));
     $this->groupResourceModel->delete($this->groupModel);
 }
Exemplo n.º 2
0
 /**
  * @param $customerData
  * @param $isSingleStoreMode
  * @param $canModifyCustomer
  */
 private function _setupStoreMode($customerData, $isSingleStoreMode, $canModifyCustomer)
 {
     $backendSessionMock = $this->getMock('\\Magento\\Backend\\Model\\Session', ['getCustomerData'], [], '', false);
     $backendSessionMock->expects($this->any())->method('getCustomerData')->will($this->returnValue([]));
     $layoutMock = $this->getMock('\\Magento\\Framework\\View\\Layout\\Element\\Layout', ['createBlock'], [], '', false);
     $layoutMock->expects($this->at(0))->method('createBlock')->with('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Group')->will($this->returnValue($this->objectManagerHelper->getObject('\\Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Group')));
     $layoutMock->expects($this->at(1))->method('createBlock')->with('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element')->will($this->returnValue($this->objectManagerHelper->getObject('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element')));
     if (empty($customerData['id'])) {
         $layoutMock->expects($this->at(2))->method('createBlock')->with('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Sendemail')->will($this->returnValue($this->objectManagerHelper->getObject('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Sendemail')));
     }
     $urlBuilderMock = $this->getMock('\\Magento\\Backend\\Model\\Url', ['getBaseUrl'], [], '', false);
     $urlBuilderMock->expects($this->once())->method('getBaseUrl')->will($this->returnValue('someUrl'));
     $storeManagerMock = $this->getMock('Magento\\Store\\Model\\StoreManager', [], [], '', false);
     $storeManagerMock->expects($this->any())->method('isSingleStoreMode')->will($this->returnValue($isSingleStoreMode));
     $customerObject = $this->getMockBuilder('\\Magento\\Customer\\Service\\V1\\Data\\Customer')->setMethods(['__toArray', 'getId'])->disableOriginalConstructor()->getMock();
     $customerObject->expects($this->any())->method('__toArray')->will($this->returnValue($customerData));
     if (!empty($customerData['id'])) {
         $customerObject->expects($this->any())->method('getId')->will($this->returnValue($customerData['id']));
     }
     $fieldset = $this->getMockBuilder('\\Magento\\Framework\\Data\\Form\\Element\\Fieldset')->setMethods(['getForm', 'addField', 'removeField'])->disableOriginalConstructor()->getMock();
     $accountForm = $this->getMockBuilder('Magento\\Framework\\Data\\Form')->setMethods(['create', 'addFieldset', 'getElement', 'setValues'])->disableOriginalConstructor()->getMock();
     $accountForm->expects($this->any())->method('addFieldset')->with('base_fieldset')->will($this->returnValue($fieldset));
     $accountForm->expects($this->any())->method('setValues')->will($this->returnValue($accountForm));
     $fieldset->expects($this->any())->method('getForm')->will($this->returnValue($accountForm));
     $formElement = $this->getMockBuilder('\\Magento\\Framework\\Data\\Form\\Element\\Select')->setMethods(['setRenderer', 'addClass', 'setDisabled'])->disableOriginalConstructor()->getMock();
     $formElement->expects($this->any())->method('setRenderer')->will($this->returnValue(null));
     $formElement->expects($this->any())->method('addClass')->will($this->returnValue(null));
     $formElement->expects($this->any())->method('setDisabled')->will($this->returnValue(null));
     $accountForm->expects($this->any())->method('getElement')->withAnyParameters()->will($this->returnValue($formElement));
     $fieldset->expects($this->any())->method('addField')->will($this->returnValue($formElement));
     $customerForm = $this->getMock('\\Magento\\Customer\\Model\\Metadata\\Form', ['getAttributes'], [], '', false);
     $customerForm->expects($this->any())->method('getAttributes')->will($this->returnValue([]));
     $this->contextMock->expects($this->any())->method('getBackendSession')->will($this->returnValue($backendSessionMock));
     $this->contextMock->expects($this->any())->method('getLayout')->will($this->returnValue($layoutMock));
     $this->contextMock->expects($this->any())->method('getUrlBuilder')->will($this->returnValue($urlBuilderMock));
     $this->contextMock->expects($this->any())->method('getStoreManager')->will($this->returnValue($storeManagerMock));
     $this->customerBuilderMock->expects($this->any())->method('populateWithArray')->will($this->returnValue($this->customerBuilderMock));
     $this->customerBuilderMock->expects($this->any())->method('create')->will($this->returnValue($customerObject));
     $this->customerHelperMock->expects($this->any())->method('getNamePrefixOptions')->will($this->returnValue(['Pref1', 'Pref2']));
     $this->customerHelperMock->expects($this->any())->method('getNameSuffixOptions')->will($this->returnValue(['Suf1', 'Suf2']));
     $this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($accountForm));
     $this->customerFormFactoryMock->expects($this->any())->method('create')->with('customer', 'adminhtml_customer')->will($this->returnValue($customerForm));
     $this->customerAccountServiceInterfaceMock->expects($this->any())->method('canModify')->withAnyParameters()->will($this->returnValue($canModifyCustomer));
     $this->customerAccountServiceInterfaceMock->expects($this->any())->method('getConfirmationStatus')->withAnyParameters()->will($this->returnValue(CustomerAccountServiceInterface::ACCOUNT_CONFIRMED));
 }
Exemplo n.º 3
0
 public function testGetHrefLoggedOut()
 {
     $this->httpContext->expects($this->once())->method('getValue')->will($this->returnValue(false));
     $this->_helper->expects($this->once())->method('getLoginUrl')->will($this->returnValue('login url'));
     $this->assertEquals('login url', $this->_block->getHref());
 }