/** * @inheritDoc */ public function negotiateAll(array $clientPrefList, array $serverPrefList, $fromField) { $emptyPref = $this->getBuilder($fromField)->setFromField($fromField)->get(); $sort = new MatchedPreferenceSort(); $matchingList = array(); foreach ($serverPrefList as $serverPref) { $matchingList[] = new MatchedPreference($fromField, $emptyPref, $serverPref); } $matchingList = $this->matchClientPreferences($fromField, $clientPrefList, $matchingList); return $sort->sortDescending($matchingList); }
public function testGetDescending() { $typePairList = array(); $typePairList[] = new MatchedPreference(Preference::LANGUAGE, new Preference('en-gb', 0.8, Preference::COMPLETE), new Preference('en-gb', 0.9, Preference::COMPLETE)); $typePairList[] = new MatchedPreference(Preference::LANGUAGE, new Preference('fr', 0.9, Preference::COMPLETE), new Preference('fr', 0.8, Preference::COMPLETE)); $sort = new MatchedPreferenceSort(); $newCollection = $sort->sortDescending($typePairList); $expectServerType = array('fr;q=0.8', 'en-gb;q=0.9'); $expectClientType = array('fr;q=0.9', 'en-gb;q=0.8'); $i = 0; foreach ($newCollection as $typePair) { $this->assertSame($expectServerType[$i], $typePair->getServerPreference()->__toString()); $this->assertSame($expectClientType[$i], $typePair->getClientPreference()->__toString()); $i++; } }