public function WeatherCommonTestTrait::weatherGetLinkForGeoId in Weather 8
Same name and namespace in other branches
- 2.0.x tests/src/Functional/WeatherCommonTestTrait.php \Drupal\Tests\weather\Functional\WeatherCommonTestTrait::weatherGetLinkForGeoId()
Construct the link for the given GeoID.
Parameters
string $geoid: The GeoID to construct the link for.
string $destination: Destination to create the link for. Currently supported are 'system-wide', 'default', 'user', 'yr', and 'autocomplete'.
int $number: Optional number of display. Applies only to 'system-wide'.
Return value
string The link for the GeoID.
2 calls to WeatherCommonTestTrait::weatherGetLinkForGeoId()
- FunctionsTest::testFunctionWeatherGetLinkForGeoId in tests/
src/ Functional/ FunctionsTest.php - Test _weather_get_link_for_geoid().
- ParserTest::weatherDownloadForecast in tests/
src/ Functional/ ParserTest.php - Downloads a new forecast from yr.no.
File
- tests/
src/ Functional/ WeatherCommonTestTrait.php, line 187
Class
- WeatherCommonTestTrait
- Provides a helper method for testing Weather module.
Namespace
Drupal\Tests\weather\FunctionalCode
public function weatherGetLinkForGeoId($geoid, $destination, $number = 1) {
$info = $this
->weatherGetInformationAboutGeoid($geoid);
// Conversion rules for all link parts:
// - Replace all spaces with an underscore.
// - If the link part ends with a dot, use an underscore.
$country = str_replace(' ', '_', $info['country']);
if (substr($country, -1) == '.') {
$country[strlen($country) - 1] = '_';
}
$link = $country . '/' . $info['link'];
switch ($destination) {
case 'system-wide':
$link = 'weather/' . $link . '/' . $number;
break;
case 'default':
$link = 'weather/' . $link;
break;
case 'user':
$link = 'weather/' . $link . '/u';
break;
case 'yr':
// Encode special characters except the '/' in the URL.
// Otherwise, the request will fail on yr.no.
$link = rawurlencode($link);
$link = str_replace('%2F', '/', $link);
$link = 'http://www.yr.no/place/' . $link . '/forecast.xml';
break;
case 'yr.no':
$link = 'http://www.yr.no/place/' . $link . '/';
break;
case 'autocomplete':
// Nothing to do here.
break;
}
return $link;
}