Skip to content

Conversation

@m0ark
Copy link
Contributor

@m0ark m0ark commented Nov 25, 2019

Preferred language selection is broken in discovery service. Currently it uses the last valid translation instead of the first valid.

Copy link
Member

@tvdijen tvdijen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be a bit more specific in a nested loop, this should preferably be break 1;

BTW, this screams to be unit tested.. If we can extract the foreach and usort into a separate method, we could perfectly test the alphabetical order and language preference.

@codecov

This comment has been minimized.

@tvdijen tvdijen force-pushed the fix-disco-language branch 2 times, most recently from 7c597df to 8b733bc Compare November 25, 2019 21:35
@tvdijen
Copy link
Member

tvdijen commented Nov 25, 2019

I think I've made a good start here, but I'm not really good with unit tests, so it would be great if someone can pick up from here

* @param array $idpList
* @return array
*/
private function getPreferredTranslations(array $idpList, array $tryLanguages): array
Copy link
Member

@jaimeperez jaimeperez Nov 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is quite misleading. What this method is doing is returning a list of IdPs, sorted by name, where their names are translated based on the preferred translation for the given request. I don't think getPreferredTranslations() correctly describes that, but instead it sounds like it's just returning the preferred translations for some given IdPs.

I would actually suggest refactoring this code. There's a lot of repetition in there, and testing is quite hard, so we could benefit from routing to feed requests and get responses out of it.

I'm going to merge @m0ark's commit into 1.18, and we can keep working on this meanwhile.

@jaimeperez
Copy link
Member

I agree with Tim here. We should do this properly and add unit tests. However, it's quite difficult to get some tests working, so I've prioritized getting the fix into a stable release (1.18.1, out just now), and then I'm leaving this PR open as a reminder that we need to get back to this.

@tvdijen tvdijen added this to the 2.0 milestone Dec 31, 2019
@tvdijen tvdijen force-pushed the master branch 3 times, most recently from 1c686ab to eb20457 Compare August 17, 2020 20:43
@tvdijen tvdijen force-pushed the master branch 2 times, most recently from 08ebb9c to 64fca25 Compare July 2, 2021 14:12
@thijskh
Copy link
Member

thijskh commented Sep 4, 2021

Fixed in #1512.

@thijskh thijskh closed this Sep 4, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants