diff --git a/lib/Datasource/AnalyticsDatasource.php b/lib/Analytics/AnalyticsDatasource.php similarity index 91% rename from lib/Datasource/AnalyticsDatasource.php rename to lib/Analytics/AnalyticsDatasource.php index 4bc4607a36..ce43b49bdf 100644 --- a/lib/Datasource/AnalyticsDatasource.php +++ b/lib/Analytics/AnalyticsDatasource.php @@ -9,7 +9,7 @@ * @author Marcel Scherello */ -namespace OCA\Forms\Datasource; +namespace OCA\Forms\Analytics; /** @psalm-suppress UndefinedClass */ use OCA\Analytics\Datasource\IDatasource; @@ -20,21 +20,15 @@ use Psr\Log\LoggerInterface; class AnalyticsDatasource implements IDatasource { - private LoggerInterface $logger; - private IL10N $l10n; - protected ?string $userId; public function __construct( - IL10N $l10n, - LoggerInterface $logger, - ?string $userId, - private FormMapper $formMapper, - private FormsService $formsService, - private SubmissionService $submissionService + protected ?string $userId, + private IL10N $l10n, + private LoggerInterface $logger, + private FormMapper $formMapper, + private FormsService $formsService, + private SubmissionService $submissionService, ) { - $this->l10n = $l10n; - $this->logger = $logger; - $this->userId = $userId; } /** diff --git a/lib/Listener/AnalyticsDatasourceListener.php b/lib/Listener/AnalyticsDatasourceListener.php index b67cdc14f5..b791f4e464 100644 --- a/lib/Listener/AnalyticsDatasourceListener.php +++ b/lib/Listener/AnalyticsDatasourceListener.php @@ -13,7 +13,7 @@ namespace OCA\Forms\Listener; use OCA\Analytics\Datasource\DatasourceEvent; -use OCA\Forms\Datasource\AnalyticsDatasource; +use OCA\Forms\Analytics\AnalyticsDatasource; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; diff --git a/tests/Unit/Analytics/AnalyticsDatasourceTest.php b/tests/Unit/Analytics/AnalyticsDatasourceTest.php new file mode 100644 index 0000000000..fabfb0ebe8 --- /dev/null +++ b/tests/Unit/Analytics/AnalyticsDatasourceTest.php @@ -0,0 +1,77 @@ + + * + * @author Ferdinand Thiessen + * + * @license AGPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +namespace OCA\Forms\Tests\Unit\Analytics; + +use OCA\Forms\Analytics\AnalyticsDatasource; +use OCA\Forms\Db\FormMapper; +use OCA\Forms\Service\FormsService; +use OCA\Forms\Service\SubmissionService; +use OCP\IL10N; +use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; +use Test\TestCase; + +class AnalyticsDatasourceTest extends TestCase { + + private AnalyticsDatasource $dataSource; + + private IL10N|MockObject $l10n; + private LoggerInterface|MockObject $logger; + private FormMapper|MockObject $formMapper; + private FormsService|MockObject $formsService; + private SubmissionService|MockObject $submissionService; + + public function setUp(): void { + parent::setUp(); + $this->l10n = $this->createMock(IL10N::class); + $this->logger = $this->createMock(LoggerInterface::class); + $this->formMapper = $this->createMock(FormMapper::class); + $this->formsService = $this->createMock(FormsService::class); + $this->submissionService = $this->createMock(SubmissionService::class); + + $this->dataSource = new AnalyticsDatasource( + null, + $this->l10n, + $this->logger, + $this->formMapper, + $this->formsService, + $this->submissionService, + ); + } + + public function testGetName() { + $this->l10n + ->expects($this->any()) + ->method('t') + ->willReturnCallback(fn (string $str) => $str); + $this->assertEquals('Nextcloud Forms', $this->dataSource->getName()); + } + + public function testGetId() { + $this->assertEquals(66, $this->dataSource->getId()); + } + + // TODO: Write tests for `getTemplate` and `readData` +}