diff --git a/tests/anchor.test.php b/tests/anchor.test.php index 61cd84c..236ef60 100644 --- a/tests/anchor.test.php +++ b/tests/anchor.test.php @@ -1,5 +1,46 @@ toBeTrue(); +use Leaf\Anchor; + +test('set config', function () { + Anchor::config(['SECRET' => 'item']); + $config = Anchor::config(); + + expect($config['SECRET'])->toBe('item'); +}); + +test('sanitize', function () { + $html = 'Hello World'; + + expect(Anchor::sanitize($html))->toBe(htmlspecialchars($html)); +}); + +test('sanitize array', function () { + $html = ['Hello World', 'Hello World']; + + expect(Anchor::sanitize($html))->toBe([ + htmlspecialchars('Hello World'), + htmlspecialchars('Hello World'), + ]); +}); + +test('sanitize assoc array', function () { + $html = ['key' => 'Hello World']; + + expect(Anchor::sanitize($html))->toBe(['key' => htmlspecialchars('Hello World')]); +}); + +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(); });