Skip to content

Commit

Permalink
Tests for create URLs with multiple domain rules. (#13351)
Browse files Browse the repository at this point in the history
  • Loading branch information
rob006 authored and samdark committed Jan 8, 2017
1 parent 7c98000 commit 6d277dd
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/framework/web/UrlManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,4 +498,50 @@ public function testHash()
$url = $manager->createAbsoluteUrl(['site/test', '#' => 'testhash']);
$this->assertEquals('http://example.com/index.php/testPage#testhash', $url);
}

/**
* @dataProvider multipleHostsRulesDataProvider
*
* @see https://github.com/yiisoft/yii2/issues/7948
*
* @param string $host
*/
public function testMultipleHostsRules($host)
{
$manager = new UrlManager([
'enablePrettyUrl' => true,
'cache' => null,
'rules' => [
['host' => 'http://example.com', 'pattern' => '<slug:(search)>', 'route' => 'products/search', 'defaults' => ['lang' => 'en']],
['host' => 'http://example.fr', 'pattern' => '<slug:(search)>', 'route' => 'products/search', 'defaults' => ['lang' => 'fr']],
],
'hostInfo' => $host,
'baseUrl' => '/',
'scriptUrl' => '',
]);

$url = $manager->createAbsoluteUrl(['products/search', 'lang' => 'en', 'slug' => 'search'], 'https');
$this->assertEquals('https://example.com/search', $url);
$url = $manager->createUrl(['products/search', 'lang' => 'en', 'slug' => 'search']);
$this->assertEquals('http://example.com/search', $url);
$url = $manager->createUrl(['products/search', 'lang' => 'en', 'slug' => 'search', 'param1' => 'value1']);
$this->assertEquals('http://example.com/search?param1=value1', $url);

$url = $manager->createAbsoluteUrl(['products/search', 'lang' => 'fr', 'slug' => 'search'], 'https');
$this->assertEquals('https://example.fr/search', $url);
$url = $manager->createUrl(['products/search', 'lang' => 'fr', 'slug' => 'search']);
$this->assertEquals('http://example.fr/search', $url);
$url = $manager->createUrl(['products/search', 'lang' => 'fr', 'slug' => 'search', 'param1' => 'value1']);
$this->assertEquals('http://example.fr/search?param1=value1', $url);
}

public function multipleHostsRulesDataProvider()
{
return [
['http://example.com'],
['https://example.com'],
['http://example.fr'],
['https://example.fr'],
];
}
}

0 comments on commit 6d277dd

Please sign in to comment.