Skip to content
Snippets Groups Projects
Verified Commit 3593479f authored by Florian Azizian's avatar Florian Azizian
Browse files

FEAT add TU

parent f709dbcd
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
<!--directory>test</directory-->
<file>test/unitTests/app/action/ActionControllerTest.php</file>
<file>test/unitTests/core/AutocompleteControllerTest.php</file>
<file>test/unitTests/core/AuthenticationControllerTest.php</file>
<file>test/unitTests/app/basket/BasketControllerTest.php</file>
<file>test/unitTests/app/contact/ContactControllerTest.php</file>
<file>test/unitTests/app/contact/ContactGroupControllerTest.php</file>
......
......@@ -13,6 +13,70 @@ use PHPUnit\Framework\TestCase;
class AutocompleteControllerTest extends TestCase
{
public function testGetContacts()
{
$autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// GET COLOR
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'search' => 'maarch',
'color' => true
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $autocompleteController->getContacts($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertInternalType('array', $responseBody);
$this->assertNotEmpty($responseBody);
foreach ($responseBody as $value) {
$this->assertSame('contact', $value->type);
$this->assertInternalType('int', $value->id);
$this->assertInternalType('string', $value->contact);
$this->assertInternalType('string', $value->address);
$this->assertInternalType('string', $value->idToDisplay);
$this->assertInternalType('string', $value->otherInfo);
$this->assertSame('#', substr($value->rateColor, 0, 1));
$this->assertInternalType('string', substr($value->rateColor, 0));
$this->assertNotEmpty($value->id);
$this->assertNotEmpty($value->contact);
$this->assertNotEmpty($value->idToDisplay);
$this->assertNotEmpty($value->otherInfo);
$this->assertNotEmpty(substr($value->rateColor, 1));
}
// GET NO COLOR
$aArgs = [
'search' => 'maarch',
'color' => false
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $autocompleteController->getContacts($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertInternalType('array', $responseBody);
$this->assertNotEmpty($responseBody);
foreach ($responseBody as $value) {
$this->assertSame('contact', $value->type);
$this->assertInternalType('int', $value->id);
$this->assertInternalType('string', $value->contact);
$this->assertInternalType('string', $value->address);
$this->assertInternalType('string', $value->idToDisplay);
$this->assertInternalType('string', $value->otherInfo);
$this->assertNotEmpty($value->id);
$this->assertNotEmpty($value->contact);
$this->assertNotEmpty($value->idToDisplay);
$this->assertNotEmpty($value->otherInfo);
$this->assertEmpty($value->rateColor);
}
}
public function testGetContactsForGroups()
{
$autocompleteController = new \SrcCore\controllers\AutoCompleteController();
......@@ -39,6 +103,38 @@ class AutocompleteControllerTest extends TestCase
$this->assertInternalType('string', $responseBody[0]->address);
}
public function testGetContactsAndUsers()
{
$autocompleteController = new \SrcCore\controllers\AutoCompleteController();
// GET
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'search' => 'maarch',
'color' => true,
'onlyContacts' => 'true'
];
$fullRequest = $request->withQueryParams($aArgs);
$response = $autocompleteController->getContactsAndUsers($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
foreach ($responseBody as $value) {
$this->assertInternalType('int', $value->id);
$this->assertInternalType('string', $value->idToDisplay);
$this->assertInternalType('string', $value->otherInfo);
$this->assertNotEmpty($value->type);
$this->assertNotEmpty($value->id);
$this->assertNotEmpty($value->idToDisplay);
$this->assertNotEmpty($value->otherInfo);
if ($value->type == 'contact') {
$this->assertNotEmpty($value->rateColor);
}
}
}
public function testGetUsers()
{
$autocompleteController = new \SrcCore\controllers\AutoCompleteController();
......
......@@ -14,6 +14,31 @@ use PHPUnit\Framework\TestCase;
class CoreControllerTest extends TestCase
{
public function testInitialize()
{
$CoreController = new \SrcCore\controllers\CoreController();
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $CoreController->initialize($request, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertNotEmpty($responseBody->coreUrl);
$this->assertNotEmpty($responseBody->applicationName);
$this->assertNotEmpty($responseBody->applicationMinorVersion);
$version = explode(".", $responseBody->applicationMinorVersion);
$this->assertSame('18', $version[0]);
$this->assertSame('10', $version[1]);
$this->assertInternalType('int', (int)$version[2]);
$this->assertSame('fr', $responseBody->lang);
$this->assertNotEmpty($responseBody->user);
$this->assertInternalType('int', $responseBody->user->id);
$this->assertSame('superadmin', $responseBody->user->user_id);
$this->assertSame('Super', $responseBody->user->firstname);
$this->assertNotEmpty($responseBody->scriptsToinject);
}
public function testGetAdministration()
{
$coreController = new \SrcCore\controllers\CoreController();
......
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