Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-12-03 13:51:42 +0300
committerJoas Schilling <coding@schilljs.com>2020-12-07 16:19:38 +0300
commitf0ca76aefbe7717b9555e0dffb8c9340e14bf3cf (patch)
tree378f19ab3ff851f245ffe90507e51830801b8908 /tests
parent46b073d7ce49d9797caf29522358562179846abd (diff)
Add and fix unit tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Accounts/AccountsManagerTest.php51
1 files changed, 45 insertions, 6 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]));
+ }
+ }
}