diff --git a/.github/workflows/nextcloud-compatibility.yml b/.github/workflows/nextcloud-compatibility.yml index 5ce8f094..b9a011e5 100644 --- a/.github/workflows/nextcloud-compatibility.yml +++ b/.github/workflows/nextcloud-compatibility.yml @@ -86,7 +86,7 @@ jobs: - name: Run PHP unit and database tests working-directory: nextcloud/apps/gestion - run: vendor/bin/phpunit --colors=always --testdox tests/Unit/Controller tests/Unit/Bdd tests/Unit/Service + run: vendor/bin/phpunit --colors=always --testdox --testsuite Controller,Bdd,Service - name: Check Nextcloud logs if: always() diff --git a/appinfo/info.xml b/appinfo/info.xml index a889023f..d598a6da 100755 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -29,7 +29,7 @@ If you require adaptations to comply with your country's regulations, please ope [![Donate](https://img.shields.io/badge/Donate-Buy%20me%20a%20coffee-yellow.svg)](https://www.buymeacoffee.com/benjaminaimard) ]]> - 3.4.8 + 3.4.9 agpl Benjamin AIMARD Gestion diff --git a/documentation/source/developer.rst b/documentation/source/developer.rst index 431c2da3..a1b62a8c 100644 --- a/documentation/source/developer.rst +++ b/documentation/source/developer.rst @@ -64,6 +64,14 @@ Commandes courantes Tests Panther ------------- +Les scénarios de connexion ``tests/Unit/Ihm/JsTest.php``, +``tests/Unit/Panther/IhmTest.php`` et ``tests/Unit/Panther/initAppTest.php`` +exigent des identifiants fournis par variables d'environnement. Aucun compte +de secours n'est utilisé. Sans les deux identifiants, ``JsTest`` est ignoré +par PHPUnit et les scripts autonomes s'arrêtent avant d'ouvrir un navigateur. +Utilisez exclusivement une instance et un compte jetables de test ; ne +commitez jamais leurs identifiants dans le dépôt. + Les tests utilisent les variables suivantes : ``NEXTCLOUD_BASE_URL`` @@ -73,7 +81,7 @@ Les tests utilisent les variables suivantes : Compte Nextcloud de test obligatoire. ``NEXTCLOUD_TEST_PASSWORD`` - Mot de passe du compte de test. + Mot de passe obligatoire du compte de test. ``NEXTCLOUD_TEST_COMPANY_ID`` Identifiant de la société de démonstration, affiché par le script de préparation. diff --git a/package-lock.json b/package-lock.json index 9a5375e7..ca46d677 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gestion", - "version": "3.4.8", + "version": "3.4.9", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "gestion", - "version": "3.4.8", + "version": "3.4.9", "license": "AGPL-3.0-or-later", "devDependencies": { "@nextcloud/dialogs": "^7.4.0", diff --git a/package.json b/package.json index 99c5eb39..b0fa6490 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gestion", - "version": "3.4.8", + "version": "3.4.9", "description": "Application pour gérer votre micro entreprise, client, facture, devis", "author": "Benjamin AIMARD", "contributors": [ diff --git a/tests/Unit/Bdd/BddTest.php b/tests/Unit/Bdd/BddTest.php index 9b4a3007..edab4788 100755 --- a/tests/Unit/Bdd/BddTest.php +++ b/tests/Unit/Bdd/BddTest.php @@ -17,7 +17,7 @@ class BddTest extends TestCase { public function setUp(): void{ parent::setUp(); - $myDb = \OC::$server->getDatabaseConnection(); + $myDb = \OCP\Server::get(\OCP\IDBConnection::class); $l = $this->createMock('OCP\IL10N'); $this->db = new Bdd($myDb,$l); diff --git a/tests/Unit/Bdd/CompanyHistoryAccessTest.php b/tests/Unit/Bdd/CompanyHistoryAccessTest.php index 78353ce7..872023a3 100644 --- a/tests/Unit/Bdd/CompanyHistoryAccessTest.php +++ b/tests/Unit/Bdd/CompanyHistoryAccessTest.php @@ -16,7 +16,7 @@ class CompanyHistoryAccessTest extends TestCase { private int $foreignCompany; protected function setUp(): void { - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OCP\Server::get(\OCP\IDBConnection::class); $this->connection->beginTransaction(); $this->owner = 'history-owner-' . bin2hex(random_bytes(6)); $this->other = 'history-other-' . bin2hex(random_bytes(6)); diff --git a/tests/Unit/Bdd/ProviderSecurityTest.php b/tests/Unit/Bdd/ProviderSecurityTest.php index 8c137005..60abd21e 100644 --- a/tests/Unit/Bdd/ProviderSecurityTest.php +++ b/tests/Unit/Bdd/ProviderSecurityTest.php @@ -15,7 +15,7 @@ class ProviderSecurityTest extends TestCase { private string $owner; private array $credentials = ['client_id'=>'fixture-id','client_secret'=>'never-return-this-secret','customer_id'=>'fixture-customer','base_url'=>'https://api.example.com','auth_url'=>'https://auth.example.com/token']; protected function setUp(): void { - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OCP\Server::get(\OCP\IDBConnection::class); $this->connection->beginTransaction(); $l = $this->createMock(IL10N::class); $this->owner = 'security-test-'.bin2hex(random_bytes(6)); diff --git a/tests/Unit/Bdd/WorkspaceTest.php b/tests/Unit/Bdd/WorkspaceTest.php index 75da53ef..cfb823ad 100644 --- a/tests/Unit/Bdd/WorkspaceTest.php +++ b/tests/Unit/Bdd/WorkspaceTest.php @@ -13,7 +13,7 @@ class WorkspaceTest extends TestCase { private string $owner; protected function setUp(): void { - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OCP\Server::get(\OCP\IDBConnection::class); $this->connection->beginTransaction(); $l = $this->createMock(IL10N::class); $l->method('t')->willReturnCallback(fn ($text) => $text); diff --git a/tests/Unit/Ihm/JsTest.php b/tests/Unit/Ihm/JsTest.php index b78ee090..87739d97 100755 --- a/tests/Unit/Ihm/JsTest.php +++ b/tests/Unit/Ihm/JsTest.php @@ -11,13 +11,19 @@ class JsTest extends PantherTestCase { private string $password; public function setUp(): void { + $username = getenv('NEXTCLOUD_TEST_USER'); + $password = getenv('NEXTCLOUD_TEST_PASSWORD'); + if (!$username || !$password) { + $this->markTestSkipped('Set NEXTCLOUD_TEST_USER and NEXTCLOUD_TEST_PASSWORD for a disposable Nextcloud test account.'); + } + parent::setUp(); $this->url = rtrim( - getenv('NEXTCLOUD_BASE_URL') ?: 'http://dev.cybercorp.fr', + getenv('NEXTCLOUD_BASE_URL') ?: 'http://127.0.0.1:8080', '/' ); - $this->username = getenv('NEXTCLOUD_TEST_USER') ?: 'nextcloud'; - $this->password = getenv('NEXTCLOUD_TEST_PASSWORD') ?: 'Gestion-Panther-2026!'; + $this->username = $username; + $this->password = $password; } public function testClient(): void { diff --git a/tests/Unit/Panther/initAppTest.php b/tests/Unit/Panther/initAppTest.php index 17e51814..40dae403 100755 --- a/tests/Unit/Panther/initAppTest.php +++ b/tests/Unit/Panther/initAppTest.php @@ -3,17 +3,24 @@ use Symfony\Component\Panther\Client; require __DIR__.'/../../../vendor/autoload.php'; +$baseUrl = rtrim(getenv('NEXTCLOUD_BASE_URL') ?: 'http://127.0.0.1:8080', '/'); +$username = getenv('NEXTCLOUD_TEST_USER'); +$password = getenv('NEXTCLOUD_TEST_PASSWORD'); +if (!$username || !$password) { + throw new RuntimeException('Set NEXTCLOUD_TEST_USER and NEXTCLOUD_TEST_PASSWORD for a disposable Nextcloud test account.'); +} + $client = Client::createFirefoxClient(); -$crawler = $client->request('GET', 'http://127.0.0.1/index.php/apps/gestion'); +$crawler = $client->request('GET', $baseUrl . '/index.php/apps/gestion'); $form = $crawler->selectButton('Log in')->form(); -$form['user'] = 'nextcloud'; -$form['password'] = 'nextcloud'; +$form['user'] = $username; +$form['password'] = $password; $client->submit($form); sleep(5); $client->executeScript("document.getElementById('firstrunwizard').getElementsByClassName('header-close')[0].click()"); -$client->request('GET', 'http://127.0.0.1/settings/apps/organization'); +$client->request('GET', $baseUrl . '/settings/apps/organization'); $client->executeScript("var els = document.getElementsByClassName('app-name');for(var i = 0; i < els.length; i++){if(els[i].innerHTML.indexOf('Gestion') > -1){els[i].parentNode.getElementsByClassName('enable')[0].click()}}"); \ No newline at end of file diff --git a/tests/Unit/Service/BrowserCredentialsTest.php b/tests/Unit/Service/BrowserCredentialsTest.php new file mode 100644 index 00000000..2cf02975 --- /dev/null +++ b/tests/Unit/Service/BrowserCredentialsTest.php @@ -0,0 +1,39 @@ + $username, 'NEXTCLOUD_TEST_PASSWORD' => $password]; + $previous = []; + foreach ($variables as $name => $value) { + $previous[$name] = getenv($name); + putenv($value === null ? $name : $name . '=' . $value); + } + + try { + $test = new JsTest('testClient'); + try { + $test->setUp(); + $this->fail('The browser scenario must not use fallback credentials.'); + } catch (SkippedTestError $exception) { + $this->assertStringContainsString('NEXTCLOUD_TEST_USER', $exception->getMessage()); + $this->assertStringContainsString('NEXTCLOUD_TEST_PASSWORD', $exception->getMessage()); + } + } finally { + foreach ($previous as $name => $value) { + putenv($value === false ? $name : $name . '=' . $value); + } + } + } + + public function incompleteCredentials(): array { + return [[null, null], ['browser-test-user', null], [null, 'browser-test-password']]; + } +}