PHP Classes

File: tests/AllowListTest.php

Recommend this page to a friend!
  Packages of Scott Arciszewski   Ionizer PHP Filter Input   tests/AllowListTest.php   Download  
File: tests/AllowListTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Ionizer PHP Filter Input
Filter input values by chaining filter objects
Author: By
Last change:
Date: 5 years ago
Size: 1,169 bytes
 

Contents

Class file image Download
<?php

use ParagonIE\Ionizer\Filter\AllowList;
use ParagonIE\Ionizer\GeneralFilterContainer;
use ParagonIE\Ionizer\InvalidDataException;
use PHPUnit\Framework\TestCase;


/**
 * Class AllowListTest
 */
class AllowListTest extends TestCase
{
    /**
     * @throws Error
     * @throws InvalidDataException
     */
    public function testWhiteList()
    {
        $filter = (new GeneralFilterContainer())
            ->addFilter(
                'test1',
                (new AllowList(
                    'abc',
                    'def',
                    'ghi'
                ))->setDefault('jkl')
            );

        if (!($filter instanceof GeneralFilterContainer)) {
            $this->fail('Type error');
        }

        $before = [
            'test1' => 'abc'
        ];
        $after = $filter($before);

        $this->assertSame(
            [
                'test1' => 'abc'
            ],
            $after
        );

        $before = [
            'test1' => 0.123
        ];
        $after = $filter($before);

        $this->assertSame(
            [
                'test1' => 'jkl'
            ],
            $after
        );
    }
}