/** * Stores user data in database. * Used internally in sAdmin during the registration process * * @param array $userObject Array with all information from the registration process * @return int Created user id */ public function sSaveRegisterMainData($userObject) { // Support for merchants $sMerchant = $userObject["billing"]["sValidation"] ?: ""; $defaultCustomerGroup = $this->config->get('sDefaultCustomerGroup'); if (empty($defaultCustomerGroup)) { $this->config->offsetSet('sDefaultCustomerGroup', 'EK'); } $referer = $this->session->offsetGet('sReferer'); $partnerId = $this->session->offsetGet('sPartner'); if (!empty($partnerId)) { $partner = (int) $this->db->fetchOne('SELECT id FROM s_emarketing_partner WHERE idcode = ?', array($partnerId)); } $data = array($userObject["auth"]["password"], $userObject["auth"]["email"], $userObject["payment"]["object"]["id"], $userObject["auth"]["accountmode"], empty($sMerchant) ? "" : $sMerchant, $this->session->offsetGet('sessionId'), empty($partner) ? "" : $partner, $this->config->get('sDefaultCustomerGroup'), $this->contextService->getShopContext()->getShop()->getId(), $this->subshopId, empty($referer) ? "" : $referer, $userObject["auth"]["encoderName"]); $sql = ' INSERT INTO s_user ( password, email, paymentID, active, accountmode, validation, firstlogin, sessionID, affiliate, customergroup, language, subshopID, referer, encoder ) VALUES (?,?,?,1,?,?,NOW(),?,?,?,?,?,?,?) '; list($sql, $data) = $this->eventManager->filter('Shopware_Modules_Admin_SaveRegisterMainData_FilterSql', array($sql, $data), array('subject' => $this)); $saveUserData = $this->db->query($sql, $data); $this->eventManager->notify('Shopware_Modules_Admin_SaveRegisterMainData_Return', array('subject' => $this, 'insertObject' => $saveUserData)); $userId = $this->db->lastInsertId(); $sql = "\n INSERT INTO s_user_attributes (userID) VALUES (?)\n "; $data = array($userId); list($sql, $data) = $this->eventManager->filter('Shopware_Modules_Admin_SaveRegisterMainDataAttributes_FilterSql', array($sql, $data), array('subject' => $this)); $saveAttributeData = $this->db->query($sql, $data); $this->eventManager->notify('Shopware_Modules_Admin_SaveRegisterMainDataAttributes_Return', array('subject' => $this, 'insertObject' => $saveAttributeData)); return $userId; }
/** * @covers sAdmin::sValidateStep2 */ public function testsValidateStep2() { // Test with no rules, should always validate $result = $this->module->sValidateStep2(array()); $this->assertInternalType('array', $result); $this->assertArrayHasKey('sErrorFlag', $result); $this->assertArrayHasKey('sErrorMessages', $result); $this->assertCount(0, $result['sErrorFlag']); $this->assertCount(0, $result['sErrorMessages']); $testRuleSet = array('testField1' => array('required' => 1), 'testField2' => array('required' => 0), 'testField3' => array('required' => 1)); // Test failing validation, should have 2 failing fields $result = $this->module->sValidateStep2($testRuleSet); $this->assertInternalType('array', $result); $this->assertArrayHasKey('sErrorFlag', $result); $this->assertArrayHasKey('sErrorMessages', $result); $this->assertCount(2, $result['sErrorFlag']); $this->assertArrayHasKey('testField1', $result['sErrorFlag']); $this->assertArrayHasKey('testField3', $result['sErrorFlag']); $this->assertCount(1, $result['sErrorMessages']); // Setup dummy test data and test with it, see it passes $this->front->Request()->setPost(array('testField1' => 'testValue', 'testField2' => 'testValue', 'testField3' => 'testValue')); $result = $this->module->sValidateStep2($testRuleSet); $this->assertInternalType('array', $result); $this->assertArrayHasKey('sErrorFlag', $result); $this->assertArrayHasKey('sErrorMessages', $result); $this->assertCount(0, $result['sErrorFlag']); $this->assertCount(0, $result['sErrorMessages']); // Test that using vat id will trigger aux function to validate it $this->config->offsetSet('sVATCHECKENDABLED', true); $testRuleSet['ustid'] = array('required' => 1); $this->front->Request()->setPost('ustid', '12345'); $result = $this->module->sValidateStep2($testRuleSet); $this->assertInternalType('array', $result); $this->assertArrayHasKey('sErrorFlag', $result); $this->assertArrayHasKey('sErrorMessages', $result); $this->assertCount(1, $result['sErrorFlag']); $this->assertCount(1, $result['sErrorMessages']); $this->assertContains('VatFailureInvalid', $result['sErrorFlag']); $this->assertContains('VatFailureErrorInfo', $result['sErrorFlag']); }