Skip to content

Commit

Permalink
✅ added anchor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Jan 3, 2022
1 parent 1cd6d63 commit 25e5c4d
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions tests/anchor.test.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
<?php

test('example', function () {
expect(true)->toBeTrue();
use Leaf\Anchor;

test('set config', function () {
Anchor::config(['SECRET' => 'item']);
$config = Anchor::config();

expect($config['SECRET'])->toBe('item');
});

test('sanitize', function () {
$html = '<b>Hello World</b>';

expect(Anchor::sanitize($html))->toBe(htmlspecialchars($html));
});

test('sanitize array', function () {
$html = ['<b>Hello World</b>', '<b>Hello World</b>'];

expect(Anchor::sanitize($html))->toBe([
htmlspecialchars('<b>Hello World</b>'),
htmlspecialchars('<b>Hello World</b>'),
]);
});

test('sanitize assoc array', function () {
$html = ['key' => '<b>Hello World</b>'];

expect(Anchor::sanitize($html))->toBe(['key' => htmlspecialchars('<b>Hello World</b>')]);
});

test('generate token', function () {
expect(Anchor::generateToken())->toBeString();
});

test('secret in token', function () {
$anchorSecret = 'SOMETHING';
Anchor::config(['SECRET' => $anchorSecret]);

expect(strpos(hex2bin(Anchor::generateToken()), $anchorSecret))->toBe(0);
});

test('errors', function () {
expect(Anchor::errors())->toBeArray();
});

0 comments on commit 25e5c4d

Please sign in to comment.