Commit 5937817d authored by Fabrice Gangler's avatar Fabrice Gangler 🎨
Browse files

TEST(mapping): add checks for add|edit form

Refs: #902 #874 #824 #882 #883
parent 3c3c5748
Pipeline #9768 passed with stage
in 4 minutes and 6 seconds
......@@ -721,14 +721,15 @@ class TaxonomysControllerTest extends ApiIntegrationTestCase
// $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-$idUser\"", $html);
$this->assertContains("class=\"taxonomyComment\"", $html);
$this->assertContains("id=\"mappingTaxon$idTaxon-UsersOf$idSoftware-comment-user$idUser\"", $html);
$this->assertContains("blabla bla du comentaire", $html);
// $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-$idUser\"", $html);
// $this->assertContains("class=\"taxonomyComment\"", $html);
// $this->assertContains("id=\"mappingTaxon$idTaxon-UsersOf$idSoftware-comment-user$idUser\"", $html);
// $this->assertContains("blabla bla du comentaire", $html);
$this->markTestIncomplete('Not implemented yet.');
}
......
......@@ -71,14 +71,16 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
* @group taxonomy-software_mappingForm
* @return void
*/
public function testMappingForm()
public function testMappingFormDisplay()
{
$url = '/fr/mappingForm/2'; // software ID 2
$title = "<title>Formulaire cartographie</title>";
$url = '/fr/mappingForm/2'; // software ID 2 "Lutèce"
$title = "<title>Logiciel Lutèce : déclarer vos usages</title>";
// Tempory test ---> can be remove when development is complete.
$this->setAdminSessionOfPersonType();
$this->checkUrlNotAuthorized($url, ['html']);
$this->setConnectedAdministrationSession();
$this->checkUrlNotAuthorized($url, ['html']);
// Admin user --> to be replaced by a connected user (type = "Administration") when development is complete.
$this->setAdminSessionOfAdministrationType(); # dev version
......@@ -87,6 +89,18 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
$html = $r['html']['data'];
$this->assertContains('<html lang="fr">', $html);
$this->assertContains("$title", $html);
$this->assertContains('class="taxonomyForm_step1_content"', $html);
$this->assertNotContains('id="checkbox_1"', $html); // Primary level --> no checkbox
$this->assertNotContains('id="checkbox_2"', $html); // Primary level --> no checkbox
$this->assertContains('id="checkbox_3"', $html);
$this->assertContains('id="checkbox_4"', $html);
$this->assertContains('id="checkbox_5"', $html);
$this->assertContains('id="checkbox_6"', $html);
$this->assertNotContains('id="checkbox_7"', $html); // no found taxon --> no checkbox
$htmlCheckBox = '<label for="checkbox_3">';
$htmlCheckBox .= '<input type="checkbox" name="taxonCheckboxes[]" value="3" id="checkbox_3">';
$htmlCheckBox .= 'Urbanisme / Espace public / Environnement</label>';
$this->assertContains($htmlCheckBox, $html); // no found taxon --> no checkbox
// Connected user (type != "Administration")
$this->setConnectedPersonSession();
......@@ -101,6 +115,149 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
$this->checkUrlRedirectToLogin($url, ['html'], 'fr');
}
/**
* MappingForm method used by connected user (type = "Administration")
* after registering as user of a sofware.
*
* URL: /en/mappingForm/<softwareId>
* /fr/mappingForm/<softwareId>
*
* User sends form several times (add/edit):
* - Check BEFORE send form data ---> no associed entry (user-software-taxon)
* - Send form data with 2 associed entries
* - Check AFTER ---> 2 entries found
* - Resend form data: user unchecks an entry
* - Check AFTER ---> only last entry found
* - Resend form data: user unchecks last entry
* - Check AFTER ---> no associed entry (user-software-taxon)
*
* @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-software
* @group taxonomy-software_public
* @group taxonomy-software_mappingForm
* @return void
*/
public function testMappingFormSend()
{
$taxonIdA = 3;
$taxonSlugA = 'urbanisme-espace-public-environnement';
$taxonIdB = 4;
$taxonSlugB = 'bureautique';
$softwareId = 2;
$softwareSlug = 'lutece';
$idUserA = 5;
$urlForm = "/fr/mappingForm/$softwareId";
$softwareUrl = "/fr/softwares/$softwareId";
$testeddUrlTaxonA = "/fr/cartographie/metiers/$taxonSlugA/$softwareSlug/$taxonIdA.$softwareId";
$redirectUrlTaxonA = "/fr/cartographie/metiers/$taxonSlugA/$taxonIdA";
$testeddUrlTaxonB = "/fr/cartographie/generiques/$taxonSlugB/$softwareSlug/$taxonIdB.$softwareId";
$redirectUrlTaxonB = "/fr/cartographie/generiques/$taxonSlugB/$taxonIdB";
// Admin user --> to be replaced by a connected user (type = "Administration") when development is complete.
$this->setAdminSessionOfAdministrationType(); # dev version
// $this->setConnectedAdministrationSession(); # final version
// Check BEFORE send form data
///////////////////////////////////
// no entry for current user (ID-5), software ID-2 and taxon ID 3 | 4
$this->checkUrlRedirectToAnotherUrl($testeddUrlTaxonA, $redirectUrlTaxonA, ['html'], 301);
$this->checkUrlRedirectToAnotherUrl($testeddUrlTaxonB, $redirectUrlTaxonB, ['html'], 301);
// in the form, checkbox (of taxon ID 3|ID 4) must not be checked
$r = $this->checkUrlOk($urlForm, ['html']);
$html = $r['html']['data'];
$this->assertContains('id="checkbox_'.$taxonIdA.'"', $html);
$this->assertContains('id="checkbox_'.$taxonIdB.'"', $html);
$this->assertNotContains('id="checkbox_'.$taxonIdA.'" checked="checked"', $html);
$this->assertNotContains('id="checkbox_'.$taxonIdB.'" checked="checked"', $html);
// Send form data
///////////////////////////////////
$data = [ 'id' => "$softwareId", 'taxonCheckboxes' => [$taxonIdA, $taxonIdB]];
$this->post($urlForm, $data);
$headers = $this->_response->header();
$this->assertResponseCode(302);
$this->assertEquals($softwareUrl, $headers['Location']);
// Check AFTER send form data
///////////////////////////////////
// entry found for current user (ID-5), software ID-2 and taxon ID 3
$r = $this->checkUrlOk($testeddUrlTaxonA, ['html']);
$html = $r['html']['data'];
$this->assertContains("id=\"mappingTaxon$taxonIdA-UsersOf$softwareId\"", $html); // <section id="">
$this->assertContains("id=\"userPreviewCard-$idUserA\"", $html);
// entry found for current user (ID-5), software ID-2 and taxon ID 4
$r = $this->checkUrlOk($testeddUrlTaxonB, ['html']);
$html = $r['html']['data'];
$this->assertContains("id=\"mappingTaxon$taxonIdB-UsersOf$softwareId\"", $html); // <section id="">
$this->assertContains("id=\"userPreviewCard-$idUserA\"", $html);
// in the form, checkbox (of taxon ID3|ID4) must be checked
$r = $this->checkUrlOk($urlForm, ['html']);
$html = $r['html']['data'];
$this->assertContains('id="checkbox_'.$taxonIdA.'" checked="checked"', $html);
$this->assertContains('id="checkbox_'.$taxonIdB.'" checked="checked"', $html);
// Resend form data: user unchecks an entry $taxonIdA
/////////////////////////////////////////////////////
$data = [ 'id' => "$softwareId", 'taxonCheckboxes' => [$taxonIdB]];
$this->post($urlForm, $data);
$headers = $this->_response->header();
$this->assertResponseCode(302);
$this->assertEquals($softwareUrl, $headers['Location']);
// Check AFTER resend send form data (user unchecks an entry $taxonIdA)
///////////////////////////////////////////////////////////////////////
// no entry for current user (ID-5), software ID-2 and taxon ID 3
$this->checkUrlRedirectToAnotherUrl($testeddUrlTaxonA, $redirectUrlTaxonA, ['html'], 301);
// entry found for current user (ID-5), software ID-2 and taxon ID 4
$r = $this->checkUrlOk($testeddUrlTaxonB, ['html']);
$html = $r['html']['data'];
$this->assertContains("id=\"mappingTaxon$taxonIdB-UsersOf$softwareId\"", $html); // <section id="">
$this->assertContains("id=\"userPreviewCard-$idUserA\"", $html);
// in the form, checkbox (of taxon ID4) must be checked, but not for taxon ID3
$r = $this->checkUrlOk($urlForm, ['html']);
$html = $r['html']['data'];
$this->assertNotContains('id="checkbox_'.$taxonIdA.'" checked="checked"', $html);
$this->assertContains('id="checkbox_'.$taxonIdB.'" checked="checked"', $html);
// Resend form data: user unchecks the last entry $taxonIdB
/////////////////////////////////////////////////////////////////////////////
$data = [ 'id' => "$softwareId"];
$this->post($urlForm, $data);
$headers = $this->_response->header();
$this->assertResponseCode(302);
$this->assertEquals($softwareUrl, $headers['Location']);
// Check AFTER resend send form data (user unchecks the last entry $taxonIdB)
/////////////////////////////////////////////////////////////////////////////
// no entry for current user (ID-5), software ID-2 and taxon ID 3
$this->checkUrlRedirectToAnotherUrl($testeddUrlTaxonA, $redirectUrlTaxonA, ['html'], 301);
// entry found for current user (ID-5), software ID-2 and taxon ID 4
$this->checkUrlRedirectToAnotherUrl($testeddUrlTaxonB, $redirectUrlTaxonB, ['html'], 301);
// in the form, checkbox (of taxon ID4) must be checked, but not for taxon ID3
$r = $this->checkUrlOk($urlForm, ['html']);
$html = $r['html']['data'];
$this->assertNotContains('id="checkbox_'.$taxonIdA.'" checked="checked"', $html);
$this->assertNotContains('id="checkbox_'.$taxonIdB.'" checked="checked"', $html);
}
/**
* MappingForm method for a not found software
*
......
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