Skip to content

Commit

Permalink
Fix code style
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey Shliakhov <husband.sergey@gmail.com>
  • Loading branch information
matchish committed Jun 8, 2020
1 parent 3b6b5ee commit d8ceb8c
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 96 deletions.
5 changes: 1 addition & 4 deletions lib/Command/TransferOwnership.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
use Symfony\Component\Console\Output\OutputInterface;

final class TransferOwnership extends Command {

protected $boardService;

public function __construct(BoardService $boardService)
{
public function __construct(BoardService $boardService) {
parent::__construct();

$this->boardService = $boardService;
Expand Down Expand Up @@ -45,5 +43,4 @@ protected function execute(InputInterface $input, OutputInterface $output) {

$output->writeln("Transfer deck entities from $owner to $newOwner completed");
}

}
3 changes: 1 addition & 2 deletions lib/Db/AclMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ public function findByParticipant($type, $participant) {
* @param $newOwnerId
* @return void
*/
public function transferOwnership($ownerId, $newOwnerId)
{
public function transferOwnership($ownerId, $newOwnerId) {
$params = [
'owner' => $ownerId,
'newOwner' => $newOwnerId,
Expand Down
3 changes: 1 addition & 2 deletions lib/Db/AssignedUsersMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ private function getOrigin(AssignedUsers $assignment) {
* @param $newOwnerId
* @return void
*/
public function transferOwnership($ownerId, $newOwnerId)
{
public function transferOwnership($ownerId, $newOwnerId) {
$params = [
'owner' => $ownerId,
'newOwner' => $newOwnerId
Expand Down
29 changes: 14 additions & 15 deletions lib/Db/BoardMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,19 +262,18 @@ public function mapOwner(Board &$board) {
});
}

/**
* @param $ownerId
* @param $newOwnerId
* @return void
*/
public function transferOwnership($ownerId, $newOwnerId)
{
$params = [
'owner' => $ownerId,
'newOwner' => $newOwnerId
];
$sql = "UPDATE `{$this->tableName}` SET `owner` = :newOwner WHERE `owner` = :owner";
$stmt = $this->execute($sql, $params);
$stmt->closeCursor();
}
/**
* @param $ownerId
* @param $newOwnerId
* @return void
*/
public function transferOwnership($ownerId, $newOwnerId) {
$params = [
'owner' => $ownerId,
'newOwner' => $newOwnerId
];
$sql = "UPDATE `{$this->tableName}` SET `owner` = :newOwner WHERE `owner` = :owner";
$stmt = $this->execute($sql, $params);
$stmt->closeCursor();
}
}
3 changes: 1 addition & 2 deletions lib/Db/CardMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ public function mapOwner(Card &$card) {
* @param $newOwnerId
* @return void
*/
public function transferOwnership($ownerId, $newOwnerId)
{
public function transferOwnership($ownerId, $newOwnerId) {
$params = [
'owner' => $ownerId,
'newOwner' => $newOwnerId
Expand Down
3 changes: 1 addition & 2 deletions lib/Service/BoardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,7 @@ public function clone($id, $userId) {
* @param $newOwnerId
* @return void
*/
public function transferOwnership($owner, $newOwner)
{
public function transferOwnership($owner, $newOwner) {
$this->boardMapper->transferOwnership($owner, $newOwner);
$this->assignedUsersMapper->transferOwnership($owner, $newOwner);
$this->aclMapper->transferOwnership($owner, $newOwner);
Expand Down
133 changes: 64 additions & 69 deletions tests/integration/database/TransferOwnershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class AssignedUsersMapperTest extends \Test\TestCase {
protected $assignedUsersMapper;
/** @var AssignmentService */
private $assignmentService;
/** @var Board */
private $board;
private $cards;
private $stacks;
/** @var Board */
private $board;
private $cards;
private $stacks;

public static function setUpBeforeClass(): void {
public static function setUpBeforeClass(): void {
parent::setUpBeforeClass();

$backend = new \Test\Util\User\Dummy();
Expand Down Expand Up @@ -60,82 +60,77 @@ public function createBoardWithExampleData() {
$stacks = [];
$board = $this->boardService->create('Test', self::TEST_OWNER, '000000');
$id = $board->getId();
$this->boardService->addAcl($id, Acl::PERMISSION_TYPE_USER, self::TEST_OWNER, true, true, true);
$this->boardService->addAcl($id, Acl::PERMISSION_TYPE_GROUP, self::TEST_GROUP, true, true, true);
$this->boardService->addAcl($id, Acl::PERMISSION_TYPE_USER, self::TEST_OWNER, true, true, true);
$this->boardService->addAcl($id, Acl::PERMISSION_TYPE_GROUP, self::TEST_GROUP, true, true, true);
$stacks[] = $this->stackService->create('Stack A', $id, 1);
$stacks[] = $this->stackService->create('Stack B', $id, 1);
$stacks[] = $this->stackService->create('Stack C', $id, 1);
$cards[] = $this->cardService->create('Card 1', $stacks[0]->getId(), 'text', 0, self::TEST_OWNER);
$cards[] = $this->cardService->create('Card 2', $stacks[0]->getId(), 'text', 0, self::TEST_OWNER);
$this->assignmentService->assignUser($cards[0]->getId(), self::TEST_OWNER);
$this->board = $board;
$this->assignmentService->assignUser($cards[0]->getId(), self::TEST_OWNER);
$this->board = $board;
$this->cards = $cards;
$this->stacks = $stacks;
}

/**
* @covers ::transferOwnership
*/
public function testTransferBoardOwnership()
{
$this->boardService->transferOwnership(self::TEST_OWNER, self::TEST_NEW_OWNER);
$board = $this->boardService->find($this->board->getId());
$boardOwner = $board->getOwner();
$this->assertEquals(self::TEST_NEW_OWNER, $boardOwner);
}
/**
* @covers ::transferOwnership
*/
public function testTransferBoardOwnership() {
$this->boardService->transferOwnership(self::TEST_OWNER, self::TEST_NEW_OWNER);
$board = $this->boardService->find($this->board->getId());
$boardOwner = $board->getOwner();
$this->assertEquals(self::TEST_NEW_OWNER, $boardOwner);
}

/**
* @covers ::transferOwnership
*/
public function testTransferACLOwnership()
{
$this->boardService->transferOwnership(self::TEST_OWNER, self::TEST_NEW_OWNER);
$board = $this->boardService->find($this->board->getId());
$acl = $board->getAcl();
$isTargetInAcl = (bool)array_filter($acl, function ($item) {
return $item->getParticipant() === self::TEST_NEW_OWNER && $item->getType() === Acl::PERMISSION_TYPE_USER;
});
$this->assertTrue($isTargetInAcl);
}
/**
* @covers ::transferOwnership
*/
public function testTransferACLOwnership() {
$this->boardService->transferOwnership(self::TEST_OWNER, self::TEST_NEW_OWNER);
$board = $this->boardService->find($this->board->getId());
$acl = $board->getAcl();
$isTargetInAcl = (bool)array_filter($acl, function ($item) {
return $item->getParticipant() === self::TEST_NEW_OWNER && $item->getType() === Acl::PERMISSION_TYPE_USER;
});
$this->assertTrue($isTargetInAcl);
}

/**
* @covers ::transferOwnership
*/
public function testNoTransferAclOwnershipIfGroupType()
{
$this->boardService->transferOwnership(self::TEST_OWNER, self::TEST_NEW_OWNER);
$board = $this->boardService->find($this->board->getId());
$acl = $board->getAcl();
$isGroupInAcl = (bool)array_filter($acl, function ($item) {
return $item->getParticipant() === self::TEST_GROUP && $item->getType() === Acl::PERMISSION_TYPE_GROUP;
});
$this->assertTrue($isGroupInAcl);
}
/**
* @covers ::transferOwnership
*/
public function testTransferCardOwnership()
{
$this->boardService->transferOwnership(self::TEST_OWNER, self::TEST_NEW_OWNER);
$card = $this->cardService->find($this->cards[0]->getId());
$cardOwner = $card->getOwner();
$this->assertEquals(self::TEST_NEW_OWNER, $cardOwner);
}
/**
* @covers ::transferOwnership
*/
public function testNoTransferAclOwnershipIfGroupType() {
$this->boardService->transferOwnership(self::TEST_OWNER, self::TEST_NEW_OWNER);
$board = $this->boardService->find($this->board->getId());
$acl = $board->getAcl();
$isGroupInAcl = (bool)array_filter($acl, function ($item) {
return $item->getParticipant() === self::TEST_GROUP && $item->getType() === Acl::PERMISSION_TYPE_GROUP;
});
$this->assertTrue($isGroupInAcl);
}
/**
* @covers ::transferOwnership
*/
public function testTransferCardOwnership() {
$this->boardService->transferOwnership(self::TEST_OWNER, self::TEST_NEW_OWNER);
$card = $this->cardService->find($this->cards[0]->getId());
$cardOwner = $card->getOwner();
$this->assertEquals(self::TEST_NEW_OWNER, $cardOwner);
}

/**
* @covers ::transferOwnership
*/
public function testReassignCardToNewOwner()
{
$this->boardService->transferOwnership(self::TEST_OWNER, self::TEST_NEW_OWNER);
$assignedUsers = $this->assignedUsersMapper->find($this->cards[0]->getId());
$participantsUIDs = [];
foreach ($assignedUsers as $user) {
$participantsUIDs[] = $user->getParticipant();
}
$this->assertContains(self::TEST_NEW_OWNER, $participantsUIDs);
$this->assertNotContains(self::TEST_OWNER, $participantsUIDs);
}
/**
* @covers ::transferOwnership
*/
public function testReassignCardToNewOwner() {
$this->boardService->transferOwnership(self::TEST_OWNER, self::TEST_NEW_OWNER);
$assignedUsers = $this->assignedUsersMapper->find($this->cards[0]->getId());
$participantsUIDs = [];
foreach ($assignedUsers as $user) {
$participantsUIDs[] = $user->getParticipant();
}
$this->assertContains(self::TEST_NEW_OWNER, $participantsUIDs);
$this->assertNotContains(self::TEST_OWNER, $participantsUIDs);
}

public function tearDown(): void {
$this->boardService->deleteForce($this->board->getId());
Expand Down

0 comments on commit d8ceb8c

Please sign in to comment.