No known key found for this signature in database
GPG 키 ID: 4B7724C136BF1D89
13개의 변경된 파일과 351개의 추가작업 그리고 5404개의 파일을 삭제
-
13composer.json
-
5399composer.lock
-
6config/application.config.php
-
36phpunit.xml
-
38tests/Functional/AbstractFunctionalTestCase.php
-
136tests/Functional/Controller/ApiAdminUsersControllerTest.php
-
13tests/bootstrap.php
-
0tests/config/data/LazyServices/Proxy/.gitkeep
-
0tests/config/data/cache/.gitkeep
-
85tests/config/local.php
-
17tests/scripts/setup_db.sh
-
8vagrant/README.rst
-
4vagrant/bootstrap.sh
5399
composer.lock
파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
파일 보기
파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
파일 보기
@ -0,0 +1,36 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<phpunit bootstrap="tests/bootstrap.php" |
|||
beStrictAboutCoversAnnotation="true" |
|||
beStrictAboutOutputDuringTests="true" |
|||
beStrictAboutTestsThatDoNotTestAnything="true" |
|||
beStrictAboutTodoAnnotatedTests="true" |
|||
forceCoversAnnotation="true" |
|||
verbose="true"> |
|||
|
|||
<testsuites> |
|||
<testsuite name="Functional"> |
|||
<directory suffix="Test.php">tests/Functional</directory> |
|||
</testsuite> |
|||
|
|||
<testsuite name="Integration"> |
|||
<directory suffix="Test.php">tests/Integration</directory> |
|||
</testsuite> |
|||
|
|||
<testsuite name="Unit"> |
|||
<directory suffix="Test.php">tests/Unit</directory> |
|||
</testsuite> |
|||
</testsuites> |
|||
|
|||
<!-- |
|||
<logging> |
|||
<log type="coverage-html" target="coverage"/> |
|||
</logging> |
|||
--> |
|||
|
|||
<filter> |
|||
<whitelist> |
|||
<directory suffix=".php">module/Monarc/Core/src</directory> |
|||
<directory suffix=".php">module/Monarc/FrontOffice/src</directory> |
|||
</whitelist> |
|||
</filter> |
|||
</phpunit> |
|||
@ -0,0 +1,38 @@ |
|||
<?php declare(strict_types=1); |
|||
|
|||
namespace MonarcAppFo\Tests\Functional; |
|||
|
|||
use Laminas\ServiceManager\ServiceManager; |
|||
use Laminas\Test\PHPUnit\Controller\AbstractHttpControllerTestCase; |
|||
|
|||
abstract class AbstractFunctionalTestCase extends AbstractHttpControllerTestCase |
|||
{ |
|||
protected function setUp(): void |
|||
{ |
|||
$this->setApplicationConfig(require dirname(__DIR__) . '/../config/application.config.php'); |
|||
|
|||
parent::setUp(); |
|||
|
|||
$this->configureServiceManager($this->getApplicationServiceLocator()); |
|||
} |
|||
|
|||
protected function tearDown(): void |
|||
{ |
|||
// TODO: clear the db data.
|
|||
} |
|||
|
|||
public static function setUpBeforeClass(): void |
|||
{ |
|||
// Creates the DB with initial data, executes all the migrations.
|
|||
shell_exec(getenv('TESTS_DIR') . '/scripts/setup_db.sh'); |
|||
} |
|||
|
|||
public static function tearDownAfterClass(): void |
|||
{ |
|||
// TODO: drop the database or clear the phinxlog table and all the data.
|
|||
} |
|||
|
|||
protected function configureServiceManager(ServiceManager $serviceManager) |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,136 @@ |
|||
<?php declare(strict_types=1); |
|||
|
|||
namespace MonarcAppFo\Tests\Functional\Controller; |
|||
|
|||
use Monarc\Core\Model\Table\UserTable; |
|||
use Monarc\Core\Service\AuthenticationService; |
|||
use Monarc\Core\Service\ConnectedUserService; |
|||
use Monarc\Core\Model\Entity\UserRole; |
|||
use Monarc\FrontOffice\Controller\ApiAdminUsersController; |
|||
use Monarc\FrontOffice\Model\Entity\User; |
|||
use MonarcAppFo\Tests\Functional\AbstractFunctionalTestCase; |
|||
use PHPUnit\Framework\MockObject\MockObject; |
|||
use Laminas\Http\Header\HeaderInterface; |
|||
use Laminas\ServiceManager\ServiceManager; |
|||
|
|||
class ApiAdminUsersControllerTest extends AbstractFunctionalTestCase |
|||
{ |
|||
//protected $traceError = false;
|
|||
|
|||
/** @var ConnectedUserService */ |
|||
private $connectedUserService; |
|||
|
|||
/** @var AuthenticationService|MockObject */ |
|||
private $authenticationService; |
|||
|
|||
protected function configureServiceManager(ServiceManager $serviceManager) |
|||
{ |
|||
$serviceManager->setAllowOverride(true); |
|||
|
|||
$this->connectedUserService = $this->createMock(ConnectedUserService::class); |
|||
$serviceManager->setService(ConnectedUserService::class, $this->connectedUserService); |
|||
|
|||
$this->authenticationService = $this->createMock(AuthenticationService::class); |
|||
$serviceManager->setService(AuthenticationService::class, $this->authenticationService); |
|||
|
|||
$serviceManager->setAllowOverride(false); |
|||
} |
|||
|
|||
public function testUserCreationByAdminUser() |
|||
{ |
|||
$user = $this->createMock(User::class); |
|||
$user->method('getRoles')->willReturn([UserRole::SUPER_ADMIN_FO]); |
|||
$user->method('getId')->willReturn(1); |
|||
|
|||
$this->connectedUserService->method('getConnectedUser')->willReturn($user); |
|||
$header = $this->createMock(HeaderInterface::class); |
|||
$header->method('getFieldName')->willReturn('token'); |
|||
$header->method('getFieldValue')->willReturn('token-value'); |
|||
$this->getRequest()->getHeaders()->addHeader($header); |
|||
|
|||
$this->authenticationService |
|||
->expects($this->once()) |
|||
->method('checkConnect') |
|||
->with(['token' => 'token-value']) |
|||
->willReturn(true); |
|||
|
|||
$email = 'testlast@gmail.com'; |
|||
|
|||
$this->dispatch('/api/users', 'POST', [ |
|||
'firstname' => 'test', |
|||
'lastname' => 'testlast', |
|||
'email' => $email, |
|||
'role' => [UserRole::USER_FO], |
|||
], true); |
|||
|
|||
$this->assertModuleName('Monarc'); |
|||
$this->assertControllerName(ApiAdminUsersController::class); |
|||
$this->assertMatchedRouteName('monarc_api_admin_users'); |
|||
$this->assertResponseStatusCode(200); |
|||
$this->assertEquals('{"status":"ok"}', $this->getResponse()->getContent()); |
|||
|
|||
$this->removeTestUser($email); |
|||
} |
|||
|
|||
public function testUserCreationFailsWhenEmailIsAlreadyExist() |
|||
{ |
|||
$user = $this->createMock(User::class); |
|||
$user->method('getRoles')->willReturn([UserRole::SUPER_ADMIN_FO]); |
|||
$user->method('getId')->willReturn(1); |
|||
|
|||
$this->connectedUserService->method('getConnectedUser')->willReturn($user); |
|||
$header = $this->createMock(HeaderInterface::class); |
|||
$header->method('getFieldName')->willReturn('token'); |
|||
$header->method('getFieldValue')->willReturn('token-value'); |
|||
$this->getRequest()->getHeaders()->addHeader($header); |
|||
|
|||
$this->authenticationService |
|||
->expects($this->once()) |
|||
->method('checkConnect') |
|||
->with(['token' => 'token-value']) |
|||
->willReturn(true); |
|||
|
|||
$email = 'testlast@gmail.com'; |
|||
|
|||
$this->createTestUser($email); |
|||
|
|||
$this->dispatch('/api/users', 'POST', [ |
|||
'firstname' => 'test', |
|||
'lastname' => 'testlast', |
|||
'email' => $email, |
|||
'role' => [UserRole::USER_FO], |
|||
], true); |
|||
|
|||
$this->assertModuleName('Monarc'); |
|||
$this->assertControllerName(ApiAdminUsersController::class); |
|||
$this->assertMatchedRouteName('monarc_api_admin_users'); |
|||
$this->assertResponseStatusCode(400); |
|||
$this->assertStringContainsString('This email is already used', $this->getResponse()->getContent()); |
|||
|
|||
$this->removeTestUser($email); |
|||
} |
|||
|
|||
protected function createTestUser(string $email): User |
|||
{ |
|||
/** @var UserTable $userTable */ |
|||
$userTable = $this->getApplicationServiceLocator()->get(UserTable::class); |
|||
$user = new User([ |
|||
'email' => $email, |
|||
'firstname' => 'firstname', |
|||
'lastname' => 'lastname', |
|||
'language' => 'fr', |
|||
'creator' => 'Test', |
|||
'role' => [], |
|||
]); |
|||
$userTable->saveEntity($user); |
|||
|
|||
return $user; |
|||
} |
|||
|
|||
protected function removeTestUser(string $email): void |
|||
{ |
|||
/** @var UserTable $userTable */ |
|||
$userTable = $this->getApplicationServiceLocator()->get(UserTable::class); |
|||
$userTable->deleteEntity($userTable->findByEmail($email)); |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
<?php declare(strict_types=1); |
|||
|
|||
chdir(dirname(__DIR__)); |
|||
|
|||
if (date_default_timezone_get() !== ini_get('date.timezone')) { |
|||
date_default_timezone_set('Europe/Luxembourg'); |
|||
} |
|||
|
|||
putenv('APP_CONF_DIR=' . dirname(__DIR__) . '/tests/config'); |
|||
putenv('TESTS_DIR=' . dirname(__DIR__) . '/tests'); |
|||
putenv('APPLICATION_ENV=testing'); |
|||
|
|||
require dirname(__DIR__) . '/vendor/autoload.php'; |
|||
@ -0,0 +1,85 @@ |
|||
<?php |
|||
|
|||
use Doctrine\DBAL\Driver\PDOSqlite\Driver; |
|||
|
|||
$appdir = dirname(__DIR__); |
|||
|
|||
return [ |
|||
'doctrine' => [ |
|||
'connection' => [ |
|||
'orm_default' => [ |
|||
'params' => array( |
|||
'host' => 'localhost', |
|||
'user' => 'sqlmonarcuser', |
|||
'password' => 'sqlmonarcuser', |
|||
'dbname' => 'monarc_common_test', |
|||
'port' => 3306, |
|||
), |
|||
], |
|||
'orm_cli' => [ |
|||
'params' => array( |
|||
'host' => 'localhost', |
|||
'user' => 'sqlmonarcuser', |
|||
'password' => 'sqlmonarcuser', |
|||
'dbname' => 'monarc_cli_test', |
|||
'port' => 3306, |
|||
), |
|||
], |
|||
], |
|||
'entitymanager' => [ |
|||
'orm_default' => [ |
|||
'connection' => 'orm_default', |
|||
'configuration' => 'orm_default' |
|||
], |
|||
'orm_cli' => [ |
|||
'connection' => 'orm_cli', |
|||
'configuration' => 'orm_cli', |
|||
], |
|||
], |
|||
'configuration' => [ |
|||
'orm_default' => [ |
|||
'metadata_cache' => 'array', |
|||
'query_cache' => 'array', |
|||
'result_cache' => 'array', |
|||
'driver' => 'orm_default', |
|||
'generate_proxies' => false, |
|||
'filters' => [], |
|||
'datetime_functions' => [], |
|||
'string_functions' => [], |
|||
'numeric_functions' => [], |
|||
'second_level_cache' => [], |
|||
], |
|||
'orm_cli' => [ |
|||
'metadata_cache' => 'array', |
|||
'query_cache' => 'array', |
|||
'result_cache' => 'array', |
|||
'driver' => 'orm_cli', |
|||
'generate_proxies' => false, |
|||
'filters' => [], |
|||
'datetime_functions' => [], |
|||
'string_functions' => [], |
|||
'numeric_functions' => [], |
|||
'second_level_cache' => [], |
|||
], |
|||
], |
|||
], |
|||
|
|||
'activeLanguages' => ['fr', 'en', 'de', 'nl',], |
|||
|
|||
'appVersion' => '3.0.0', |
|||
|
|||
'checkVersion' => false, |
|||
'appCheckingURL' => 'https://version.monarc.lu/check/MONARC', |
|||
|
|||
'email' => [ |
|||
'name' => 'MONARC', |
|||
'from' => 'info@monarc.lu', |
|||
], |
|||
|
|||
'mospApiUrl' => 'https://objects.monarc.lu/api/v1/', |
|||
|
|||
'monarc' => [ |
|||
'ttl' => 60, |
|||
'salt' => '', |
|||
], |
|||
]; |
|||
@ -0,0 +1,17 @@ |
|||
#!/bin/bash |
|||
|
|||
DBUSER_MONARC='sqlmonarcuser' |
|||
DBPASSWORD_MONARC="sqlmonarcuser" |
|||
|
|||
mysql -u $DBUSER_MONARC -p$DBPASSWORD_MONARC -e "CREATE DATABASE IF NOT EXISTS monarc_cli_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;" > /dev/null |
|||
|
|||
# Check if the database is already exist we don't need to create the structure and import the data. |
|||
if ! mysql -u $DBUSER_MONARC -p$DBPASSWORD_MONARC -e 'use monarc_common_test'; then |
|||
mysql -u $DBUSER_MONARC -p$DBPASSWORD_MONARC -e "CREATE DATABASE monarc_common_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;" > /dev/null |
|||
mysql -u $DBUSER_MONARC -p$DBPASSWORD_MONARC monarc_common_test < db-bootstrap/monarc_structure.sql > /dev/null |
|||
mysql -u $DBUSER_MONARC -p$DBPASSWORD_MONARC monarc_common_test < db-bootstrap/monarc_data.sql > /dev/null |
|||
fi |
|||
|
|||
php bin/phinx migrate -c tests/migrations/phinx_core.php |
|||
|
|||
php bin/phinx migrate -c tests/migrations/phinx_frontoffice.php |
|||
쓰기
미리보기
불러오는 중...
취소
저장
Reference in new issue