Commit b7b6e570 authored by Fabrice Gangler's avatar Fabrice Gangler 🎨 Committed by Matthieu FAURE
Browse files

TESTS(mapping): add 6 tests for mappingTaxonUsersOf() method

6 tests for mappingTaxonUsersOf() method:
- a taxon has a software with users (one or more)
- a taxon has a software without user (preselected software)
- a taxon is not associated with this software
- taxon not found in database
- redirects work when the URL is slightly different
- with URL prefix /api/v1/ redirect to '/en/mapping/'

Refs: #823
parent 8655aab6
......@@ -628,6 +628,285 @@ class TaxonomysControllerTest extends ApiIntegrationTestCase
$this->checkUrlRedirectToLogin($url, ['html']);
}
// mappingTaxonUsersOf method
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* mappingTaxonUsersOf method: a taxon has a software with users (one or more)
*
* URL: /fr/cartographie/<slugPrimaryLevel>/<slugTaxon>/<slugSoftware>/<taxonId>.<softwareId>
* /en/mapping/<slugPrimaryLevel>/<slugTaxon>/<slugSoftware>/<taxonId>.<softwareId>
*
* ex: /fr/cartographie/generiques/bureautique/libreoffice/20.33
* /en/mapping/generics/office-automation/libreoffice/20.33
*
*
* @todo WIP
* @todo admin user to be replaced by a connected user (type = "Administration") when development is complete.
*
* @group public
* @group taxonomy
* @group taxonomy_public
* @group taxonomy_mappingTaxonUsersOf
* @return void
*/
public function testMappingTaxonUsersOfShouldHaveSoftwareWithUsers()
{
$idTaxon = 3;
$idSoftware = 1;
$url = "/fr/cartographie/metiers/urbanisme-espace-public-environnement/asalae/$idTaxon.$idSoftware";
$title = "<title>Utilisateurs du logiciel Asalae - Urbanisme / Espace public / Environnement";
// Admin user --> to be replaced by a connected user (type = "Administration") when development is complete.
$this->setAdminSessionOfAdministrationType(); # dev version
// $this->setConnectedAdministrationSession(); # final version
$r = $this->checkUrlOk($url, ['html']);
$html = $r['html']['data'];
$this->assertContains('<html lang="fr">', "$html");
$this->assertContains("$title", "$html");
$this->assertContains("id=\"mappingTaxon$idTaxon-UsersOf$idSoftware\"", $html); // <section id="">
$this->assertContains("class=\"mappingTaxonUsersOfPage", $html); // <section class="">
$this->assertContains("id=\"userPreviewCard-$idSoftware\"", $html);
// Connected user (type != "Administration") --> to be deleted when development is complete.
$this->setConnectedPersonSession();
$this->checkUrlNotAuthorized($url, ['html']);
$this->setConnectedCompanySession();
$this->checkUrlNotAuthorized($url, ['html']);
$this->setConnectedAssociationSession();
$this->checkUrlNotAuthorized($url, ['html']);
// Anonymous user --> to be deleted when development is complete.
$this->setAnonymousUserSession();
$this->checkUrlRedirectToLogin($url, ['html'], 'fr');
}
/**
* mappingTaxonUsersOf method: a taxon has a software without user (preselected software)
*
* URL: /en/mapping/<slugPrimaryLevel>/<slugTaxon>/<slugSoftware>/<taxonId>.<softwareId_withoutUser>
* ----> redirect to /en/mapping/<slugPrimaryLevel>/<slugTaxon>/<taxonId>
*
* ex: /fr/cartographie/generiques/bureautique/libreoffice/20.33
* /en/mapping/generics/office-automation/libreoffice/20.33
*
* @todo WIP
* @todo admin user to be replaced by an anonymous and/or connected user when development is complete.
*
* @group public
* @group taxonomy
* @group taxonomy_public
* @group taxonomy_mappingTaxonUsersOf
* @return void
*/
public function testMappingTaxonUsersOfShouldHaveSoftwareWithoutUsers()
{
$idTaxon = 6;
$idSoftware = 4;
$testeddUrl = "/fr/cartographie/generiques/design/soft-4/$idTaxon.$idSoftware";
// Admin user --> to be replaced by an anonymous user and a logged-in user when development is complete.
$this->setAdminSessionOfPersonType();
$expectedUrl = "/fr/cartographie/generiques/design/$idTaxon";
$this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
}
/**
* MappingTaxonUsersOf method: a taxon is not associated with this software
*
* URL: /en/mapping/<slugPrimaryLevel>/<slugTaxon>/<slugSoftware>/<taxonId>.<softwareId_notAssociated>
* ----> redirect to /en/mapping/<slugPrimaryLevel>/<slugTaxon>/<taxonId>
*
* ex: /fr/cartographie/generiques/bureautique/libreoffice/20.33
* /en/mapping/generics/office-automation/libreoffice/20.33
*
* @todo WIP
* @todo admin user to be replaced by an anonymous and/or connected user when development is complete.
*
* @group public
* @group taxonomy
* @group taxonomy_public
* @group taxonomy_mappingTaxonUsersOf
* @return void
*/
public function testMappingTaxonUsersOfShouldNotBeAssociatedWithThisSoftware()
{
$idTaxon = 4;
$idSoftware = 4;
$testeddUrl = "/fr/cartographie/generiques/bureautique/soft-4/$idTaxon.$idSoftware";
// Admin user --> to be replaced by an anonymous user and a logged-in user when development is complete.
$this->setAdminSessionOfPersonType();
$expectedUrl = "/fr/cartographie/generiques/bureautique/$idTaxon";
$this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
}
/**
* MappingTaxonUsersOf method: taxon not found in database
*
* Check that if the requested taxon does not exist,
* a redirection is made to '/en/mapping/' or '/fr/cartographie/'
*
* URL: /en/mapping/<slugPrimaryLevel>/<slugTaxon>/<slugSoftware>/<taxonId_notFound>.<softwareId>
* /fr/mapping/<slugPrimaryLevel>/<slugTaxon>/<slugSoftware>/<taxonId_notFound>.<softwareId>
*
* ex: /fr/cartographie/generiques/bureautique/libreoffice/20.33
* /en/mapping/generics/office-automation/libreoffice/20.33
*
* @todo admin user to be replaced by an anonymous and/or connected user when development is complete.
*
* @group seo
* @group public
* @group taxonomy
* @group taxonomy_public
* @group taxonomy_mappingTaxonUsersOf
* @return void
*/
public function testMappingTaxonUsersOfTaxonNotFound()
{
$idTaxon = 999; // not found taxon
$idSoftware = 4;
// Admin user
// --> to be replaced by an anonymous user and a logged-in user when development is complete.
$this->setAdminSessionOfPersonType();
// French user:
$expectedUrl = '/fr/cartographie/';
$testeddUrl = "/fr/cartographie/metiers/notFoundTaxon/soft4Name/$idTaxon.$idSoftware";
$this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
// English user
$expectedUrl = '/en/mapping/';
$testeddUrl = "/en/mapping/business/notFoundTaxon/soft4Name/$idTaxon.$idSoftware";
$this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
}
/**
* MappingTaxonUsersOf method:
*
* Check that redirects work when the URL is slightly different
* - extra slash at the end of the URL
* - the language prefix is missing at the beginning of the URL
* - the user has changed the language prefix in the URL
*
* URL: /en/mapping/<slugPrimaryLevel>/<slugTaxon>/<slugSoftware>/<taxonId>.<softwareId>
* /fr/mapping/<slugPrimaryLevel>/<slugTaxon>/<slugSoftware>/<taxonId>.<softwareId>
*
* ex: /fr/cartographie/generiques/bureautique/libreoffice/20.33
* /en/mapping/generics/office-automation/libreoffice/20.33
*
* @todo admin user to be replaced by an anonymous and/or connected user when development is complete.
*
* @group seo
* @group public
* @group taxonomy
* @group taxonomy_public
* @group taxonomy_mappingTaxonUsersOf
* @return void
*/
public function testMMappingTaxonUsersOfCheckRedirects()
{
$idTaxon = 5;
$idSoftware = 4;
// Admin user
// --> to be replaced by an anonymous user and a logged-in user when development is complete.
$this->setAdminSessionOfPersonType();
// French user
//////////////////////////////////////////
$expectedUrl = "/fr/cartographie/generiques/infrastructure/soft-4/$idTaxon.$idSoftware";
// extra slash at the end of the URL
$testeddUrl = "$expectedUrl/";
$this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
// the user has changed the language prefix in the URL
$testeddUrl = "/fr/mapping/generics/infrastructure/soft-4/$idTaxon.$idSoftware";
$this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
// French user: language prefix is missing at the beginning of URL
$this->get("/fr/"); // force user language to french
$testeddUrl = "/cartographie/generiques/infrastructure/soft-4/$idTaxon.$idSoftware";
$this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
// English user
//////////////////////////////////////////
$expectedUrl = "/en/mapping/generics/infrastructure/soft-4/$idTaxon.$idSoftware";
// extra slash at the end of the URL
$testeddUrl = "$expectedUrl/";
$this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
// user has changed the language prefix in the URL
$testeddUrl = "/en/cartographie/generiques/infrastructure/soft-4/$idTaxon.$idSoftware";
$this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
// English user: language prefix is missing at the beginning of URL
$this->get("/en/"); // force user language to english
$testeddUrl = "/mapping/generics/infrastructure/soft-4/$idTaxon.$idSoftware";
$this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
}
/**
* MappingTaxonUsersOf method with URL prefix /api/v1/
* - HTML format redirects to the official URL
* - JSON format returns a 404 "not found" error.
*
* URL: /api/v1/taxonomys/mappingTaxonUsersOf ---> redirect to '/en/mapping/'
* /api/v1/taxonomys/mappingTaxonUsersOf/<id> ---> redirect to '/en/mapping/'
* /api/v1/taxonomys/mappingTaxonUsersOf.json ---> disable via parent::beforeFilter()
* /api/v1/taxonomys/mappingTaxonUsersOf/<id>.json ---> disable via parent::beforeFilter()
*
* @todo admin user to be replaced by a connected user (type = "Administration") when development is complete.
*
* @group seo
* @group public
* @group taxonomy
* @group taxonomy_public
* @group taxonomy_mappingTaxonUsersOf
* @return void
*/
public function testMappingTaxonUsersOfCheckApiPrefixInUrl()
{
$urlBase = '/api/v1/taxonomys/mappingTaxonUsersOf'; // missing software ID
$url = "$urlBase/2"; // software ID 2
// Admin user ---> to be replaced by a connected user (type = "Administration") when development is complete.
$this->setAdminSessionOfAdministrationType();
// JSON format
$this->checkUrlNotFound($urlBase, ['json']);
$this->checkUrlNotFound($url, ['json']);
// HTML format
$this->get("/fr/"); // force user language to french
$expectedUrl = '/fr/cartographie/'; // software ID 2
$this->checkUrlRedirectToAnotherUrl($urlBase, $expectedUrl, ['html'], 301);
$this->checkUrlRedirectToAnotherUrl($url, $expectedUrl, ['html'], 301);
// Connected user (type != "Administration") --> to be deleted when development is complete.
$this->setConnectedUserSession();
$this->checkUrlNotFound($url, ['json']);
$this->checkUrlNotAuthorized($url, ['html']);
// Anonymous user --> to be deleted when development is complete.
$this->setAnonymousUserSession();
$this->checkUrlNotFound($url, ['json']);
$this->checkUrlRedirectToLogin($url, ['html']);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//// Admin actions ---> self-generated by CakePHP //////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......
Supports Markdown
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