diff --git a/Makefile b/Makefile index 54930c6b6..8d428a7d3 100644 --- a/Makefile +++ b/Makefile @@ -50,8 +50,7 @@ ifeq (, $(shell which phpunit 2> /dev/null)) php $(build_tools_directory)/phpunit.phar -c tests/phpunit.xml --coverage-clover build/php-unit.coverage.xml php $(build_tools_directory)/phpunit.phar -c tests/phpunit.integration.xml --coverage-clover build/php-integration.coverage.xml else - phpunit -c tests/phpunit.xml --coverage-clover build/php-unit.coverage.xml - phpunit -c tests/phpunit.integration.xml --coverage-clover build/php-integration.coverage.xml + phpunit -c tests/phpunit.integration.xml --testsuite=integration-database --coverage-clover build/php-integration.coverage.xml endif test-integration: diff --git a/lib/Db/AssignmentMapper.php b/lib/Db/AssignmentMapper.php index 7a7f368ae..5bc49e40d 100644 --- a/lib/Db/AssignmentMapper.php +++ b/lib/Db/AssignmentMapper.php @@ -155,9 +155,10 @@ class AssignmentMapper extends QBMapper implements IPermissionMapper { public function transferOwnership($ownerId, $newOwnerId) { $params = [ 'owner' => $ownerId, - 'newOwner' => $newOwnerId + 'newOwner' => $newOwnerId, + 'type' => AssignedUsers::TYPE_USER ]; - $sql = "UPDATE `{$this->tableName}` SET `participant` = :newOwner WHERE `participant` = :owner"; + $sql = "UPDATE `{$this->tableName}` SET `participant` = :newOwner WHERE `participant` = :owner AND `type`= :type"; $stmt = $this->execute($sql, $params); $stmt->closeCursor(); } diff --git a/tests/integration/config/behat.yml b/tests/integration/config/behat.yml index b8673a677..507138122 100644 --- a/tests/integration/config/behat.yml +++ b/tests/integration/config/behat.yml @@ -5,7 +5,7 @@ default: - '%paths.base%/../features/' contexts: - ServerContext: - baseUrl: http://localhost:8080/ + baseUrl: http://localhost:9090/ - RequestContext - BoardContext - CommentContext diff --git a/tests/integration/database/TransferOwnershipTest.php b/tests/integration/database/TransferOwnershipTest.php index e49e409b4..aff664640 100644 --- a/tests/integration/database/TransferOwnershipTest.php +++ b/tests/integration/database/TransferOwnershipTest.php @@ -13,6 +13,8 @@ use OCA\Deck\Db\Board; class TransferOwnershipTest extends \Test\TestCase { private const TEST_OWNER = 'test-share-user1'; private const TEST_NEW_OWNER = 'target'; + private const TEST_NEW_OWNER_PARTICIPANT = 'target-participant'; + private const TEST_NEW_OWNER_IN_ACL = 'target-in-acl'; private const TEST_GROUP = 'test-share-user1'; /** @var BoardService */ @@ -38,6 +40,7 @@ class TransferOwnershipTest extends \Test\TestCase { \OC::$server->getUserManager()->registerBackend($backend); $backend->createUser(self::TEST_OWNER, self::TEST_OWNER); $backend->createUser(self::TEST_NEW_OWNER, self::TEST_NEW_OWNER); + $backend->createUser(self::TEST_NEW_OWNER_PARTICIPANT, self::TEST_NEW_OWNER_PARTICIPANT); // create group $groupBackend = new \Test\Util\Group\Dummy(); $groupBackend->createGroup(self::TEST_GROUP); @@ -68,6 +71,7 @@ class TransferOwnershipTest extends \Test\TestCase { $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->assignmentService->assignUser($cards[0]->getId(), self::TEST_NEW_OWNER_PARTICIPANT); $this->board = $board; $this->cards = $cards; $this->stacks = $stacks; @@ -137,7 +141,22 @@ class TransferOwnershipTest extends \Test\TestCase { */ public function testReassignCardToNewParticipantOnlyIfParticipantHasUserType() { $this->boardService->transferOwnership(self::TEST_OWNER, self::TEST_NEW_OWNER); - $this->assignmentService->ass($cards[0]->getId(), self::TEST_OWNER); + $this->assignmentService->ass($this->cards[0]->getId(), self::TEST_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 testTargetAlreadyParticipantOfTransferedCard() { + $this->boardService->transferOwnership(self::TEST_OWNER, self::TEST_NEW_OWNER_PARTICIPANT); + $this->assignmentService->assignUser($this->cards[0]->getId(), self::TEST_OWNER); $assignedUsers = $this->assignedUsersMapper->find($this->cards[0]->getId()); $participantsUIDs = []; foreach ($assignedUsers as $user) { diff --git a/tests/integration/run.sh b/tests/integration/run.sh index ab9790b26..de8b32563 100755 --- a/tests/integration/run.sh +++ b/tests/integration/run.sh @@ -26,7 +26,7 @@ composer dump-autoload if [ -z "$EXECUTOR_NUMBER" ]; then EXECUTOR_NUMBER=0 fi -PORT=$((8080 + $EXECUTOR_NUMBER)) +PORT=$((9090 + $EXECUTOR_NUMBER)) echo $PORT php -S localhost:$PORT -t $OC_PATH & PHPPID=$! diff --git a/tests/unit/Service/BoardServiceTest.php b/tests/unit/Service/BoardServiceTest.php index e59662489..c64422ff5 100644 --- a/tests/unit/Service/BoardServiceTest.php +++ b/tests/unit/Service/BoardServiceTest.php @@ -31,6 +31,7 @@ use OCA\Deck\Db\Assignment; use OCA\Deck\Db\AssignmentMapper; use OCA\Deck\Db\Board; use OCA\Deck\Db\BoardMapper; +use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\ChangeHelper; use OCA\Deck\Db\LabelMapper; use OCA\Deck\Db\StackMapper; @@ -58,6 +59,8 @@ class BoardServiceTest extends TestCase { private $boardMapper; /** @var StackMapper */ private $stackMapper; + /** @var CardMapper */ + private $cardMapper; /** @var PermissionService */ private $permissionService; /** @var NotificationHelper */ @@ -85,6 +88,7 @@ class BoardServiceTest extends TestCase { $this->boardMapper = $this->createMock(BoardMapper::class); $this->stackMapper = $this->createMock(StackMapper::class); $this->config = $this->createMock(IConfig::class); + $this->cardMapper = $this->createMock(CardMapper::class); $this->labelMapper = $this->createMock(LabelMapper::class); $this->permissionService = $this->createMock(PermissionService::class); $this->notificationHelper = $this->createMock(NotificationHelper::class); @@ -106,6 +110,7 @@ class BoardServiceTest extends TestCase { $this->permissionService, $this->notificationHelper, $this->assignedUsersMapper, + $this->cardMapper, $this->userManager, $this->groupManager, $this->activityManager,