Commit ec0fa69e authored by Fabrice Gangler's avatar Fabrice Gangler 🎨
Browse files

TEST(mapping): add some assertions for software page

Refs: #918
parent 2563865f
......@@ -351,17 +351,22 @@ class TaxonomysControllerTest extends ApiIntegrationTestCase
* @group taxonomy
* @group taxonomy_public
* @group taxonomy_method_mappingTaxon
*
* @group wip_userPage
* @return void
*/
public function testMappingTaxonShouldHaveSoftwareWithUsers()
{
$idTaxon = 3;
$idSoftware = 1;
$idUserA = 5;
$idUserB = 10;
$url = "/fr/cartographie/metiers/urbanisme-espace-public-environnement/$idTaxon";
$softwareUrl = "/fr/softwares/$idSoftware";
$htmlTitle = "<title>Urbanisme / Espace public / Environnement";
// Anonymous user
$this->setAnonymousUserSession();
// Connected user
$this->setConnectedUserSession();
$r = $this->checkUrlOk($url, ['html']);
$html = $r['html']['data'];
$this->assertContains('<html lang="fr">', $html);
......@@ -371,8 +376,8 @@ class TaxonomysControllerTest extends ApiIntegrationTestCase
$this->assertContains("id=\"item-software$idSoftware-forTaxon$idTaxon\"", $html);
$this->assertContains("id=\"link-software$idSoftware-forTaxon$idTaxon\"", $html);
// Connected user
$this->setConnectedUserSession();
// Anonymous user
$this->setAnonymousUserSession();
$r = $this->checkUrlOk($url, ['html']);
$html = $r['html']['data'];
$this->assertContains('<html lang="fr">', $html);
......@@ -381,6 +386,31 @@ class TaxonomysControllerTest extends ApiIntegrationTestCase
$this->assertContains("class=\"item-softwareForTaxon$idTaxon\"", $html);
$this->assertContains("id=\"item-software$idSoftware-forTaxon$idTaxon\"", $html);
$this->assertContains("id=\"link-software$idSoftware-forTaxon$idTaxon\"", $html);
// on software page: found link for taxon ID 6
$r = $this->checkUrlOk($softwareUrl, ['html'], false);
$html = $r['html']['data'];
$this->assertContains("id=\"mappingForSoftware-$idSoftware\"", $html);
$this->assertContains("class=\"linkMapping-taxonSoftware\"", $html);
$this->assertContains("id=\"linkMapping-taxon-$idTaxon-Software-$idSoftware\"", $html);
// on user (ID 5) page: found link for taxon ID 6
$userUrl = "/fr/users/$idUserA";
$r = $this->checkUrlOk($userUrl, ['html'], false);
$html = $r['html']['data'];
$this->assertContains("id=\"softwarePreviewCard-$idSoftware\"", $html);
// $this->assertContains("id=\"mappingForUser-$idUserA\"", $html);
// $this->assertContains("class=\"linkMappingTaxon\"", $html);
// $this->assertContains("id=\"linkMappingTaxon-$idTaxon\"", $html);
// on user (ID 10) page: found link for taxon ID 6
$userUrl = "/fr/users/$idUserB";
$r = $this->checkUrlOk($userUrl, ['html'], false);
$html = $r['html']['data'];
$this->assertContains("id=\"softwarePreviewCard-$idSoftware\"", $html);
// $this->assertContains("id=\"mappingForUser-$idUserB\"", $html);
// $this->assertContains("class=\"linkMappingTaxon\"", $html);
// $this->assertContains("id=\"linkMappingTaxon-$idTaxon\"", $html);
}
......@@ -404,11 +434,12 @@ class TaxonomysControllerTest extends ApiIntegrationTestCase
$idTaxon = 6;
$idSoftware = 4;
$url = "/fr/cartographie/generiques/design/$idTaxon";
$softwareUrl = "/fr/softwares/$idSoftware";
$htmlTitle = "<title>Design";
// Anonymous user
$this->setAnonymousUserSession();
$r = $this->checkUrlOk($url, ['html']);
$r = $this->checkUrlOk($url, ['html'], false);
$html = $r['html']['data'];
$this->assertContains('<html lang="fr">', $html);
$this->assertContains($htmlTitle, $html);
......@@ -416,6 +447,13 @@ class TaxonomysControllerTest extends ApiIntegrationTestCase
$this->assertContains("class=\"item-softwareForTaxon$idTaxon\"", $html);
$this->assertContains("id=\"item-software$idSoftware-forTaxon$idTaxon\"", $html);
$this->assertNotContains("id=\"link-software$idSoftware-forTaxon$idTaxon\"", $html);
// on software page: no link for taxon ID 6
$r = $this->checkUrlOk($softwareUrl, ['html'], false);
$html = $r['html']['data'];
$this->assertContains("id=\"mappingForSoftware-$idSoftware\"", $html);
$this->assertContains("class=\"linkMapping-taxonSoftware\"", $html);
$this->assertNotContains("id=\"linkMapping-taxon-$idTaxon-Software-$idSoftware\"", $html);
}
......@@ -593,8 +631,8 @@ class TaxonomysControllerTest extends ApiIntegrationTestCase
{
$idTaxon = 3;
$idSoftware = 1;
$idUserA = 2;
$idUserB = 4;
$idUserA = 5;
$idUserB = 10;
$url = "/fr/cartographie/metiers/urbanisme-espace-public-environnement/asalae/$idTaxon.$idSoftware";
$title = "<title>Utilisateurs du logiciel Asalae - Urbanisme / Espace public / Environnement";
......
......@@ -128,6 +128,8 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
* @group taxonomy-software
* @group taxonomy-software_public
* @group taxonomy-software_mappingForm
* @group wip_userPage
*
* @return void
*/
public function testMappingFormSend()
......@@ -136,11 +138,12 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
$taxonSlugA = 'urbanisme-espace-public-environnement';
$taxonIdB = 4;
$taxonSlugB = 'bureautique';
$softwareId = 2;
$softwareSlug = 'lutece';
$softwareId = 5;
$softwareSlug = 'soft-5';
$idUserA = 6;
$urlForm = "/fr/mappingForm/$softwareId";
$softwareUrl = "/fr/softwares/$softwareId";
$userUrl = "/fr/users/$idUserA";
$testeddUrlTaxonA = "/fr/cartographie/metiers/$taxonSlugA/$softwareSlug/$taxonIdA.$softwareId";
$redirectUrlTaxonA = "/fr/cartographie/metiers/$taxonSlugA/$taxonIdA";
$testeddUrlTaxonB = "/fr/cartographie/generiques/$taxonSlugB/$softwareSlug/$taxonIdB.$softwareId";
......@@ -149,15 +152,41 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
// connected user (type = "Administration")
$this->setConnectedAdministrationSession();
// Beforehand, the user declares himself/herself to be a user of the software.
$r = $this->checkUrlOk($userUrl, ['html'], false);
$html = $r['html']['data'];
$this->assertNotContains("id=\"softwarePreviewCard-$softwareId\"", $html);
$this->post('api/v1/softwares/usersSoftware/5.json');
// Check BEFORE send form data
///////////////////////////////////
// no entry for current user (ID-6), software ID-2 and taxon ID 3 | 4
// (1) no entry for current user (ID-6), software ID-5 and taxon ID 3 | 4
// on mapping page (1)
$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']);
// on software page (1)
$r = $this->checkUrlOk($softwareUrl, ['html'], false);
$html = $r['html']['data'];
$this->assertNotContains("id=\"mappingForSoftware-$softwareId\"", $html);
$this->assertNotContains("class=\"linkMapping-taxonSoftware\"", $html);
$this->assertNotContains("id=\"linkMapping-taxon-$taxonIdA-Software-$softwareId\"", $html);
$this->assertNotContains("id=\"linkMapping-taxon-$taxonIdB-Software-$softwareId\"", $html);
// on user page (1)
$r = $this->checkUrlOk($userUrl, ['html'], false);
$html = $r['html']['data'];
$this->assertContains("id=\"softwarePreviewCard-$softwareId\"", $html);
$this->assertNotContains("id=\"mappingForUser-$idUserA\"", $html);
$this->assertNotContains("class=\"linkMappingTaxon\"", $html);
$this->assertNotContains("id=\"linkMappingTaxon-$taxonIdA\"", $html);
$this->assertNotContains("id=\"linkMappingTaxon-$taxonIdB\"", $html);
// on form page, checkbox (of taxon ID 3|ID 4) must not be checked
$r = $this->checkUrlOk($urlForm, ['html'], false);
$html = $r['html']['data'];
$this->assertContains('id="checkbox_'.$taxonIdA.'"', $html);
$this->assertContains('id="checkbox_'.$taxonIdB.'"', $html);
......@@ -175,20 +204,39 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
// Check AFTER send form data
///////////////////////////////////
// entry found for current user (ID-6), software ID-2 and taxon ID 3
$r = $this->checkUrlOk($testeddUrlTaxonA, ['html']);
// (2) entries found for current user (ID-6), software ID-5 and taxon ID 3 | 4
// on software page (2)
$r = $this->checkUrlOk($softwareUrl, ['html'], false);
$html = $r['html']['data'];
$this->assertContains("id=\"mappingForSoftware-$softwareId\"", $html);
$this->assertContains("class=\"linkMapping-taxonSoftware\"", $html);
$this->assertContains("id=\"linkMapping-taxon-$taxonIdA-Software-$softwareId\"", $html);
$this->assertContains("id=\"linkMapping-taxon-$taxonIdB-Software-$softwareId\"", $html);
// on user page (2)
$r = $this->checkUrlOk($userUrl, ['html'], false);
$html = $r['html']['data'];
$this->assertContains("id=\"softwarePreviewCard-$softwareId\"", $html);
// $this->assertContains("id=\"mappingForUser-$idUserA\"", $html);
// $this->assertContains("class=\"linkMappingTaxon\"", $html);
// $this->assertContains("id=\"linkMappingTaxon-$taxonIdA\"", $html);
// $this->assertContains("id=\"linkMappingTaxon-$taxonIdB\"", $html);
// on mapping page: entry found for current user (ID-6), software ID-5 and taxon ID 3
$r = $this->checkUrlOk($testeddUrlTaxonA, ['html'], false);
$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']);
// on mapping page: entry found for current user (ID-6), software ID-5 and taxon ID 4
$r = $this->checkUrlOk($testeddUrlTaxonB, ['html'], false);
$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']);
// on form page, checkbox (of taxon ID3|ID4) must be checked
$r = $this->checkUrlOk($urlForm, ['html'], false);
$html = $r['html']['data'];
$this->assertContains('id="checkbox_'.$taxonIdA.'" checked="checked"', $html);
$this->assertContains('id="checkbox_'.$taxonIdB.'" checked="checked"', $html);
......@@ -204,17 +252,36 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
// Check AFTER resend send form data (user unchecks an entry $taxonIdA)
///////////////////////////////////////////////////////////////////////
// no entry for current user (ID-6), software ID-2 and taxon ID 3
// (3) entry found for current user (ID-6), software ID-5 and taxon ID 4, but not for taxon ID 3
// on software page (3)
$r = $this->checkUrlOk($softwareUrl, ['html'], false);
$html = $r['html']['data'];
$this->assertContains("id=\"mappingForSoftware-$softwareId\"", $html);
$this->assertContains("class=\"linkMapping-taxonSoftware\"", $html);
$this->assertNotContains("id=\"linkMapping-taxon-$taxonIdA-Software-$softwareId\"", $html);
$this->assertContains("id=\"linkMapping-taxon-$taxonIdB-Software-$softwareId\"", $html);
// on user page (3)
$r = $this->checkUrlOk($userUrl, ['html'], false);
$html = $r['html']['data'];
$this->assertContains("id=\"softwarePreviewCard-$softwareId\"", $html);
// $this->assertContains("id=\"mappingForUser-$idUserA\"", $html);
// $this->assertContains("class=\"linkMappingTaxon\"", $html);
// $this->assertNotContains("id=\"linkMappingTaxon-$taxonIdA\"", $html);
// $this->assertContains("id=\"linkMappingTaxon-$taxonIdB\"", $html);
// on mapping page: no entry for current user (ID-6), software ID-5 and taxon ID 3
$this->checkUrlRedirectToAnotherUrl($testeddUrlTaxonA, $redirectUrlTaxonA, ['html'], 301);
// entry found for current user (ID-6), software ID-2 and taxon ID 4
$r = $this->checkUrlOk($testeddUrlTaxonB, ['html']);
// on mapping page: entry found for current user (ID-6), software ID-5 and taxon ID 4
$r = $this->checkUrlOk($testeddUrlTaxonB, ['html'], false);
$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']);
// on form page, checkbox (of taxon ID4) must be checked, but not for taxon ID3
$r = $this->checkUrlOk($urlForm, ['html'], false);
$html = $r['html']['data'];
$this->assertNotContains('id="checkbox_'.$taxonIdA.'" checked="checked"', $html);
$this->assertContains('id="checkbox_'.$taxonIdB.'" checked="checked"', $html);
......@@ -231,14 +298,31 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
// Check AFTER resend send form data (user unchecks the last entry $taxonIdB)
/////////////////////////////////////////////////////////////////////////////
// no entry for current user (ID-6), software ID-2 and taxon ID 3
$this->checkUrlRedirectToAnotherUrl($testeddUrlTaxonA, $redirectUrlTaxonA, ['html'], 301);
// (4) no entry for current user (ID-6), software ID-5 and taxon ID 3 | 4
// entry found for current user (ID-6), software ID-2 and taxon ID 4
// on software page (4)
$r = $this->checkUrlOk($softwareUrl, ['html'], false);
$html = $r['html']['data'];
$this->assertNotContains("id=\"mappingForSoftware-$softwareId\"", $html);
$this->assertNotContains("class=\"linkMapping-taxonSoftware\"", $html);
$this->assertNotContains("id=\"linkMapping-taxon-$taxonIdA-Software-$softwareId\"", $html);
$this->assertNotContains("id=\"linkMapping-taxon-$taxonIdB-Software-$softwareId\"", $html);
// on user page (4)
$r = $this->checkUrlOk($userUrl, ['html'], false);
$html = $r['html']['data'];
$this->assertContains("id=\"softwarePreviewCard-$softwareId\"", $html);
$this->assertNotContains("id=\"mappingForUser-$idUserA\"", $html);
$this->assertNotContains("class=\"linkMappingTaxon\"", $html);
$this->assertNotContains("id=\"linkMappingTaxon-$taxonIdA\"", $html);
$this->assertNotContains("id=\"linkMappingTaxon-$taxonIdB\"", $html);
// on mapping page (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']);
// on form page, checkbox (of taxon ID 3|ID 4) must not be checked
$r = $this->checkUrlOk($urlForm, ['html'], false);
$html = $r['html']['data'];
$this->assertNotContains('id="checkbox_'.$taxonIdA.'" checked="checked"', $html);
$this->assertNotContains('id="checkbox_'.$taxonIdB.'" checked="checked"', $html);
......
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