Skip to content

Commit 7d262d6

Browse files
authored
Merge pull request #309 from Art4/fix-308
Allow unassign user from an issue
2 parents a88dbd3 + cd1f555 commit 7d262d6

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased](https://github.com/kbsali/php-redmine-api/compare/v2.1.1...v2.x)
99

10+
### Fixed
11+
12+
- Allow unassign user from an issue
13+
1014
## [v2.1.1](https://github.com/kbsali/php-redmine-api/compare/v2.1.0...v2.1.1) - 2022-01-15
1115

1216
### Fixed

src/Redmine/Api/Issue.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,14 @@ public function update($id, array $params)
160160
'due_date' => null,
161161
];
162162
$params = $this->cleanParams($params);
163-
$params = $this->sanitizeParams($defaults, $params);
163+
$sanitizedParams = $this->sanitizeParams($defaults, $params);
164164

165-
$xml = $this->buildXML($params);
165+
// Allow assigned_to_id to be `` (empty string) to unassign a user from an issue
166+
if (array_key_exists('assigned_to_id', $params) && $params['assigned_to_id'] === '') {
167+
$sanitizedParams['assigned_to_id'] = '';
168+
}
169+
170+
$xml = $this->buildXML($sanitizedParams);
166171

167172
return $this->put('/issues/'.$id.'.xml', $xml->asXML());
168173
}

tests/Unit/Api/IssueTest.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,4 +887,70 @@ public function testBuildXmlWithWatcherAndUploadAndCustomFieldAndStandard()
887887
// Perform the tests
888888
$api->create($parameters);
889889
}
890+
891+
/**
892+
* Test assign an user to an issue
893+
*
894+
* @test
895+
*/
896+
public function testAssignUserToAnIssue()
897+
{
898+
// Test values
899+
$parameters = [
900+
'assigned_to_id' => 5,
901+
];
902+
903+
// Create the used mock objects
904+
$client = $this->createMock(Client::class);
905+
$client->expects($this->once())
906+
->method('requestPut')
907+
->with(
908+
'/issues/5.xml',
909+
$this->logicalAnd(
910+
$this->stringStartsWith('<?xml version="1.0"?>'."\n".'<issue>'),
911+
$this->stringContains('<assigned_to_id>5</assigned_to_id>'),
912+
$this->stringEndsWith('</issue>'."\n"),
913+
914+
)
915+
);
916+
917+
// Create the object under test
918+
$api = new Issue($client);
919+
920+
// Perform the tests
921+
$api->update(5, $parameters);
922+
}
923+
924+
/**
925+
* Test unassign an user from an issue
926+
*
927+
* @test
928+
*/
929+
public function testUnassignUserFromAnIssue()
930+
{
931+
// Test values
932+
$parameters = [
933+
'assigned_to_id' => "",
934+
];
935+
936+
// Create the used mock objects
937+
$client = $this->createMock(Client::class);
938+
$client->expects($this->once())
939+
->method('requestPut')
940+
->with(
941+
'/issues/5.xml',
942+
$this->logicalAnd(
943+
$this->stringStartsWith('<?xml version="1.0"?>'."\n".'<issue>'),
944+
$this->stringContains('<assigned_to_id></assigned_to_id>'),
945+
$this->stringEndsWith('</issue>'."\n"),
946+
947+
)
948+
);
949+
950+
// Create the object under test
951+
$api = new Issue($client);
952+
953+
// Perform the tests
954+
$api->update(5, $parameters);
955+
}
890956
}

0 commit comments

Comments
 (0)