Skip to content
Snippets Groups Projects
Commit 12aab391 authored by Fabrice Gangler's avatar Fabrice Gangler :art:
Browse files

WIP - don't works (secu unit test for external ressource)

parent 2763833c
No related branches found
No related tags found
No related merge requests found
Pipeline #59619 canceled
......@@ -1924,4 +1924,126 @@ class SoftwaresControllerTest extends ApiIntegrationTestCase
$this->setConnectedCompanySession();
$this->commonCheckForHtmlFormEditSoftwareWithExtraFormData('providerFor');
}
/**
* Test HTML form:
* for the different user types ("Person", "Association", "Administration" and "Company"),
* edit a software by sending an HTTP Post request (the UI of the form is not tested)
* with "userOf" or "ProviderFor" parameters equal to "yes".
*
* - (1) Edit a software by sending an HTTP Post request (the UI of the form is not tested)
* - (1) Check that the main data is correctly recorded in the database.
* - (1) Check if current HTTP response is a redirection to the software URL.
* - For this user and this new software:
* - (2) Check if there are 1 records in 'RelationshipsSoftwaresUsers' table
* - (2) Check if there are 1 records in 'RelationshipsSoftwaresUsers' table, with correct relationship ID
*
* (1) via commonCheckForHtmlFormEditSoftware()
* (2) via commonCheckForHtmlFormEditSoftwareWithExtraFormData()
*
* @group user
* @group user_person
* @group software
* @group software_edit
* @group software_methode_edit
* @group software_methode_edit
* @group wip
*/
public function testHtmlFormEditSoftwareUpdateExternalRessources()
{
// "Person" user with "admin" role
$this->setAdminSessionOfPersonType();
// Grab a software in the database before updating it.
$softwareId = 7;
$software = $this->Softwares->find()->where(['id' => $softwareId])->toList()[0];
// dump($software); exit();
$alea = mt_rand();
$newSoftwareName = $software->get('softwarename'). " $alea";
$dataForm = [
'softwarename' => $newSoftwareName,
'url_repository' => $software->get('url_repository') . "/$alea",
'description' => $software->get('description') . " $alea",
'licence_id' => $software->get('licence_id'),
"url_website" => $software->get('url_website') . "/$alea",
"tag_string" => $software->get('tag_string'). "$alea $alea$alea",
'sill' => 1,
'wikidata' => '',
'framalibre' => '',
'wikipedia_en' => '',
'wikipedia_fr' => '',
// 'sill' => $software->get('sill'),
// 'wikidata' => $software->get('wikidata') ."$alea",
// 'framalibre' => $software->get('framalibre') ,
// 'wikipedia_en' => $software->get('wikipedia_fr') ,
// 'wikipedia_fr' => $software->get('wikipedia_fr') ,
// 'sill' => $alea,
// 'wikidata' => $software->get('wikidata') ."$alea",
// 'framalibre' => $software->get('framalibre') ."$alea",
// 'wikipedia_en' => $software->get('wikipedia_fr') ."$alea",
// 'wikipedia_fr' => $software->get('wikipedia_fr') ."$alea",
];
// Edit software
$this->put("/fr/softwares/edit/$softwareId", $dataForm);
$this->assertEventFired('Model.Software.modified', $this->Softwares->eventManager());
// Cheking that the software now exists with its new name
// in the database and grab it's ID.
$this->assertEquals(
1,
$this->Softwares
->find()
->where(['softwarename' => $newSoftwareName ])
->count()
);
$softwareUpdated = $this->Softwares->find()->where(['id' => $softwareId ])->limit(1)->toList()[0];
$this->assertEquals($softwareId, $softwareUpdated->id);
// Cheking if current HTTP response is a redirection to the software URL
$redirectTo = "/fr/softwares/$softwareId";
$this->currentResponseIsRedirectionToAnotherUrl($redirectTo);
// Check that the main data is correctly recorded in the database.
$dataInDb = [
'softwarename' => $softwareUpdated->get('softwarename'),
'url_repository' => $softwareUpdated->get('url_repository'),
'description' => $softwareUpdated->get('description'),
'licence_id' => $softwareUpdated->get('licence_id'),
"url_website" => $softwareUpdated->get('url_website'),
"tag_string" => $softwareUpdated->get('tag_string'),
'sill' => $software->get('sill'),
'wikidata' => $software->get('wikidata'),
'framalibre' => $software->get('framalibre'),
'wikipedia_en' => $software->get('wikipedia_fr'),
'wikipedia_fr' => $software->get('wikipedia_fr'),
];
dump($alea);
dump($dataForm);
dump($dataInDb);
$this->assertTrue($this->arraysAreSimilar($dataForm, $dataInDb));
// "Person" user with "admin" role
$this->setAdminSessionOfPersonType();
// "Person" user without "admin" role
$this->setConnectedPersonSession();
// "Administration" user without "admin" role
$this->setConnectedAdministrationSession();
// "Administration" user with "admin" role
$this->setAdminSessionOfAdministrationType();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment