2018-12-17 16:55:00 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2018 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
*
|
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2020-04-29 12:57:22 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2018-12-17 16:55:00 +03:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-12-17 16:55:00 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\User_LDAP\Tests\User;
|
|
|
|
|
|
|
|
use OCA\User_LDAP\Mapping\UserMapping;
|
|
|
|
use OCA\User_LDAP\User\DeletedUsersIndex;
|
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class DeletedUsersIndexTest
|
|
|
|
*
|
|
|
|
* @group DB
|
|
|
|
*
|
|
|
|
* @package OCA\User_LDAP\Tests\User
|
|
|
|
*/
|
|
|
|
class DeletedUsersIndexTest extends \Test\TestCase {
|
|
|
|
/** @var DeletedUsersIndex */
|
|
|
|
protected $dui;
|
|
|
|
|
|
|
|
/** @var IConfig */
|
|
|
|
protected $config;
|
|
|
|
|
|
|
|
/** @var IDBConnection */
|
|
|
|
protected $db;
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var UserMapping|\PHPUnit\Framework\MockObject\MockObject */
|
2018-12-17 16:55:00 +03:00
|
|
|
protected $mapping;
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2018-12-17 16:55:00 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
// no mocks for those as tests go against DB
|
|
|
|
$this->config = \OC::$server->getConfig();
|
|
|
|
$this->db = \OC::$server->getDatabaseConnection();
|
|
|
|
|
2019-01-05 00:10:22 +03:00
|
|
|
// ensure a clean database
|
|
|
|
$this->config->deleteAppFromAllUsers('user_ldap');
|
|
|
|
|
2018-12-17 16:55:00 +03:00
|
|
|
$this->mapping = $this->createMock(UserMapping::class);
|
|
|
|
|
|
|
|
$this->dui = new DeletedUsersIndex($this->config, $this->db, $this->mapping);
|
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function tearDown(): void {
|
2018-12-17 16:55:00 +03:00
|
|
|
$this->config->deleteAppFromAllUsers('user_ldap');
|
2019-11-21 18:40:38 +03:00
|
|
|
parent::tearDown();
|
2018-12-17 16:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testMarkAndFetchUser() {
|
|
|
|
$uids = [
|
|
|
|
'cef3775c-71d2-48eb-8984-39a4051b0b95',
|
|
|
|
'8c4bbb40-33ed-42d0-9b14-85b0ab76c1cc',
|
|
|
|
];
|
|
|
|
|
|
|
|
// ensure test works on a pristine state
|
|
|
|
$this->assertFalse($this->dui->hasUsers());
|
|
|
|
|
|
|
|
$this->dui->markUser($uids[0]);
|
|
|
|
|
|
|
|
$this->assertTrue($this->dui->hasUsers());
|
|
|
|
|
|
|
|
$this->dui->markUser($uids[1]);
|
|
|
|
|
|
|
|
$deletedUsers = $this->dui->getUsers();
|
|
|
|
$this->assertSame(2, count($deletedUsers));
|
|
|
|
|
|
|
|
// ensure the different uids were used
|
2020-04-10 15:19:56 +03:00
|
|
|
foreach ($deletedUsers as $deletedUser) {
|
2018-12-17 16:55:00 +03:00
|
|
|
$this->assertTrue(in_array($deletedUser->getOCName(), $uids));
|
|
|
|
$i = array_search($deletedUser->getOCName(), $uids);
|
|
|
|
$this->assertNotFalse($i);
|
|
|
|
unset($uids[$i]);
|
|
|
|
}
|
|
|
|
$this->assertEmpty($uids);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUnmarkUser() {
|
|
|
|
$uids = [
|
|
|
|
'22a162c7-a9ee-487c-9f33-0563795583fb',
|
|
|
|
'1fb4e0da-4a75-47f3-8fa7-becc7e35c9c5',
|
|
|
|
];
|
|
|
|
|
|
|
|
// we know this works, because of "testMarkAndFetchUser"
|
|
|
|
$this->dui->markUser($uids[0]);
|
|
|
|
// this returns a working instance of OfflineUser
|
|
|
|
$testUser = $this->dui->getUsers()[0];
|
|
|
|
$testUser->unmark();
|
|
|
|
|
|
|
|
// the DUI caches the users, to clear mark someone else
|
|
|
|
$this->dui->markUser($uids[1]);
|
|
|
|
|
|
|
|
$deletedUsers = $this->dui->getUsers();
|
|
|
|
foreach ($deletedUsers as $deletedUser) {
|
|
|
|
$this->assertNotSame($testUser->getOCName(), $deletedUser->getOCName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|