Skip to content
Snippets Groups Projects
Verified Commit 6be49db4 authored by Damien's avatar Damien
Browse files

FEAT #7722 Unit tests + ContactType unit tests

parent 30746e0f
No related branches found
No related tags found
No related merge requests found
......@@ -102,6 +102,73 @@ class ContactGroupControllerTest extends TestCase
$this->assertInternalType('array', $responseBody->contactsGroup->contacts);
}
public function testAddContacts()
{
$contactGroupController = new \Contact\controllers\ContactGroupController();
$contacts = \Contact\models\ContactModel::getOnView([
'select' => ['ca_id'],
'limit' => 1
]);
if (!empty($contacts[0])) {
// UPDATE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'contacts' => [$contacts[0]['ca_id']]
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $contactGroupController->addContacts($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(self::$id, $responseBody->contactsGroup->id);
$this->assertNotEmpty($responseBody->contactsGroup);
$this->assertNotEmpty($responseBody->contactsGroup->contacts);
$this->assertSame($contacts[0]['ca_id'], $responseBody->contactsGroup->contacts[0]->addressId);
$this->assertSame(0, $responseBody->contactsGroup->contacts[0]->position);
$this->assertInternalType('string', $responseBody->contactsGroup->contacts[0]->contact);
$this->assertInternalType('string', $responseBody->contactsGroup->contacts[0]->address);
}
}
public function testDeleteContacts()
{
$contactGroupController = new \Contact\controllers\ContactGroupController();
$contacts = \Contact\models\ContactModel::getOnView([
'select' => ['ca_id'],
'limit' => 1
]);
if (!empty($contacts[0])) {
// UPDATE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $contactGroupController->deleteContact($request, new \Slim\Http\Response(), ['id' => self::$id, 'addressId' => $contacts[0]['ca_id']]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('success', $responseBody->success);
}
// READ
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $contactGroupController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]);
$responseBody = json_decode((string)$response->getBody());
$user = \User\models\UserModel::getByUserId(['select' => ['id'], 'userId' => 'superadmin']);
$this->assertSame(self::$id, $responseBody->contactsGroup->id);
$this->assertSame($user['id'], $responseBody->contactsGroup->owner);
$this->assertSame('superadmin', $responseBody->contactsGroup->entity_owner);
$this->assertInternalType('string', $responseBody->contactsGroup->labelledOwner);
$this->assertInternalType('array', $responseBody->contactsGroup->contacts);
$this->assertEmpty($responseBody->contactsGroup->contacts);
}
public function testDelete()
{
$contactGroupController = new \Contact\controllers\ContactGroupController();
......
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
use PHPUnit\Framework\TestCase;
class ContactTypeControllerTest extends TestCase
{
public function testGet()
{
$contactTypeController = new \Contact\controllers\ContactTypeController();
// GET
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $contactTypeController->get($request, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertInternalType('array', $responseBody->contactsTypes);
$this->assertNotEmpty($responseBody->contactsTypes);
}
}
......@@ -4,10 +4,11 @@
<testsuite name="Maarch Core Test Suite">
<!--directory>core/Test</directory-->
<file>core/Test/ActionControllerTest.php</file>
<file>core/Test/AutocompleteControllerTest.php</file>
<file>core/Test/AutocompleteControllerTest.php</file>
<file>core/Test/BasketControllerTest.php</file>
<file>core/Test/ContactControllerTest.php</file>
<file>core/Test/ContactGroupControllerTest.php</file>
<file>core/Test/ContactTypeControllerTest.php</file>
<file>core/Test/DoctypeControllerTest.php</file>
<file>core/Test/EntityControllerTest.php</file>
<file>core/Test/GroupControllerTest.php</file>
......
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