Commit 4db58b6c authored by Fabrice Gangler's avatar Fabrice Gangler 🎨
Browse files

TEST: check some redirections (language prefix missing...)

Refs: #908 #907
parent 256369d3
Pipeline #9832 passed with stage
in 3 minutes and 40 seconds
<?php
namespace App\Test\TestCase\Controller\Api\V1;
/**
* URls webapp Test Case
*/
class AppUrlTest extends ApiIntegrationTestCase
{
/**
* Fixtures
*
* @var array
*/
public $fixtures = [
'app.taxonomys',
'app.taxonomys_softwares',
'app.softwares',
'app.licenses',
'app.licence_types',
'app.relationships_softwares_users',
'app.users',
'app.user_types',
'app.reviews',
'app.relationships',
'app.relationship_types',
'app.relationships_softwares',
'app.relationships_users',
// 'app.usedsoftwares',
// 'app.backedsoftwares',
// 'app.createdsoftwares',
// 'app.contributionssoftwares',
// 'app.providerforsoftwares',
'app.screenshots',
'app.softwares_statistics',
'app.tags',
'app.softwares_tags',
// 'app.userssoftwares',
// 'app.backerssoftwares',
// 'app.creatorssoftwares',
// 'app.contributorssoftwares',
// 'app.providerssoftwares',
// 'app.workswellsoftwares',
// 'app.alternativeto'
];
// Mapping method
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Check that the redirections are working
* when the language prefix is not present in the URL.
*
* @group public
* @group url
* @return void
*/
public function testRedirectWhenLangPrefixIsMissing()
{
// Format: 'Tested URL' => 'Expected URL'
$englishUrls = [
'/' => '/en/',
'/pages/index' => '/en/',
'/pages/contact' => '/en/pages/contact',
'/pages/accessibility' => '/en/pages/accessibility',
'/users/2' => '/en/users/2',
'/users/usedSoftwares/2' => '/en/users/usedSoftwares/2',
'/users/providerforSoftwares/2' => '/en/users/providerforSoftwares/2',
'/users/2/reviews' => '/en/users/2/reviews',
'/softwares/3' => '/en/softwares/3',
'/softwares/usersSoftware/3' => '/en/softwares/usersSoftware/3',
'/softwares/servicesProviders/3' => '/en/softwares/servicesProviders/3',
'/softwares/usersSoftware/3' => '/en/softwares/usersSoftware/3',
'/softwares/1/reviews' => '/en/softwares/1/reviews',
'/softwares/1/reviews/2' => '/en/softwares/1/reviews/2',
];
$frenchUrls = [];
foreach ($englishUrls as $testedUrl => $expectedUrl) {
$frenchUrls[$testedUrl] = str_replace('/en/', '/fr/', $expectedUrl);
}
// Checki if the URLs redirects correctly
$this->get("/en/"); // force user language to english
$this->commonCheck($englishUrls);
$this->get("/fr/"); // force user language to french
$this->commonCheck($frenchUrls);
}
/**
* Check that redirections are working
* for old URLs
*
* @group public
* @group url
* @return void
*/
public function testRedirectWhenOldURL()
{
// Format: 'Tested URL' => 'Expected URL'
$urls = [
'/softwares/services-providers/3' => '/en/softwares/servicesProviders/3',
'/softwares/users-software/3' => '/en/softwares/usersSoftware/3',
];
$englishUrls = [];
foreach ($urls as $testedUrl => $expectedUrl) {
$englishUrls['/en'. $testedUrl] = $expectedUrl;
}
// Checki if the URLs redirects correctly
$this->get("/en/"); // force user language to english
$this->commonCheck($urls);
$this->commonCheck($englishUrls);
}
/**
* Checking if a list of URLs redirects correctly
*
* @param array $urls example: [ 'Tested URL' => 'Expected URL', ... ]
*/
private function commonCheck(array $urls)
{
foreach ($urls as $testedUrl => $expectedUrl) {
$this->checkUrlRedirectToAnotherUrl($testedUrl, $expectedUrl, ['html'], 301);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment