diff --git a/src/Redmine/Api/Issue.php b/src/Redmine/Api/Issue.php
index e3dfe3a5..fde13968 100644
--- a/src/Redmine/Api/Issue.php
+++ b/src/Redmine/Api/Issue.php
@@ -393,14 +393,22 @@ private function cleanParams(array $params = [])
if (isset($params['assigned_to'])) {
$userApi = $this->getUserApi();
- $params['assigned_to_id'] = $userApi->getIdByUsername($params['assigned_to']);
+ $params['assigned_to_id'] = array_search(
+ $params['assigned_to'],
+ $userApi->listLogins(),
+ true,
+ );
unset($params['assigned_to']);
}
if (isset($params['author'])) {
$userApi = $this->getUserApi();
- $params['author_id'] = $userApi->getIdByUsername($params['author']);
+ $params['author_id'] = array_search(
+ $params['author'],
+ $userApi->listLogins(),
+ true,
+ );
unset($params['author']);
}
diff --git a/tests/Unit/Api/Issue/CreateTest.php b/tests/Unit/Api/Issue/CreateTest.php
index 04275625..4510d2d3 100644
--- a/tests/Unit/Api/Issue/CreateTest.php
+++ b/tests/Unit/Api/Issue/CreateTest.php
@@ -410,12 +410,12 @@ public function testCreateWithHttpClientRetrievesUserId()
$this,
[
'GET',
- '/users.json',
+ '/users.json?limit=100&offset=0',
'application/json',
'',
200,
'application/json',
- '{"users":[{"login":"Author Name","id":5},{"login":"Assigned to User Name","id":6}]}',
+ '{"users":[{"login":"user_5","id":5},{"login":"user_6","id":6}]}',
],
[
'POST',
@@ -432,7 +432,7 @@ public function testCreateWithHttpClientRetrievesUserId()
$api = new Issue($client);
// Perform the tests
- $xmlElement = $api->create(['assigned_to' => 'Assigned to User Name', 'author' => 'Author Name']);
+ $xmlElement = $api->create(['assigned_to' => 'user_6', 'author' => 'user_5']);
$this->assertInstanceOf(SimpleXMLElement::class, $xmlElement);
$this->assertXmlStringEqualsXmlString(
@@ -486,12 +486,12 @@ public function testCreateWithClientCleansParameters()
],
[
'GET',
- '/users.json',
+ '/users.json?limit=100&offset=0',
'application/json',
'',
200,
'application/json',
- '{"users":[{"login":"Author Name","id":5},{"login":"Assigned to User Name","id":6}]}',
+ '{"users":[{"login":"user_5","id":5},{"login":"user_6","id":6}]}',
],
[
'POST',
@@ -519,8 +519,8 @@ public function testCreateWithClientCleansParameters()
'category' => 'Category Name',
'status' => 'Status Name',
'tracker' => 'Tracker Name',
- 'assigned_to' => 'Assigned to User Name',
- 'author' => 'Author Name',
+ 'assigned_to' => 'user_6',
+ 'author' => 'user_5',
];
// Create the object under test
diff --git a/tests/Unit/Api/Issue/UpdateTest.php b/tests/Unit/Api/Issue/UpdateTest.php
index 3897ad6b..5a2e6da3 100644
--- a/tests/Unit/Api/Issue/UpdateTest.php
+++ b/tests/Unit/Api/Issue/UpdateTest.php
@@ -155,7 +155,7 @@ public function testUpdateCleansParameters()
],
[
'GET',
- '/users.json',
+ '/users.json?limit=100&offset=0',
'application/json',
'',
200,
diff --git a/tests/Unit/Api/IssueTest.php b/tests/Unit/Api/IssueTest.php
index 49b88ac8..b00d8c21 100644
--- a/tests/Unit/Api/IssueTest.php
+++ b/tests/Unit/Api/IssueTest.php
@@ -10,6 +10,7 @@
use Redmine\Api\IssueStatus;
use Redmine\Api\Project;
use Redmine\Api\Tracker;
+use Redmine\Api\User;
use Redmine\Client\Client;
use Redmine\Http\HttpClient;
use Redmine\Http\Response;
@@ -152,16 +153,11 @@ public function testCreateWithClientCleansParameters()
'category' => 'Category 5 Name',
'status' => 'Status 6 Name',
'tracker' => 'Tracker 2 Name',
- 'assigned_to' => 'Assigned to User Name',
- 'author' => 'Author Name',
+ 'assigned_to' => 'user_3',
+ 'author' => 'user_4',
];
// Create the used mock objects
- $getIdByUsernameApi = $this->createMock('Redmine\Api\User');
- $getIdByUsernameApi->expects($this->exactly(2))
- ->method('getIdByUsername')
- ->willReturn('cleanedValue');
-
$httpClient = AssertingHttpClient::create(
$this,
[
@@ -200,6 +196,15 @@ public function testCreateWithClientCleansParameters()
'application/json',
'{"trackers":[{"id":2,"name":"Tracker 2 Name"}]}',
],
+ [
+ 'GET',
+ '/users.json?limit=100&offset=0',
+ 'application/json',
+ '',
+ 200,
+ 'application/json',
+ '{"users":[{"id":3,"login":"user_3"},{"id":4,"login":"user_4"}]}',
+ ],
);
$client = $this->createMock(Client::class);
@@ -211,7 +216,7 @@ public function testCreateWithClientCleansParameters()
['issue_category', new IssueCategory($httpClient)],
['issue_status', new IssueStatus($httpClient)],
['tracker', new Tracker($httpClient)],
- ['user', $getIdByUsernameApi],
+ ['user', new User($httpClient)],
],
)
;
@@ -222,7 +227,7 @@ public function testCreateWithClientCleansParameters()
'/issues.xml',
<<< XML
- 1562cleanedValuecleanedValue
+ 156234
XML,
)