diff --git a/phpunit.xml b/phpunit.xml index edd581bb897e800ad6c179ca0d7b9ed022a98904..3c14ca419adf6076d27e3fce1ab9e16bf4144be5 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -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> diff --git a/test/unitTests/core/AutocompleteControllerTest.php b/test/unitTests/core/AutocompleteControllerTest.php index 0a1baf61e64d16a3dc26f2cb2d83508cad2e65a3..5d69bc5e438b786655c305e2bdc5f3d2f2ba3a2b 100644 --- a/test/unitTests/core/AutocompleteControllerTest.php +++ b/test/unitTests/core/AutocompleteControllerTest.php @@ -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(); diff --git a/test/unitTests/core/CoreControllerTest.php b/test/unitTests/core/CoreControllerTest.php index 78f906a7f6dc0b0436728321235f0d82d15697e2..356ae9aa5ac0cf324e0215ef364de22c08915b50 100644 --- a/test/unitTests/core/CoreControllerTest.php +++ b/test/unitTests/core/CoreControllerTest.php @@ -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();