PathCheckTest::data()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 23
nc 1
nop 0
dl 0
loc 32
rs 9.552
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lochmueller\LanguageDetection\Tests\Unit\Check;
6
7
use Lochmueller\LanguageDetection\Check\PathCheck;
8
use Lochmueller\LanguageDetection\Event\CheckLanguageDetectionEvent;
9
use Lochmueller\LanguageDetection\Service\SiteConfigurationService;
10
use Lochmueller\LanguageDetection\Tests\Unit\AbstractUnitTest;
11
use TYPO3\CMS\Core\Http\ServerRequest;
12
use TYPO3\CMS\Core\Site\Entity\Site;
13
14
/**
15
 * @internal
16
 *
17
 * @coversNothing
18
 */
19
class PathCheckTest extends AbstractUnitTest
20
{
21
    /**
22
     * @covers \Lochmueller\LanguageDetection\Check\PathCheck
23
     * @covers \Lochmueller\LanguageDetection\Domain\Model\Dto\SiteConfiguration
24
     * @covers \Lochmueller\LanguageDetection\Event\CheckLanguageDetectionEvent
25
     * @covers \Lochmueller\LanguageDetection\Service\SiteConfigurationService
26
     *
27
     * @dataProvider data
28
     *
29
     * @param array<string, bool>|array<string, false>|mixed[] $config
30
     */
31
    public function testPathConfiguration(array $config, string $uri, bool $result): void
32
    {
33
        $site = $this->createStub(Site::class);
34
        $site->method('getConfiguration')->willReturn($config);
35
36
        $request = new ServerRequest($uri, null, 'php://input', []);
37
        $event = new CheckLanguageDetectionEvent($site, $request);
38
39
        $pathCheck = new PathCheck(new SiteConfigurationService());
40
        $pathCheck($event);
41
42
        self::assertEquals($result, $event->isLanguageDetectionEnable());
43
    }
44
45
    /**
46
     * @return array<string, mixed[]>
47
     */
48
    public static function data(): array
49
    {
50
        return [
51
            'allowAllPaths and deeplink' => [
52
                ['allowAllPaths' => true],
53
                'https://www.google.de/deep-link/',
54
                true,
55
            ],
56
            'allowAllPaths and homepage' => [
57
                ['allowAllPaths' => true],
58
                'https://www.google.de/',
59
                true,
60
            ],
61
            'no allowAllPaths and deeplink' => [
62
                ['allowAllPaths' => false],
63
                'https://www.google.de/deep-link-more/',
64
                false,
65
            ],
66
            'no allowAllPaths and homepage' => [
67
                ['allowAllPaths' => false],
68
                'https://www.home-page.de/',
69
                true,
70
            ],
71
            'without allowAllPaths and deeplink' => [
72
                [],
73
                'https://www.google.de/deep-link-next/',
74
                false,
75
            ],
76
            'without allowAllPaths and homepage' => [
77
                [],
78
                'https://www.tester.de/',
79
                true,
80
            ],
81
        ];
82
    }
83
}
84