Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nextcloud-compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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)

]]></description>
<version>3.4.8</version>
<version>3.4.9</version>
<licence>agpl</licence>
<author mail="benjamin@cybercorp.fr" homepage="https://github.com/baimard">Benjamin AIMARD</author>
<namespace>Gestion</namespace>
Expand Down
10 changes: 9 additions & 1 deletion documentation/source/developer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Bdd/BddTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Bdd/CompanyHistoryAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Bdd/ProviderSecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Bdd/WorkspaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 9 additions & 3 deletions tests/Unit/Ihm/JsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 11 additions & 4 deletions tests/Unit/Panther/initAppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()}}");
39 changes: 39 additions & 0 deletions tests/Unit/Service/BrowserCredentialsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
namespace OCA\Gestion\Tests\Unit\Service;

use OCA\Gestion\Tests\Unit\js\JsTest;
use PHPUnit\Framework\SkippedTestError;
use PHPUnit\Framework\TestCase;

require_once __DIR__ . '/../Ihm/JsTest.php';

class BrowserCredentialsTest extends TestCase {
/** @dataProvider incompleteCredentials */
public function testMissingCredentialsSkipBeforeAnyBrowserIsOpened(?string $username, ?string $password): void {
$variables = ['NEXTCLOUD_TEST_USER' => $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']];
}
}
Loading