diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2020-12-08 17:05:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-08 17:05:38 +0100 |
commit | 86a3b7e7bf419e2bf1acc687625d0ff8596d39dc (patch) | |
tree | e467d21a31f7e78320ee9739ba66dccd4025eb65 /tests/lib | |
parent | fda6ffc866cf8c5d3579fe95d1731ab747894002 (diff) | |
parent | 13a438b3224f3f42a0f552230f680a243e1af705 (diff) | |
download | nextcloud-server-86a3b7e7bf419e2bf1acc687625d0ff8596d39dc.tar.gz nextcloud-server-86a3b7e7bf419e2bf1acc687625d0ff8596d39dc.zip |
Merge pull request #24486 from nextcloud/feature/noid/phone-number-validation
Phone number validation and search
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/Accounts/AccountsManagerTest.php | 51 | ||||
-rw-r--r-- | tests/lib/Accounts/HooksTest.php | 29 |
2 files changed, 60 insertions, 20 deletions
diff --git a/tests/lib/Accounts/AccountsManagerTest.php b/tests/lib/Accounts/AccountsManagerTest.php index ff75b51d008..d13d5f4186a 100644 --- a/tests/lib/Accounts/AccountsManagerTest.php +++ b/tests/lib/Accounts/AccountsManagerTest.php @@ -25,6 +25,7 @@ use OC\Accounts\Account; use OC\Accounts\AccountManager; use OCP\Accounts\IAccountManager; use OCP\BackgroundJob\IJobList; +use OCP\IConfig; use OCP\IUser; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; @@ -43,6 +44,9 @@ class AccountsManagerTest extends TestCase { /** @var \OCP\IDBConnection */ private $connection; + /** @var IConfig|MockObject */ + private $config; + /** @var EventDispatcherInterface|MockObject */ private $eventDispatcher; @@ -59,6 +63,7 @@ class AccountsManagerTest extends TestCase { parent::setUp(); $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class); $this->connection = \OC::$server->getDatabaseConnection(); + $this->config = $this->createMock(IConfig::class); $this->jobList = $this->createMock(IJobList::class); $this->logger = $this->createMock(LoggerInterface::class); } @@ -77,7 +82,13 @@ class AccountsManagerTest extends TestCase { */ public function getInstance($mockedMethods = null) { return $this->getMockBuilder(AccountManager::class) - ->setConstructorArgs([$this->connection, $this->eventDispatcher, $this->jobList, $this->logger]) + ->setConstructorArgs([ + $this->connection, + $this->config, + $this->eventDispatcher, + $this->jobList, + $this->logger, + ]) ->setMethods($mockedMethods) ->getMock(); } @@ -187,9 +198,9 @@ class AccountsManagerTest extends TestCase { public function testUpdateExistingUser() { $user = $this->getMockBuilder(IUser::class)->getMock(); - $user->expects($this->once())->method('getUID')->willReturn('uid'); - $oldData = ['key' => 'value']; - $newData = ['newKey' => 'newValue']; + $user->expects($this->atLeastOnce())->method('getUID')->willReturn('uid'); + $oldData = ['key' => ['value' => 'value']]; + $newData = ['newKey' => ['value' => 'newValue']]; $accountManager = $this->getInstance(); $this->addDummyValuesToTable('uid', $oldData); @@ -201,10 +212,10 @@ class AccountsManagerTest extends TestCase { public function testInsertNewUser() { $user = $this->getMockBuilder(IUser::class)->getMock(); $uid = 'uid'; - $data = ['key' => 'value']; + $data = ['key' => ['value' => 'value']]; $accountManager = $this->getInstance(); - $user->expects($this->once())->method('getUID')->willReturn($uid); + $user->expects($this->atLeastOnce())->method('getUID')->willReturn($uid); $this->assertNull($this->getDataFromTable($uid)); $this->invokePrivate($accountManager, 'insertNewUser', [$user, $data]); @@ -293,4 +304,32 @@ class AccountsManagerTest extends TestCase { ->willReturn($data); $this->assertEquals($expected, $accountManager->getAccount($user)); } + + public function dataParsePhoneNumber(): array { + return [ + ['0711 / 25 24 28-90', 'DE', '+4971125242890'], + ['0711 / 25 24 28-90', '', null], + ['+49 711 / 25 24 28-90', '', '+4971125242890'], + ]; + } + + /** + * @dataProvider dataParsePhoneNumber + * @param string $phoneInput + * @param string $defaultRegion + * @param string|null $phoneNumber + */ + public function testParsePhoneNumber(string $phoneInput, string $defaultRegion, ?string $phoneNumber): void { + $this->config->method('getSystemValueString') + ->willReturn($defaultRegion); + + $instance = $this->getInstance(); + + if ($phoneNumber === null) { + $this->expectException(\InvalidArgumentException::class); + self::invokePrivate($instance, 'parsePhoneNumber', [$phoneInput]); + } else { + self::assertEquals($phoneNumber, self::invokePrivate($instance, 'parsePhoneNumber', [$phoneInput])); + } + } } diff --git a/tests/lib/Accounts/HooksTest.php b/tests/lib/Accounts/HooksTest.php index 39003b2ef23..8af9e209034 100644 --- a/tests/lib/Accounts/HooksTest.php +++ b/tests/lib/Accounts/HooksTest.php @@ -23,6 +23,7 @@ namespace Test\Accounts; use OC\Accounts\AccountManager; use OC\Accounts\Hooks; +use OCP\Accounts\IAccountManager; use OCP\IUser; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; @@ -77,11 +78,11 @@ class HooksTest extends TestCase { $this->accountManager->expects($this->once())->method('getUser')->willReturn($data); $newData = $data; if ($setEmail) { - $newData[AccountManager::PROPERTY_EMAIL]['value'] = $params['value']; + $newData[IAccountManager::PROPERTY_EMAIL]['value'] = $params['value']; $this->accountManager->expects($this->once())->method('updateUser') ->with($params['user'], $newData); } elseif ($setDisplayName) { - $newData[AccountManager::PROPERTY_DISPLAYNAME]['value'] = $params['value']; + $newData[IAccountManager::PROPERTY_DISPLAYNAME]['value'] = $params['value']; $this->accountManager->expects($this->once())->method('updateUser') ->with($params['user'], $newData); } else { @@ -98,48 +99,48 @@ class HooksTest extends TestCase { [ ['feature' => '', 'value' => ''], [ - AccountManager::PROPERTY_EMAIL => ['value' => ''], - AccountManager::PROPERTY_DISPLAYNAME => ['value' => ''] + IAccountManager::PROPERTY_EMAIL => ['value' => ''], + IAccountManager::PROPERTY_DISPLAYNAME => ['value' => ''] ], false, false, true ], [ ['user' => $user, 'value' => ''], [ - AccountManager::PROPERTY_EMAIL => ['value' => ''], - AccountManager::PROPERTY_DISPLAYNAME => ['value' => ''] + IAccountManager::PROPERTY_EMAIL => ['value' => ''], + IAccountManager::PROPERTY_DISPLAYNAME => ['value' => ''] ], false, false, true ], [ ['user' => $user, 'feature' => ''], [ - AccountManager::PROPERTY_EMAIL => ['value' => ''], - AccountManager::PROPERTY_DISPLAYNAME => ['value' => ''] + IAccountManager::PROPERTY_EMAIL => ['value' => ''], + IAccountManager::PROPERTY_DISPLAYNAME => ['value' => ''] ], false, false, true ], [ ['user' => $user, 'feature' => 'foo', 'value' => 'bar'], [ - AccountManager::PROPERTY_EMAIL => ['value' => 'oldMail@example.com'], - AccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName'] + IAccountManager::PROPERTY_EMAIL => ['value' => 'oldMail@example.com'], + IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName'] ], false, false, false ], [ ['user' => $user, 'feature' => 'eMailAddress', 'value' => 'newMail@example.com'], [ - AccountManager::PROPERTY_EMAIL => ['value' => 'oldMail@example.com'], - AccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName'] + IAccountManager::PROPERTY_EMAIL => ['value' => 'oldMail@example.com'], + IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName'] ], true, false, false ], [ ['user' => $user, 'feature' => 'displayName', 'value' => 'newDisplayName'], [ - AccountManager::PROPERTY_EMAIL => ['value' => 'oldMail@example.com'], - AccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName'] + IAccountManager::PROPERTY_EMAIL => ['value' => 'oldMail@example.com'], + IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName'] ], false, true, false ], |