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

Add more func tests #36

Merged
merged 7 commits into from
Sep 22, 2023
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
4 changes: 4 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ services:
JWeiland\Replacer\:
resource: '../Classes/*'

# Called by makeInstance in tslib/class.tslib_fe.php Hook
JWeiland\Replacer\Hook\TypoScriptFrontendControllerHook:
public: true

# Event Listener Configuration
# This event listener is implemented for replacing the Hook implementation which is removed in TYPO3 12LTS
# the implementation is same as the ReplaceContent Middleware (which only replace for USER_INT Plugins)
Expand Down
5 changes: 5 additions & 0 deletions Documentation/ChangeLog/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
ChangeLog
=========

Version 3.0.3
=============

* [TASK] Add a lot more func. tests

Version 3.0.2
=============

Expand Down
2 changes: 1 addition & 1 deletion Documentation/Settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[general]

project = Replacer
version = 3.0.2
version = 3.0.3
release = 3.0
copyright = by jweiland.net & Contributors

Expand Down
101 changes: 101 additions & 0 deletions Tests/Functional/Configuration/ReplaceConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package jweiland/replacer.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace JWeiland\Replacer\Tests\Functional\Configuration;

use JWeiland\Replacer\Configuration\ReplaceConfiguration;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

final class ReplaceConfigurationTest extends FunctionalTestCase
{
protected ReplaceConfiguration $subject;

protected array $testExtensionsToLoad = [
'jweiland/replacer',
];

protected function setUp(): void
{
parent::setUp();

$this->subject = new ReplaceConfiguration();
}

/**
* @test
*/
public function getSearchValueInitiallyReturnsEmptyString(): void
{
self::assertSame(
'',
$this->subject->getSearchValue()
);
}

/**
* @test
*/
public function setSearchValueWillSetSearchValue(): void
{
$this->subject->setSearchValue('foo bar');

self::assertSame(
'foo bar',
$this->subject->getSearchValue()
);
}

/**
* @test
*/
public function getReplaceValueInitiallyReturnsEmptyString()
{
self::assertSame(
'',
$this->subject->getReplaceValue()
);
}

/**
* @test
*/
public function setReplaceValueSetsReplaceValue()
{
$this->subject->setReplaceValue('foo bar');

self::assertSame(
'foo bar',
$this->subject->getReplaceValue()
);
}

/**
* @test
*/
public function getUseRegExpInitiallyReturnsFalse()
{
self::assertFalse(
$this->subject->isUseRegExp()
);
}

/**
* @test
*/
public function setUseRegExpSetsUseRegExp()
{
$this->subject->setUseRegExp(true);

self::assertTrue(
$this->subject->isUseRegExp()
);
}
}
79 changes: 79 additions & 0 deletions Tests/Functional/Enumeration/ConfigurationTypeEnumerationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package jweiland/replacer.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace JWeiland\Replacer\Tests\Functional\Enumeration;

use JWeiland\Replacer\Enumeration\ConfigurationTypeEnumeration;
use TYPO3\CMS\Core\Type\Exception\InvalidEnumerationValueException;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

final class ConfigurationTypeEnumerationTest extends FunctionalTestCase
{
protected ConfigurationTypeEnumeration $subject;

protected array $testExtensionsToLoad = [
'jweiland/replacer',
];

protected function setUp(): void
{
parent::setUp();

$this->subject = new ConfigurationTypeEnumeration();
}

/**
* @test
*/
public function configurationTypeAsStringWillReturnDefaultValue(): void
{
self::assertSame(
'search.',
(string)$this->subject
);
}

/**
* @test
*/
public function setValueToSearchWillAppendDot(): void
{
$subject = new ConfigurationTypeEnumeration('search');

self::assertSame(
'search.',
(string)$subject
);
}

/**
* @test
*/
public function setValueToReplaceWillAppendDot(): void
{
$subject = new ConfigurationTypeEnumeration('replace');

self::assertSame(
'replace.',
(string)$subject
);
}

/**
* @test
*/
public function setUnknownValueWillThrowException(): void
{
self::expectException(InvalidEnumerationValueException::class);

new ConfigurationTypeEnumeration('reload');
}
}
hojalatheef marked this conversation as resolved.
Show resolved Hide resolved
79 changes: 79 additions & 0 deletions Tests/Functional/FrontendRequest/ReplaceContentCachedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package jweiland/replacer.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace JWeiland\Replacer\Tests\Functional\FrontendRequest;

use JWeiland\Replacer\Tests\Functional\Traits\SetUpFrontendSiteTrait;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

class ReplaceContentCachedTest extends FunctionalTestCase
{
use SetUpFrontendSiteTrait;

protected array $testExtensionsToLoad = [
'jweiland/replacer',
];

protected function setUp(): void
{
parent::setUp();

$this->importCSVDataSet(__DIR__ . '/../Fixtures/pages.csv');
$this->setUpFrontendSite(1);
$this->setUpFrontendRootPage(
1,
[
'EXT:replacer/Tests/Functional/Fixtures/basic_template.typoscript',
]
);
}

/**
* @test
*/
public function frontendRequestDoNotReplacesContentOnTypo3Error(): void
{
$response = self::executeFrontendSubRequest(
new InternalRequest('https://website.local/site-not-found')
);

$body = (string)$response->getBody();

// If page was not found, do nothing. Let TYPO3 throw the error, but do not try to replace anything
// which will result in an uninitialized TSFE or methods on null exception
self::assertStringNotContainsString(
'TSFE',
$body
);
self::assertStringNotContainsString(
'null',
$body
);
}

/**
* @test
*/
public function frontendRequestReplacesContent(): void
{
$response = self::executeFrontendSubRequest(
new InternalRequest('https://website.local/')
);

$body = (string)$response->getBody();

self::assertStringContainsString(
'I like fruits',
$body
);
}
}
80 changes: 80 additions & 0 deletions Tests/Functional/FrontendRequest/ReplaceContentUnCachedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package jweiland/replacer.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace JWeiland\Replacer\Tests\Functional\FrontendRequest;

use JWeiland\Replacer\Tests\Functional\Traits\SetUpFrontendSiteTrait;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

class ReplaceContentUnCachedTest extends FunctionalTestCase
{
use SetUpFrontendSiteTrait;

protected array $testExtensionsToLoad = [
'jweiland/replacer',
];

protected function setUp(): void
{
parent::setUp();

$this->importCSVDataSet(__DIR__ . '/../Fixtures/pages.csv');
$this->setUpFrontendSite(1);
$this->setUpFrontendRootPage(
1,
[
'EXT:replacer/Tests/Functional/Fixtures/basic_template.typoscript',
'EXT:replacer/Tests/Functional/Fixtures/user_int.typoscript',
]
);
}

/**
* @test
*/
public function frontendRequestDoNotReplacesContentOnTypo3Error(): void
{
$response = self::executeFrontendSubRequest(
new InternalRequest('https://website.local/site-not-found')
);

$body = (string)$response->getBody();

// If page was not found, do nothing. Let TYPO3 throw the error, but do not try to replace anything
// which will result in an uninitialized TSFE or methods on null exception
self::assertStringNotContainsString(
'TSFE',
$body
);
self::assertStringNotContainsString(
'null',
$body
);
}

/**
* @test
*/
public function frontendRequestReplacesContent(): void
{
$response = self::executeFrontendSubRequest(
new InternalRequest('https://website.local/')
);

$body = (string)$response->getBody();

self::assertStringContainsString(
'I like fruits',
$body
);
}
}
2 changes: 1 addition & 1 deletion Tests/Functional/Helper/ReplacerHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* LICENSE file that was distributed with this source code.
*/

namespace JWeiland\Replacer\Tests\Unit\Helper;
namespace JWeiland\Replacer\Tests\Functional\Helper;

use JWeiland\Replacer\Helper\ReplacerHelper;
use JWeiland\Replacer\Helper\TypoScriptHelper;
Expand Down
Loading