diff --git a/.ddev/commands/web/init-typo3 b/.ddev/commands/web/init-typo3 index 58ad7ba..2b6da81 100755 --- a/.ddev/commands/web/init-typo3 +++ b/.ddev/commands/web/init-typo3 @@ -11,7 +11,7 @@ readonly dbUser="db" readonly dbPassword="db" readonly dbName="db" readonly dbCredentials="-h${dbHost} -u${dbUser} -p${dbPassword}" -readonly fixturePath="/var/www/html/Tests/Acceptance/Fixtures" +readonly fixturePath="/var/www/html/Tests/Fixtures" readonly typo3Binary="/var/www/html/vendor/bin/typo3" readonly typo3cmsBinary="/var/www/html/vendor/bin/typo3cms" diff --git a/.gitignore b/.gitignore index 1a92840..c5ec781 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +composer.lock +coverage public/.htaccess public/index.php public/fileadmin diff --git a/Tests/Fixtures/page1.html b/Tests/Fixtures/page1.html new file mode 100644 index 0000000..c63aea8 --- /dev/null +++ b/Tests/Fixtures/page1.html @@ -0,0 +1,13 @@ + + + Page 1 + + +

EXCLUDE FROM CRAWLER

+
+

Page 1

+

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Amet deserunt dolorem, id illo minima necessitatibus optio porro sequi + soluta ullam! Ad aut dignissimos eius ipsa laboriosam necessitatibus sapiente tempore voluptatum.

+
+ + diff --git a/Tests/Fixtures/page2.html b/Tests/Fixtures/page2.html new file mode 100644 index 0000000..f4a1a98 --- /dev/null +++ b/Tests/Fixtures/page2.html @@ -0,0 +1,13 @@ + + + Page 2 + + +

EXCLUDE FROM CRAWLER

+
+

Page 2

+

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Amet deserunt dolorem, id illo minima necessitatibus optio porro sequi + soluta ullam! Ad aut dignissimos eius ipsa laboriosam necessitatibus sapiente tempore voluptatum.

+
+ + diff --git a/Tests/Fixtures/pages.sql b/Tests/Fixtures/pages.sql new file mode 100644 index 0000000..b5a51f0 --- /dev/null +++ b/Tests/Fixtures/pages.sql @@ -0,0 +1,4 @@ +insert into `pages` (`uid`, `pid`, `title`, `slug`, `sys_language_uid`, `l10n_parent`, `l10n_source`, `perms_userid`, + `perms_groupid`, `perms_user`, `perms_group`, `perms_everybody`, `doktype`, `is_siteroot`) +values (1, 0, 'Main', '/', 0, 0, 0, 1, 1, 31, 31, 1, 1, 1), + (2, 1, 'search_data', '/search_data', 0, 0, 0, 1, 1, 31, 31, 1, 254, 0); diff --git a/Tests/Fixtures/sitemap.xml b/Tests/Fixtures/sitemap.xml new file mode 100644 index 0000000..a5b1c9c --- /dev/null +++ b/Tests/Fixtures/sitemap.xml @@ -0,0 +1,12 @@ + + + + 2024-07-10T11:01:00+02:00 + https://xm-kesearch-remote.ddev.site/fileadmin/Fixtures/page1.html + + + 2024-07-10T10:56:00+02:00 + https://xm-kesearch-remote.ddev.site/fileadmin/Fixtures/page2.html + + diff --git a/Tests/Fixtures/sys_template.sql b/Tests/Fixtures/sys_template.sql new file mode 100644 index 0000000..0efbe43 --- /dev/null +++ b/Tests/Fixtures/sys_template.sql @@ -0,0 +1,2 @@ +insert into `sys_template` (`pid`, `title`, `root`, `clear`, `include_static_file`) +values (1, 'MAIN TEMPLATE', 1, 3, 'EXT:bootstrap_package/Configuration/TypoScript,EXT:ke_search/Configuration/TypoScript'); diff --git a/Tests/Fixtures/tx_kesearch_indexerconfig.csv b/Tests/Fixtures/tx_kesearch_indexerconfig.csv new file mode 100644 index 0000000..7f304b6 --- /dev/null +++ b/Tests/Fixtures/tx_kesearch_indexerconfig.csv @@ -0,0 +1,3 @@ +"tx_kesearch_indexerconfig",,,,,,,,,, +,"uid","pid","title","storagepid","type","tx_xmkesearchremote_sitemap","tx_xmkesearchremote_filter","tx_xmkesearchremote_language", +,1,2,"TestIndexer",2,"xmkesearchremote","https://xm-kesearch-remote.ddev.site/fileadmin/Fixtures/sitemap.xml","",-1, diff --git a/Tests/Functional/Command/FetchContentCommandTest.php b/Tests/Functional/Command/FetchContentCommandTest.php new file mode 100644 index 0000000..538a59b --- /dev/null +++ b/Tests/Functional/Command/FetchContentCommandTest.php @@ -0,0 +1,38 @@ + 'fileadmin/Fixtures', + ]; + + private CommandTester $commandTester; + + public function testUrlCrawler(): void + { + $this->importCSVDataSet(__DIR__ . '/../../Fixtures/tx_kesearch_indexerconfig.csv'); + $this->commandTester->execute([]); + } + + protected function setUp(): void + { + parent::setUp(); + + $extensionConfigurationMock = $this->createMock(ExtensionConfiguration::class); + + $command = new FetchContentCommand($extensionConfigurationMock); + $this->commandTester = new CommandTester($command); + } +} diff --git a/composer.json b/composer.json index ab899f3..8ae5793 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,8 @@ } ], "require": { + "symfony/css-selector": "*", + "symfony/dom-crawler": "*", "typo3/cms-core": "^11.0", "tpwd/ke_search": "^4.5" }, @@ -18,7 +20,8 @@ "friendsofphp/php-cs-fixer": "^3.12", "helhum/typo3-console": "* || dev-issue/1169", "saschaegerer/phpstan-typo3": "^1.8", - "symfony/translation": "*" + "symfony/translation": "*", + "typo3/testing-framework": "^7.0" }, "extra": { "typo3/cms": { @@ -30,6 +33,11 @@ "Xima\\XmKesearchRemote\\": "Classes" } }, + "autoload-dev": { + "psr-4": { + "Xima\\XmKesearchRemote\\Tests\\": "Tests" + } + }, "config": { "sort-packages": true, "allow-plugins": { @@ -41,6 +49,7 @@ "php:fixer": "php-cs-fixer --config=php-cs-fixer.php fix", "php:stan": "phpstan --generate-baseline=phpstan-baseline.neon --allow-empty-baseline", "xml:lint": "find . -name '*.xlf' ! -path './vendor/*' ! -path './var/*' ! -path './public/*' | xargs -r xmllint --schema vendor/symfony/translation/Resources/schemas/xliff-core-1.2-transitional.xsd --noout", + "test:functional": "phpunit -c phpunit.functional.xml --no-coverage", "ci:test:unit": "XDEBUG_MODE=coverage && phpunit -c phpunit.unit.xml", "ci:test:functional": "XDEBUG_MODE=coverage && phpunit -c phpunit.functional.xml", "ci:test:acceptance": "XDEBUG_MODE=coverage && codecept run Acceptance --coverage --coverage-xml", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 0edba52..8a0be60 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,25 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Call to method children\\(\\) on an unknown class Symfony\\\\Component\\\\DomCrawler\\\\Crawler\\.$#" - count: 2 - path: Classes/Command/FetchContentCommand.php - - - - message: "#^Call to method filter\\(\\) on an unknown class Symfony\\\\Component\\\\DomCrawler\\\\Crawler\\.$#" - count: 3 - path: Classes/Command/FetchContentCommand.php - - - - message: "#^Instantiated class Symfony\\\\Component\\\\DomCrawler\\\\Crawler not found\\.$#" - count: 3 - path: Classes/Command/FetchContentCommand.php - - - - message: "#^Parameter \\$parentCrawler of anonymous function has invalid type Symfony\\\\Component\\\\DomCrawler\\\\Crawler\\.$#" - count: 1 - path: Classes/Command/FetchContentCommand.php - - message: "#^Property Xima\\\\XmKesearchRemote\\\\Indexer\\\\RemoteIndexer\\:\\:\\$logger is unused\\.$#" count: 1 diff --git a/phpunit.functional.xml b/phpunit.functional.xml new file mode 100644 index 0000000..7bd8c86 --- /dev/null +++ b/phpunit.functional.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + Tests/Functional + + + + + + + + Classes + + + diff --git a/phpunit.unit.xml b/phpunit.unit.xml new file mode 100644 index 0000000..c951c12 --- /dev/null +++ b/phpunit.unit.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + Tests/Unit + + + + + + + + Classes + + +