Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests #6

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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 .ddev/commands/web/init-typo3
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
composer.lock
coverage
public/.htaccess
public/index.php
public/fileadmin
Expand Down
13 changes: 13 additions & 0 deletions Tests/Fixtures/page1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<html lang="en">
<head>
<title>Page 1</title>
</head>
<body>
<p>EXCLUDE FROM CRAWLER</p>
<div class="">
<h1>Page 1</h1>
<p>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.</p>
</div>
</body>
</html>
13 changes: 13 additions & 0 deletions Tests/Fixtures/page2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<html lang="en">
<head>
<title>Page 2</title>
</head>
<body>
<p>EXCLUDE FROM CRAWLER</p>
<div class="">
<h1>Page 2</h1>
<p>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.</p>
</div>
</body>
</html>
4 changes: 4 additions & 0 deletions Tests/Fixtures/pages.sql
Original file line number Diff line number Diff line change
@@ -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);
12 changes: 12 additions & 0 deletions Tests/Fixtures/sitemap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<lastmod>2024-07-10T11:01:00+02:00</lastmod>
<loc>https://xm-kesearch-remote.ddev.site/fileadmin/Fixtures/page1.html</loc>
</url>
<url>
<lastmod>2024-07-10T10:56:00+02:00</lastmod>
<loc>https://xm-kesearch-remote.ddev.site/fileadmin/Fixtures/page2.html</loc>
</url>
</urlset>
2 changes: 2 additions & 0 deletions Tests/Fixtures/sys_template.sql
Original file line number Diff line number Diff line change
@@ -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');
3 changes: 3 additions & 0 deletions Tests/Fixtures/tx_kesearch_indexerconfig.csv
Original file line number Diff line number Diff line change
@@ -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,
38 changes: 38 additions & 0 deletions Tests/Functional/Command/FetchContentCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Xima\XmKesearchRemote\Tests\Functional\Command;

use Symfony\Component\Console\Tester\CommandTester;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
use Xima\XmKesearchRemote\Command\FetchContentCommand;

class FetchContentCommandTest extends FunctionalTestCase
{
protected array $testExtensionsToLoad = [
'typo3conf/ext/ke_search',
'typo3conf/ext/xm_kesearch_remote',
];

protected array $pathsToProvideInTestInstance = [
'typo3conf/ext/xm_kesearch_remote/Tests/Fixtures' => '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);
}
}
11 changes: 10 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
}
],
"require": {
"symfony/css-selector": "*",
"symfony/dom-crawler": "*",
"typo3/cms-core": "^11.0",
"tpwd/ke_search": "^4.5"
},
Expand All @@ -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": {
Expand All @@ -30,6 +33,11 @@
"Xima\\XmKesearchRemote\\": "Classes"
}
},
"autoload-dev": {
"psr-4": {
"Xima\\XmKesearchRemote\\Tests\\": "Tests"
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
Expand All @@ -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",
Expand Down
20 changes: 0 additions & 20 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -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
Expand Down
35 changes: 35 additions & 0 deletions phpunit.functional.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
backupGlobals="true"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php"
cacheResult="false"
colors="true"
failOnRisky="true"
failOnWarning="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
>
<coverage>
<report>
<clover outputFile="coverage/clover-functional.xml"/>
<text outputFile="php://stdout" showOnlySummary="true"/>
</report>
</coverage>
<testsuites>
<testsuite name="functional">
<directory>Tests/Functional</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="coverage/functional/unit.xml"/>
</logging>
<source>
<include>
<directory>Classes</directory>
</include>
</source>
</phpunit>
27 changes: 27 additions & 0 deletions phpunit.unit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="true"
bootstrap="vendor/typo3/testing-framework/Resources/Core/Build/UnitTestsBootstrap.php"
colors="true"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
>
<coverage>
<report>
<clover outputFile="coverage/clover-unit.xml"/>
<text outputFile="php://stdout" showOnlySummary="true"/>
</report>
</coverage>
<testsuites>
<testsuite name="unit">
<directory>Tests/Unit</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="coverage/junit/unit.xml"/>
</logging>
<source>
<include>
<directory>Classes</directory>
</include>
</source>
</phpunit>