
<?php

use \Inspekt\Inspekt;
use \Inspekt\Cage;
use \Inspekt\SuperglobalsCage;

require_once dirname(__FILE__) . "/../vendor/autoload.php";

/**
 * Test class for Inspekt.
 * Generated by PHPUnit on 2009-07-18 at 19:53:18.
 */
class InspektTest extends PHPUnit_Framework_TestCase
{
    /**
     * @var       Inspekt
     * @access protected
     */
    protected $object;

    /**
     * Sets up the fixture, for example, opens a network connection.
     * This method is called before a test is executed.
     *
     * @access protected
     */
    protected function setUp()
    {
        // $this->object = new Inspekt;
    }

    /**
     * Tears down the fixture, for example, closes a network connection.
     * This method is called after a test is executed.
     *
     * @access protected
     */
    protected function tearDown()
    {
    }

    /**
     * Generated from @assert ('1)@*(&UR)HQ)W(*(HG))') === '1URHQWHG'.
     */
    public function testGetAlnum()
    {
        $this->assertSame(
            '1URHQWHG',
            Inspekt::getAlnum('1)@*(&UR)HQ)W(*(HG))')
        );
    }

    /**
     * Generated from @assert ('1)@*(&UR)HQ)56W(*(HG))') === '156'.
     */
    public function testGetDigits()
    {
        $this->assertSame(
            '156',
            Inspekt::getDigits('1)@*(&UR)HQ)56W(*(HG))')
        );
    }

    /**
     * Generated from @assert ('/usr/lib/php/Pear.php') === '/usr/lib/php'.
     */
    public function testGetDir()
    {
        $this->assertSame(
            '/usr/lib/php',
            Inspekt::getDir('/usr/lib/php/Pear.php')
        );
    }

    /**
     * Generated from @assert ('1)45@*(&UR)HQ)W.0000(*(HG))') === 1.
     */
    public function testGetInt()
    {
        $this->assertSame(
            1,
            Inspekt::getInt('1)45@*(&UR)HQ)W.0000(*(HG))')
        );
    }

    /**
     * Generated from @assert ('A1)45@*(&UR)HQ)W.0000(*(HG))') === 0.
     */
    public function testGetInt2()
    {
        $this->assertSame(
            0,
            Inspekt::getInt('A1)45@*(&UR)HQ)W.0000(*(HG))')
        );
    }

    /**
     * Generated from @assert ('NCOFWIERNVOWIEBHV12047057y0650ytg0314') === true.
     */
    public function testIsAlnum()
    {
        $this->assertSame(
            true,
            Inspekt::isAlnum('NCOFWIERNVOWIEBHV12047057y0650ytg0314')
        );
    }

    /**
     * Generated from @assert ('NCOFWIERNVOWIEBHV2@12047057y0650ytg0314') === false.
     */
    public function testIsAlnum2()
    {
        $this->assertSame(
            false,
            Inspekt::isAlnum('NCOFWIERNVOWIEBHV2@12047057y0650ytg0314')
        );
    }

    /**
     * Generated from @assert ('funkatron') === true.
     */
    public function testIsAlnum3()
    {
        $this->assertSame(
            true,
            Inspekt::isAlnum('funkatron')
        );
    }

    /**
     * Generated from @assert ('funkatron_user') === false.
     */
    public function testIsAlnum4()
    {
        $this->assertSame(
            false,
            Inspekt::isAlnum('funkatron_user')
        );
    }

    /**
     * Generated from @assert ('funkatron-user') === false.
     */
    public function testIsAlnum5()
    {
        $this->assertSame(
            false,
            Inspekt::isAlnum('funkatron-user')
        );
    }

    /**
     * Generated from @assert ('_funkatronuser') === false.
     */
    public function testIsAlnum6()
    {
        $this->assertSame(
            false,
            Inspekt::isAlnum('_funkatronuser')
        );
    }

    /**
     * Generated from @assert ('NCOFWIERNVOWIEBHV12047057y0650ytg0314') === false.
     */
    public function testIsAlpha()
    {
        $this->assertSame(
            false,
            Inspekt::isAlpha('NCOFWIERNVOWIEBHV12047057y0650ytg0314')
        );
    }

    /**
     * Generated from @assert ('NCOFWIERNVOWIEBHV2@12047057y0650ytg0314') === false.
     */
    public function testIsAlpha2()
    {
        $this->assertSame(
            false,
            Inspekt::isAlpha('NCOFWIERNVOWIEBHV2@12047057y0650ytg0314')
        );
    }

    /**
     * Generated from @assert ('funkatron') === true.
     */
    public function testIsAlpha3()
    {
        $this->assertSame(
            true,
            Inspekt::isAlpha('funkatron')
        );
    }

    /**
     * Generated from @assert ('funkatron_user') === false.
     */
    public function testIsAlpha4()
    {
        $this->assertSame(
            false,
            Inspekt::isAlpha('funkatron_user')
        );
    }

    /**
     * Generated from @assert ('funkatron-user') === false.
     */
    public function testIsAlpha5()
    {
        $this->assertSame(
            false,
            Inspekt::isAlpha('funkatron-user')
        );
    }

    /**
     * Generated from @assert ('_funkatronuser') === false.
     */
    public function testIsAlpha6()
    {
        $this->assertSame(
            false,
            Inspekt::isAlpha('_funkatronuser')
        );
    }

    /**
     * Generated from @assert (12, 0, 12) === TRUE.
     */
    public function testIsBetween()
    {
        $this->assertSame(
            true,
            Inspekt::isBetween(12, 0, 12)
        );
    }

    /**
     * Generated from @assert (12, 0, 12, FALSE) === FALSE.
     */
    public function testIsBetween2()
    {
        $this->assertSame(
            false,
            Inspekt::isBetween(12, 0, 12, false)
        );
    }

    /**
     * Generated from @assert ('f', 'a', 'm', FALSE) === TRUE.
     */
    public function testIsBetween3()
    {
        $this->assertSame(
            true,
            Inspekt::isBetween('f', 'a', 'm', false)
        );
    }

    /**
     * Generated from @assert ('p', 'a', 'm', FALSE) === FALSE.
     */
    public function testIsBetween4()
    {
        $this->assertSame(
            false,
            Inspekt::isBetween('p', 'a', 'm', false)
        );
    }

    /**
     * Generated from @assert ('2009-06-30') === TRUE.
     */
    public function testIsDate()
    {
        $this->assertSame(
            true,
            Inspekt::isDate('2009-06-30')
        );
    }

    /**
     * Generated from @assert ('2009-06-31') === FALSE.
     */
    public function testIsDate2()
    {
        $this->assertSame(
            false,
            Inspekt::isDate('2009-06-31')
        );
    }

    /**
     * Generated from @assert ('2009-6-30') === TRUE.
     */
    public function testIsDate3()
    {
        $this->assertSame(
            true,
            Inspekt::isDate('2009-6-30')
        );
    }

    /**
     * Generated from @assert ('2-6-30') === TRUE.
     */
    public function testIsDate4()
    {
        $this->assertSame(
            true,
            Inspekt::isDate('2-6-30')
        );
    }

    /**
     * Generated from @assert ('1029438750192730t91740987023948') === FALSE.
     */
    public function testIsDigits()
    {
        $this->assertSame(
            false,
            Inspekt::isDigits('1029438750192730t91740987023948')
        );
    }

    /**
     * Generated from @assert ('102943875019273091740987023948') === TRUE.
     */
    public function testIsDigits2()
    {
        $this->assertSame(
            true,
            Inspekt::isDigits('102943875019273091740987023948')
        );
    }

    /**
     * Generated from @assert (102943875019273091740987023948) === FALSE.
     */
    public function testIsDigits3()
    {
        $this->assertSame(
            false,
            Inspekt::isDigits(102943875019273091740987023948)
        );
    }

    /**
     * Generated from @assert ('coj@poop.com') === TRUE.
     */
    public function testIsEmail()
    {
        $this->assertSame(
            true,
            Inspekt::isEmail('coj@poop.com')
        );
    }

    /**
     * Generated from @assert ('coj+booboo@poop.com') === TRUE.
     */
    public function testIsEmail2()
    {
        $this->assertSame(
            true,
            Inspekt::isEmail('coj+booboo@poop.com')
        );
    }

    /**
     * Generated from @assert ('coj!booboo@poop.com') === FALSE.
     */
    public function testIsEmail3()
    {
        $this->assertSame(
            false,
            Inspekt::isEmail('coj!booboo@poop.com')
        );
    }

    /**
     * Generated from @assert ('@poop.com') === FALSE.
     */
    public function testIsEmail4()
    {
        $this->assertSame(
            false,
            Inspekt::isEmail('@poop.com')
        );
    }

    /**
     * Generated from @assert ('a@b') === FALSE.
     */
    public function testIsEmail5()
    {
        $this->assertSame(
            false,
            Inspekt::isEmail('a@b')
        );
    }

    /**
     * Generated from @assert ('webmaster') === FALSE.
     */
    public function testIsEmail6()
    {
        $this->assertSame(
            false,
            Inspekt::isEmail('webmaster')
        );
    }

    /**
     * Generated from @assert (10244578109.234451) === TRUE.
     */
    public function testIsFloat()
    {
        $this->assertSame(
            true,
            Inspekt::isFloat(10244578109.234451)
        );
    }

    /**
     * Generated from @assert ('10244578109.234451') === FALSE.
     */
    public function testIsFloat2()
    {
        $this->assertSame(
            false,
            Inspekt::isFloat('10244578109.234451')
        );
    }

    /**
     * Generated from @assert ('10,244,578,109.234451') === FALSE.
     */
    public function testIsFloat3()
    {
        $locale = localeconv();
        $thousands_sep = $locale['thousands_sep'];
        $this->assertSame(
            false,
            Inspekt::isFloat("10{$thousands_sep}244{$thousands_sep}578{$thousands_sep}109.234451")
        );
    }

    /**
     * Generated from @assert (5, 0) === TRUE.
     */
    public function testIsGreaterThan()
    {
        $this->assertSame(
            true,
            Inspekt::isGreaterThan(5, 0)
        );
    }

    /**
     * Generated from @assert (2, 10) === FALSE.
     */
    public function testIsGreaterThan2()
    {
        $this->assertSame(
            false,
            Inspekt::isGreaterThan(2, 10)
        );
    }

    /**
     * Generated from @assert ('b', 'a') === TRUE.
     */
    public function testIsGreaterThan3()
    {
        $this->assertSame(
            true,
            Inspekt::isGreaterThan('b', 'a')
        );
    }

    /**
     * Generated from @assert ('a', 'b') === FALSE.
     */
    public function testIsGreaterThan4()
    {
        $this->assertSame(
            false,
            Inspekt::isGreaterThan('a', 'b')
        );
    }

    /**
     * Generated from @assert ('6F') === TRUE.
     */
    public function testIsHex()
    {
        $this->assertSame(
            true,
            Inspekt::isHex('6F')
        );
    }

    /**
     * Generated from @assert ('F6') === TRUE.
     */
    public function testIsHex2()
    {
        $this->assertSame(
            true,
            Inspekt::isHex('F6')
        );
    }

    /**
     *
     */
    public function testMakeServerCage()
    {
        $cage = Inspekt::makeServerCage();
        $this->assertTrue($cage instanceof Cage);
    }

    /**
     *
     */
    public function testMakeGetCage()
    {
        $cage = Inspekt::makeGetCage();
        $this->assertTrue($cage instanceof Cage);
    }

    /**
     *
     */
    public function testMakePostCage()
    {
        $cage = Inspekt::makePostCage();
        $this->assertTrue($cage instanceof Cage);
    }

    /**
     *
     */
    public function testMakeCookieCage()
    {
        $cage = Inspekt::makeCookieCage();
        $this->assertTrue($cage instanceof Cage);
    }

    /**
     *
     */
    public function testMakeEnvCage()
    {
        $cage = Inspekt::makeEnvCage();
        $this->assertTrue($cage instanceof Cage);
    }

    /**
     *
     */
    public function testMakeFilesCage()
    {
        $cage = Inspekt::makeFilesCage();
        $this->assertTrue($cage instanceof Cage);
    }

    /**
     * session cages currently aren't supported
     */
    public function testMakeSessionCage()
    {

    }

    /**
     *
     */
    public function testMakeSuperCage()
    {
        $cage = Inspekt::makeSuperCage();
        $this->assertTrue($cage instanceof SuperglobalsCage);
    }

    /**
     *
     */
    public function testUseFilterExt()
    {
        $this->assertTrue(Inspekt::useFilterExt(true));
        $this->assertTrue(Inspekt::useFilterExt());
        $this->assertFalse(Inspekt::useFilterExt(false));
        $this->assertFalse(Inspekt::useFilterExt());
    }

    /**
     *
     */
    public function testConvertArrayToArrayObject()
    {
        $arr = array(1, 2, 3, 4);
        $ao = Inspekt::convertArrayToArrayObject($arr);
        $this->assertTrue($ao instanceof \ArrayObject);
    }

    /**
     *
     */
    public function testGetAlpha()
    {
        $input = '0qhf01 *#R& !)*h09hqwe0fH! )efh0hf';
        $output = 'qhfRhhqwefHefhhf';
        $this->assertTrue(Inspekt::getAlpha($input) === $output);

        $input = array('1241DOSLDH', 'efoihr123-', 'eoeijfo1');
        $output = array('DOSLDH', 'efoihr', 'eoeijfo');
        $this->assertEquals(Inspekt::getAlpha($input), $output);
    }

    /**
     *
     */
    public function testGetPath()
    {
        $old_cwd = getcwd();
        chdir(dirname(__FILE__));

        $expected = dirname(__FILE__);
        $this->assertSame(Inspekt::getPath('./'), $expected);

        $expected = dirname(dirname(dirname(__FILE__)));
        $this->assertSame(Inspekt::getPath('./../../'), $expected);

        chdir($old_cwd);
    }

    /**
     *
     */
    public function testGetROT13()
    {
        $input = 'I am not an animal!';
        $expect = 'V nz abg na navzny!';
        $this->assertSame($expect, Inspekt::getROT13($input));
    }

    /**
     * @link https://www.paypal.com/en_US/vhelp/paypalmanager_help/credit_card_numbers.htm
     */
    public function testIsCcnum()
    {
        $input = '5105105105105100';
        $this->assertTrue(Inspekt::isCcnum($input));
    }

    /**
     * @throws \Inspekt\Exception
     * @expectedException \Inspekt\Exception
     */
    public function testIsCcnumType()
    {
        $input = '5105105105105100';
        $this->assertTrue(Inspekt::isCcnum($input, 'mastercard'));
    }

    /**
     *
     */
    public function testIsHostname()
    {
        $input = '192.168.1.1';
        $this->assertTrue(Inspekt::isHostname($input));
    }

    /**
     * @expectedException \Inspekt\Exception
     */
    public function testIsHostnameBadAllow()
    {
        $input = '192.168.1.1';
        $this->assertTrue(Inspekt::isHostname($input, 'c'));
    }

    /**
     * @expectedException \Inspekt\Exception
     */
    public function testIsHostnameBadAllow2()
    {
        $input = '192.168.1.1';
        $this->assertTrue(Inspekt::isHostname($input, 0));
    }

    /**
     * @expectedException \Inspekt\Exception
     */
    public function testIsHostnameBadAllow3()
    {
        $input = '192.168.1.1';
        $this->assertTrue(Inspekt::isHostname($input, 8));
    }

    /**
     *
     */
    public function testIsInt()
    {
        $input = '9223372036854775807';
        $this->assertTrue(Inspekt::isInt($input));
    }

    /**
     *
     */
    public function testIsInt1()
    {
        $input = '-9223372036854775807';
        $this->assertTrue(Inspekt::isInt($input));
    }

    /**
     *
     */
    public function testIsInt2()
    {
        $input = '4523231.123';
        $this->assertFalse(Inspekt::isInt($input));
    }

    /**
     *
     */
    public function testIsInt3()
    {
        $input = '1';
        $this->assertTrue(Inspekt::isInt($input));
    }

    /**
     *
     */
    public function testIsInt4()
    {
        $input = 2147483647;
        $this->assertTrue(Inspekt::isInt($input));
    }

    /**
     *
     */
    public function testIsInt5()
    {
        $input = "";
        $this->assertFalse(Inspekt::isInt($input));
    }

    /**
     *
     */
    public function testIsInt6()
    {
        $input = "123abg";
        $this->assertFalse(Inspekt::isInt($input));
    }

    /**
     *
     */
    public function testIsInt7()
    {
        $input = "abg123";
        $this->assertFalse(Inspekt::isInt($input));
    }

    /**
     *
     */
    public function testIsInt8()
    {
        $input = "0x1234cafe";
        $this->assertFalse(Inspekt::isInt($input));
    }

    /**
     *
     */
    public function testIsInt9()
    {
        $input = "-";
        $this->assertFalse(Inspekt::isInt($input));
    }

    /**
     *
     */
    public function testIsInt10()
    {
        $input = "&";
        $this->assertFalse(Inspekt::isInt($input));
    }

    /**
     *
     */
    public function testIsIp()
    {
        $input = '192.168.1.1';
        $this->assertTrue(Inspekt::isIp($input));
    }

    /**
     *
     */
    public function testIsLessThan()
    {
        $this->assertTrue(Inspekt::isLessThan('a', 'b'));
    }

    /**
     *
     */
    public function testIsOneOf()
    {
        $oneof = '<>\'"&';
        $input = '&';
        $this->assertTrue(Inspekt::isOneOf($input, $oneof));
    }

    /**
     *
     */
    public function testIsPhone()
    {
        $input = '7655559090';
        $this->assertTrue(Inspekt::isPhone($input));
    }

    /**
     * @todo Implement testIsRegex().
     */
    public function testIsRegex()
    {
        $input = 'username_786';
        $regex = '/[a-zA-Z0-9_]/';
        $this->assertTrue(Inspekt::isRegex($input, $regex));
    }

    /**
     *
     */
    public function testIsUri()
    {
        $input = '//lessthan';
        $this->assertFalse(Inspekt::isUri($input));
    }

    /**
     *
     */
    public function testIsUri1()
    {
        $input = 'ftp://funky7:boooboo@123.444.999.12/';
        $this->assertTrue(Inspekt::isUri($input));
    }

    /**
     *
     */
    public function testIsUri2()
    {
        $input = 'http://spinaltap.micro.umn.edu/00/Weather/California/Los%lngeles';
        $this->assertFalse(Inspekt::isUri($input));
    }

    /**
     *
     */
    public function testIsUri3()
    {
        $input = 'http://funkatron.com/////////12341241';
        $this->assertTrue(Inspekt::isUri($input));
    }

    /**
     *
     */
    public function testIsUri4()
    {
        $input = 'http://funkatron.com:12';
        $this->assertTrue(Inspekt::isUri($input));
    }

    /**
     *
     */
    public function testIsUri5()
    {
        $input = 'http://funkatron.com:8000/#foo';
        $this->assertTrue(Inspekt::isUri($input));
    }

    /**
     *
     */
    public function testIsUri6()
    {
        $input = 'https://funkatron.com';
        $this->assertTrue(Inspekt::isUri($input));
    }

    /**
     *
     */
    public function testIsUri7()
    {
        $input = 'https://funkatron.com:42/funky.php?foo[]=bar';
        $this->assertTrue(Inspekt::isUri($input));
    }

    /**
     *
     */
    public function testIsUri8()
    {
        $input = 'http://www.w3.org/2001/XMLSchema';
        $this->assertTrue(Inspekt::isUri($input));
    }

    /**
     *
     */
    public function testIsUri9()
    {
        $input = 'http://news.bbc.co.uk/2/hi/middle_east/8277040.stm';
        $this->assertTrue(Inspekt::isUri($input));
    }

    /**
     *
     */
    public function testIsZip()
    {
        $input = '00202';
        $this->assertTrue(Inspekt::isZip($input));
    }

    /**
     *
     */
    public function testIsZip1()
    {
        $input = 'C6D-5F5';
        $this->assertFalse(Inspekt::isZip($input));
    }

    /**
     *
     */
    public function testIsZip2()
    {
        $input = '46544-4142';
        $this->assertTrue(Inspekt::isZip($input));
    }

    /**
     *
     */
    public function testNoTags()
    {
        $input = '<SCRIPT>alert(\'foobar\');</SCRIPT>';
        $expect = 'alert(\'foobar\');';
        $this->assertSame($expect, Inspekt::noTags($input));
    }

    /**
     * What might look like blank spaces below are mostly low ASCII chars
     */
    public function testNoTagsOrSpecial()
    {
        $input = '    <SCRIPT<strong>>alert(\'foobar\');<</strong>/SCRIPT>';
        $expect = '&#21;&#21;&#21;&#21;&#21;&#21;&#22; &#22; &#22; &#22; alert(&#039;foobar&#039;);';
        $this->assertSame($expect, Inspekt::noTagsOrSpecial($input));
    }

    /**
     *
     */
    public function testNoPath()
    {
        $input = './../../../../../../../../../etc/passwd';
        $expect = 'passwd';
        $this->assertSame($expect, Inspekt::noPath($input));
    }

    /**
     * @todo Implement testEscMySQL().
     */
    public function testEscMySQL()
    {
        if (!extension_loaded('mysqli')) {
            $this->markTestSkipped(
                'The MySQLi extension is not available.'
            );
        }
    }

    /**
     * @todo Implement testEscPgSQL().
     */
    public function testEscPgSQL()
    {
        if (!extension_loaded('pgsql')) {
            $this->markTestSkipped(
                'The PGSQL extension is not available.'
            );
        }
    }

    /**
     * @todo Implement testEscPgSQLBytea().
     */
    public function testEscPgSQLBytea()
    {
        if (!extension_loaded('pgsql')) {
            $this->markTestSkipped(
                'The PGSQL extension is not available.'
            );
        }
    }
}
