27 private $adminAccount;
36 $this->dbAdapter = $this->getMockBuilder(Mysql::class)
37 ->disableOriginalConstructor()
41 ->method(
'getTableName')
42 ->willReturnCallback(
function (
$table) {
46 $this->encryptor = $this->getMockBuilder(\
Magento\Framework\Encryption\EncryptorInterface::class)
47 ->getMockForAbstractClass();
72 'username' =>
'admin',
77 $existingAdminRoleData = [
83 'role_name' =>
'admin',
89 'SELECT user_id, username, email FROM ' . $this->prefix .
90 'admin_user WHERE username = :username OR email = :email',
96 'SELECT user_id, username, email FROM ' . $this->prefix .
97 'admin_user WHERE username = :username OR email = :email',
103 'SELECT * FROM ' . $this->prefix .
104 'authorization_role WHERE user_id = :user_id AND user_type = :user_type',
105 [
'user_id' => 1,
'user_type' => 2],
107 $existingAdminRoleData,
111 ->expects($this->exactly(3))
113 ->will($this->returnValueMap($returnValueMap));
114 $this->dbAdapter->expects($this->once())->method(
'quoteInto')->will($this->returnValue(
''));
115 $this->dbAdapter->expects($this->once())->method(
'update')->will($this->returnValue(1));
117 $this->dbAdapter->expects($this->once())
119 ->with($this->equalTo(
'pre_admin_passwords'), $this->anything());
121 $this->adminAccount->save();
127 $existingUserData = [
129 'username' =>
'admin',
134 $administratorRoleData = [
140 'role_name' =>
'Administrators',
146 'SELECT user_id, username, email FROM ' . $this->prefix .
147 'admin_user WHERE username = :username OR email = :email',
153 'SELECT user_id, username, email FROM ' . $this->prefix .
154 'admin_user WHERE username = :username OR email = :email',
160 'SELECT * FROM ' . $this->prefix .
161 'authorization_role WHERE user_id = :user_id AND user_type = :user_type',
162 [
'user_id' => 1,
'user_type' => 2],
167 'SELECT * FROM ' . $this->prefix .
168 'authorization_role WHERE parent_id = :parent_id AND tree_level = :tree_level ' .
169 'AND role_type = :role_type AND user_id = :user_id ' .
170 'AND user_type = :user_type AND role_name = :role_name',
177 'role_name' =>
'Administrators',
180 $administratorRoleData,
185 ->expects(self::exactly(4))
187 ->willReturnMap($returnValueMap);
188 $this->dbAdapter->method(
'quoteInto')
190 $this->dbAdapter->method(
'update')
191 ->with(self::equalTo(
'pre_admin_user'), self::anything())
194 $this->dbAdapter->expects(self::at(8))
196 ->with(self::equalTo(
'pre_admin_passwords'), self::anything());
198 $this->dbAdapter->expects(self::at(14))
200 ->with(self::equalTo(
'pre_authorization_role'), self::anything());
202 $this->adminAccount->save();
208 $existingAdminRoleData = [
214 'role_name' =>
'admin',
220 'SELECT user_id, username, email FROM ' . $this->prefix .
221 'admin_user WHERE username = :username OR email = :email',
227 'SELECT * FROM ' . $this->prefix .
228 'authorization_role WHERE user_id = :user_id AND user_type = :user_type',
229 [
'user_id' => 1,
'user_type' => 2],
231 $existingAdminRoleData,
236 ->expects($this->exactly(2))
238 ->will($this->returnValueMap($returnValueMap));
240 $this->dbAdapter->expects($this->at(3))
242 ->with($this->equalTo(
'pre_admin_user'), $this->anything());
243 $this->dbAdapter->expects($this->at(6))
245 ->with($this->equalTo(
'pre_admin_passwords'), $this->anything());
248 $this->dbAdapter->expects($this->once())->method(
'lastInsertId')->will($this->returnValue(1));
250 $this->adminAccount->save();
256 $administratorRoleData = [
262 'role_name' =>
'Administrators',
268 'SELECT user_id, username, email FROM ' . $this->prefix .
269 'admin_user WHERE username = :username OR email = :email',
275 'SELECT * FROM ' . $this->prefix .
276 'authorization_role WHERE user_id = :user_id AND user_type = :user_type',
277 [
'user_id' => 1,
'user_type' => 2],
282 'SELECT * FROM ' . $this->prefix .
283 'authorization_role WHERE parent_id = :parent_id AND tree_level = :tree_level ' .
284 'AND role_type = :role_type AND user_id = :user_id ' .
285 'AND user_type = :user_type AND role_name = :role_name',
292 'role_name' =>
'Administrators',
295 $administratorRoleData,
301 ->expects($this->exactly(3))
303 ->will($this->returnValueMap($returnValueMap));
305 $this->dbAdapter->expects($this->once())->method(
'lastInsertId')->will($this->returnValue(1));
308 $this->dbAdapter->expects($this->exactly(3))->method(
'insert');
310 $this->adminAccount->save();
320 $existingUserData = [
322 'username' =>
'Another.name',
325 $this->dbAdapter->expects($this->exactly(2))
326 ->method(
'fetchRow')->will($this->returnValue($existingUserData));
328 $this->dbAdapter->expects($this->never())->method(
'update');
329 $this->dbAdapter->expects($this->never())->method(
'insert');
331 $this->adminAccount->save();
340 $existingUserData = [
342 'username' =>
'admin',
345 $this->dbAdapter->expects($this->exactly(2))
346 ->method(
'fetchRow')->will($this->returnValue($existingUserData));
348 $this->dbAdapter->expects($this->never())->method(
'update');
349 $this->dbAdapter->expects($this->never())->method(
'insert');
351 $this->adminAccount->save();
360 $this->dbAdapter->expects($this->exactly(3))->method(
'fetchRow')->will($this->returnValue([]));
361 $this->dbAdapter->expects($this->once())->method(
'lastInsertId')->will($this->returnValue(1));
363 $this->adminAccount->save();
389 $existingUserData = [
391 'username' =>
'passMatch2Username',
397 'SELECT user_id, username, email FROM admin_user WHERE username = :username OR email = :email',
405 ->expects($this->exactly(1))
407 ->will($this->returnValueMap($returnValueMap));
408 $this->dbAdapter->expects($this->never())->method(
'insert');
409 $this->dbAdapter->expects($this->never())->method(
'update');
411 $adminAccount->save();
437 $existingUserData = [
439 'username' =>
'passMatch2Username',
445 'SELECT user_id, username, email FROM admin_user WHERE username = :username OR email = :email',
452 ->expects($this->exactly(1))
454 ->will($this->returnValueMap($returnValueMap));
455 $this->dbAdapter->expects($this->never())->method(
'insert');
456 $this->dbAdapter->expects($this->never())->method(
'update');
458 $adminAccount->save();
testSaveExceptionSpecialAdminRoleNotFound()
testSaveExceptionUsernameNotMatch()
testSaveNewUserAdminRoleExists()
testSaveNewUserNewAdminRole()
testSaveExceptionEmailNotMatch()
testSaveUserExistsNewAdminRole()
testSaveExceptionPasswordEmpty()
testSaveUserExistsAdminRoleExists()
testSaveExceptionPasswordAndUsernameEqual()