2018-11-07 18:22:15 -05:00
|
|
|
<?php
|
2020-02-09 09:45:36 -05:00
|
|
|
/**
|
2022-01-02 02:27:47 -05:00
|
|
|
* @copyright Copyright (C) 2010-2022, the Friendica project
|
2020-02-09 09:45:36 -05: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
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2018-11-07 18:22:15 -05:00
|
|
|
|
2019-02-27 06:32:56 -05:00
|
|
|
namespace Friendica\Test\src\Model;
|
2018-11-07 18:22:15 -05:00
|
|
|
|
2021-10-18 14:08:40 -04:00
|
|
|
use Dice\Dice;
|
|
|
|
use Friendica\Database\Database;
|
|
|
|
use Friendica\DI;
|
2018-11-07 18:22:15 -05:00
|
|
|
use Friendica\Model\User;
|
|
|
|
use Friendica\Test\MockedTest;
|
2021-10-18 14:08:40 -04:00
|
|
|
use Mockery\MockInterface;
|
2018-11-07 18:22:15 -05:00
|
|
|
|
|
|
|
class UserTest extends MockedTest
|
|
|
|
{
|
|
|
|
private $parent;
|
|
|
|
private $child;
|
|
|
|
private $manage;
|
|
|
|
|
2021-10-18 14:08:40 -04:00
|
|
|
/** @var Database|MockInterface */
|
|
|
|
private $dbMock;
|
|
|
|
|
2021-04-01 17:04:30 -04:00
|
|
|
protected function setUp(): void
|
2018-11-07 18:22:15 -05:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2021-10-18 14:08:40 -04:00
|
|
|
$this->dbMock = \Mockery::mock(Database::class);
|
|
|
|
|
|
|
|
$diceMock = \Mockery::mock(Dice::class)->makePartial();
|
|
|
|
/** @var Dice|MockInterface $diceMock */
|
|
|
|
$diceMock = $diceMock->addRules(include __DIR__ . '/../../../static/dependencies.config.php');
|
|
|
|
$diceMock->shouldReceive('create')->withArgs([Database::class])->andReturn($this->dbMock);
|
|
|
|
DI::init($diceMock);
|
|
|
|
|
2018-11-07 18:22:15 -05:00
|
|
|
$this->parent = [
|
2021-10-18 14:08:40 -04:00
|
|
|
'uid' => 1,
|
|
|
|
'username' => 'maxmuster',
|
|
|
|
'nickname' => 'Max Muster'
|
2018-11-07 18:22:15 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
$this->child = [
|
2021-10-18 14:08:40 -04:00
|
|
|
'uid' => 2,
|
|
|
|
'username' => 'johndoe',
|
|
|
|
'nickname' => 'John Doe'
|
2018-11-07 18:22:15 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
$this->manage = [
|
2021-10-18 14:08:40 -04:00
|
|
|
'uid' => 3,
|
|
|
|
'username' => 'janesmith',
|
|
|
|
'nickname' => 'Jane Smith'
|
2018-11-07 18:22:15 -05:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIdentitiesEmpty()
|
|
|
|
{
|
2021-10-18 14:08:40 -04:00
|
|
|
$this->dbMock->shouldReceive('selectFirst')->with('user',
|
|
|
|
['uid', 'nickname', 'username', 'parent-uid'],['uid' => $this->parent['uid']], [])->andReturn($this->parent)->once();
|
|
|
|
$this->dbMock->shouldReceive('isResult')->with($this->parent)->andReturn(false)->once();
|
2018-11-07 18:22:15 -05:00
|
|
|
|
|
|
|
$record = User::identities($this->parent['uid']);
|
|
|
|
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertEquals([], $record);
|
2018-11-07 18:22:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIdentitiesAsParent()
|
|
|
|
{
|
2021-10-18 14:08:40 -04:00
|
|
|
$parentSelect = $this->parent;
|
2018-11-07 18:22:15 -05:00
|
|
|
$parentSelect['parent-uid'] = 0;
|
|
|
|
|
|
|
|
// Select the user itself (=parent)
|
2021-10-18 14:08:40 -04:00
|
|
|
$this->dbMock->shouldReceive('selectFirst')->with('user',
|
|
|
|
['uid', 'nickname', 'username', 'parent-uid'],['uid' => $this->parent['uid']], [])->andReturn($parentSelect)->once();
|
|
|
|
$this->dbMock->shouldReceive('isResult')->with($parentSelect)->andReturn(true)->once();
|
2018-11-07 18:22:15 -05:00
|
|
|
|
|
|
|
// Select one child
|
2021-10-18 14:08:40 -04:00
|
|
|
$this->dbMock->shouldReceive('select')->with('user',
|
2018-11-07 18:22:15 -05:00
|
|
|
['uid', 'username', 'nickname'],
|
|
|
|
[
|
2021-10-18 14:08:40 -04:00
|
|
|
'parent-uid' => $this->parent['uid'],
|
2018-11-07 18:22:15 -05:00
|
|
|
'account_removed' => false
|
2021-10-18 14:08:40 -04:00
|
|
|
], [])->andReturn('objectReturn')->once();
|
|
|
|
$this->dbMock->shouldReceive('isResult')->with('objectReturn')->andReturn(true)->once();
|
|
|
|
$this->dbMock->shouldReceive('toArray')->with('objectReturn', true, 0)->andReturn([$this->child])->once();
|
2018-11-07 18:22:15 -05:00
|
|
|
|
|
|
|
// Select the manage
|
2021-10-18 14:08:40 -04:00
|
|
|
$this->dbMock->shouldReceive('p')->withAnyArgs()->andReturn('objectTwo')->once();
|
|
|
|
$this->dbMock->shouldReceive('isResult')->with('objectTwo')->andReturn(true)->once();
|
|
|
|
$this->dbMock->shouldReceive('toArray')->with('objectTwo', true, 0)->andReturn([$this->manage])->once();
|
2018-11-07 18:22:15 -05:00
|
|
|
|
|
|
|
$record = User::identities($this->parent['uid']);
|
|
|
|
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertEquals([
|
2018-11-07 18:22:15 -05:00
|
|
|
$this->parent,
|
|
|
|
$this->child,
|
|
|
|
$this->manage
|
|
|
|
], $record);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIdentitiesAsChild()
|
|
|
|
{
|
2021-10-18 14:08:40 -04:00
|
|
|
$childSelect = $this->child;
|
2018-11-07 18:22:15 -05:00
|
|
|
$childSelect['parent-uid'] = $this->parent['uid'];
|
|
|
|
|
|
|
|
// Select the user itself (=child)
|
2021-10-18 14:08:40 -04:00
|
|
|
$this->dbMock->shouldReceive('selectFirst')->with('user',
|
|
|
|
['uid', 'nickname', 'username', 'parent-uid'],['uid' => $this->child['uid']], [])->andReturn($childSelect)->once();
|
|
|
|
$this->dbMock->shouldReceive('isResult')->with($childSelect)->andReturn(true)->once();
|
2018-11-07 18:22:15 -05:00
|
|
|
|
|
|
|
// Select the parent
|
2021-10-18 14:08:40 -04:00
|
|
|
$this->dbMock->shouldReceive('select')->with('user',
|
2018-11-07 18:22:15 -05:00
|
|
|
['uid', 'username', 'nickname'],
|
|
|
|
[
|
2021-10-18 14:08:40 -04:00
|
|
|
'uid' => $this->parent['uid'],
|
2018-11-07 18:22:15 -05:00
|
|
|
'account_removed' => false
|
2021-10-18 14:08:40 -04:00
|
|
|
], [])->andReturn('objectReturn')->once();
|
|
|
|
$this->dbMock->shouldReceive('isResult')->with('objectReturn')->andReturn(true)->once();
|
|
|
|
$this->dbMock->shouldReceive('toArray')->with('objectReturn', true, 0)->andReturn([$this->parent])->once();
|
2018-11-07 18:22:15 -05:00
|
|
|
|
|
|
|
// Select the childs (user & manage)
|
2021-10-18 14:08:40 -04:00
|
|
|
$this->dbMock->shouldReceive('select')->with('user',
|
2018-11-07 18:22:15 -05:00
|
|
|
['uid', 'username', 'nickname'],
|
|
|
|
[
|
2021-10-18 14:08:40 -04:00
|
|
|
'parent-uid' => $this->parent['uid'],
|
2018-11-07 18:22:15 -05:00
|
|
|
'account_removed' => false
|
2021-10-18 14:08:40 -04:00
|
|
|
], [])->andReturn('objectReturn')->once();
|
|
|
|
$this->dbMock->shouldReceive('isResult')->with('objectReturn')->andReturn(true)->once();
|
|
|
|
$this->dbMock->shouldReceive('toArray')->with('objectReturn', true, 0)->andReturn([$this->child, $this->manage])->once();
|
2018-11-07 18:22:15 -05:00
|
|
|
|
|
|
|
// Select the manage
|
2021-10-18 14:08:40 -04:00
|
|
|
$this->dbMock->shouldReceive('p')->withAnyArgs()->andReturn('objectTwo')->once();
|
|
|
|
$this->dbMock->shouldReceive('isResult')->with('objectTwo')->andReturn(false)->once();
|
2018-11-07 18:22:15 -05:00
|
|
|
|
|
|
|
$record = User::identities($this->child['uid']);
|
|
|
|
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertEquals([
|
2018-11-07 18:22:15 -05:00
|
|
|
$this->parent,
|
|
|
|
$this->child,
|
|
|
|
$this->manage
|
|
|
|
], $record);
|
|
|
|
}
|
|
|
|
}
|