-
Notifications
You must be signed in to change notification settings - Fork 698
fix preferred translation #1244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d27a03c
fix preffered translation
6ab70b7
Reduce complexity; cut method in two so the business end can be unit …
tvdijen 8f641a9
WIP: unit test
tvdijen 9ec6029
Merge branch 'master' into fix-disco-language
tvdijen 549a538
Fix signatures
tvdijen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| <?php | ||
|
|
||
| namespace SimpleSAML\Test; | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
| use SimpleSAML\Configuration; | ||
| use SimpleSAML\Metadata\MetaDataStorageHandler; | ||
| use SimpleSAML\XHTML\IdPDisco; | ||
|
|
||
| /** | ||
| * Tests for the IdPDisco class. | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE file that was | ||
| * distributed with this source code. | ||
| * | ||
| * @author Tim van Dijen <tvdijen@gmail.com> | ||
| * @package simplesamlphp/simplesamlphp | ||
| */ | ||
| class IdPDiscoTest extends TestCase | ||
| { | ||
| /** @var \SimpleSAML\Metadata\MetaDataStorageHandler */ | ||
| private $mhandler; | ||
|
|
||
| /** @var array */ | ||
| private $config = [ | ||
| 'language' => [ | ||
| 'priorities' => [ | ||
| 'nl' => ['nl', 'en', 'de'], | ||
| 'es' => ['es', 'fr', 'cz'], | ||
| ], | ||
| ], | ||
| 'language.default' => 'nl', | ||
|
|
||
| 'metadata.sources' => [ | ||
| [ | ||
| 'type' => 'xml', | ||
| 'file' => 'vendor/simplesamlphp/simplesamlphp-test-framework/metadata/xml/unsigned-metadata.xml' | ||
| ] | ||
| ], | ||
| ]; | ||
|
|
||
|
|
||
| /** | ||
| * @return void | ||
| */ | ||
| public function setUp(): void | ||
| { | ||
| $config = Configuration::loadFromArray($this->config); | ||
|
|
||
| Configuration::setPreloadedConfig($config, 'config.php'); | ||
|
|
||
| $this->mhandler = MetaDataStorageHandler::getMetadataHandler(); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| */ | ||
| public function testPreferredTranslation(): void | ||
| { | ||
| $disco = new IdPDisco(['saml20-idp-remote'], 'unittest'); | ||
|
|
||
| $reflection = new \ReflectionClass(get_class($disco)); | ||
| $method = $reflection->getMethod('getPreferredTranslations'); | ||
| $method->setAccessible(true); | ||
|
|
||
| $idpList = $method->invokeArgs($disco, $idpList); | ||
|
|
||
| // Assert that result comes with the right translation based on default languages and available translations | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| */ | ||
| public function testIdPSortingOrder(): void | ||
| { | ||
| $disco = new IdPDisco(['saml20-idp-remote'], 'unittest'); | ||
|
|
||
| $reflection = new \ReflectionClass(get_class($disco)); | ||
| $method = $reflection->getMethod('getPreferredTranslations'); | ||
| $method->setAccessible(true); | ||
|
|
||
| $idpList = $method->invokeArgs($disco, $idpList); | ||
|
|
||
| // Assert that result comes alphabetically ordered, whatever language or translation is used | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.