-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate tests to Pest Remove support for PHP 7.4, 8.0 Add support for PHP 8.3 Antispambot: update phpdoc
- Loading branch information
Showing
11 changed files
with
156 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
/vendor | ||
composer.lock | ||
.php-cs-fixer.cache | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="Antispambot tests"> | ||
<directory>tests</directory> | ||
<testsuite name="Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<source> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
dataset('emails', [ | ||
'info@example.com', | ||
'dot.in.name@example.com', | ||
'info@subdomain.example.com', | ||
'test+plus@example.com', | ||
'another+plus+test@example.com', | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Test Case | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The closure you provide to your test functions is always bound to a specific PHPUnit test | ||
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may | ||
| need to change it using the "uses()" function to bind a different classes or traits. | ||
| | ||
*/ | ||
|
||
// uses(Tests\TestCase::class)->in('Feature'); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Expectations | ||
|-------------------------------------------------------------------------- | ||
| | ||
| When you're writing tests, you often need to check that values meet certain conditions. The | ||
| "expect()" function gives you access to a set of "expectations" methods that you can use | ||
| to assert different things. Of course, you may extend the Expectation API at any time. | ||
| | ||
*/ | ||
|
||
expect()->extend('toBeOne', function () { | ||
return $this->toBe(1); | ||
}); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Functions | ||
|-------------------------------------------------------------------------- | ||
| | ||
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your | ||
| project that you don't want to repeat in every file. Here you can also expose helpers as | ||
| global functions to help you to reduce the number of lines of code in your test files. | ||
| | ||
*/ | ||
|
||
function something() | ||
{ | ||
// .. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Webnuvola\Antispambot\Tests; | ||
|
||
use PHPUnit\Framework\TestCase as BaseTestCase; | ||
|
||
abstract class TestCase extends BaseTestCase | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
use Illuminate\Support\HtmlString; | ||
use Webnuvola\Antispambot\Antispambot; | ||
|
||
function decode_email(string $encodedEmail): string | ||
{ | ||
return html_entity_decode($encodedEmail, ENT_HTML5); | ||
} | ||
|
||
it('can obfuscate email', function (string $email) { | ||
$antispambot = Antispambot::antispambot($email); | ||
|
||
expect($antispambot) | ||
->not->toBe($email) | ||
->and(decode_email($antispambot))->toBe($email); | ||
})->with('emails'); | ||
|
||
it('can obfuscate email with hex encoding', function (string $email) { | ||
$antispambot = Antispambot::antispambot($email, true); | ||
|
||
expect($antispambot) | ||
->not->toBe($email) | ||
->and(html_entity_decode(urldecode(str_replace('+', '+', $antispambot)), ENT_HTML5))->toBe($email); | ||
})->with('emails'); | ||
|
||
test('antispambot function return value', function (string $email) { | ||
$result = antispambot($email); | ||
$return = preg_match('/"([^"]+)"/', $result, $matches); | ||
expect($return) | ||
->toBe(1) | ||
->and(decode_email($matches[1]))->toBe('mailto:' . $email) | ||
->and(decode_email(strip_tags($result)))->toBe($email); | ||
|
||
$result = antispambot($email, 'Contact us'); | ||
$return = preg_match('/"([^"]+)"/', $result, $matches); | ||
expect($return) | ||
->toBe(1) | ||
->and(decode_email($matches[1]))->toBe('mailto:' . $email) | ||
->and(strip_tags($result))->toBe('Contact us'); | ||
|
||
$result = antispambot($email, 'Contact us', ['class' => 'text-white', 'target' => '_blank']); | ||
$return = preg_match('/"([^"]+)"/', $result, $matches); | ||
expect($return) | ||
->toBe(1) | ||
->and(decode_email($matches[1]))->toBe('mailto:' . $email) | ||
->and(strip_tags($result))->toBe('Contact us') | ||
->and(str_contains($result, 'class="text-white"'))->toBeTrue() | ||
->and(str_contains($result, 'target="_blank"'))->toBeTrue(); | ||
})->with(['demo@example.com']); | ||
|
||
test('antispambot_html function return value', function (string $email) { | ||
$antispambotHtml = antispambot_html($email); | ||
|
||
expect($antispambotHtml) | ||
->toBeInstanceOf(HtmlString::class) | ||
->and(decode_email(strip_tags((string) $antispambotHtml)))->toBe($email); | ||
})->with(['demo@example.com']); |