Viewing File: /usr/local/cpanel/3rdparty/wpinstaller/tests/CoreTest.php

<?php
declare(strict_types=1);

final class CoreTest extends PHPUnit\Framework\TestCase {
    public function testConfTransformDefinePattern() {
        $const_name = 'HORCRUX';

        $pattern = \WpInstaller\Core::_conf_transform_define_pattern($const_name);

        $test_strings = [
            "define('$const_name','oof')",                  // No spaces
            "define ('$const_name', 'oof')",                // Subjectively normal spacing
            " define ( '$const_name' , 'oof' ) ",           // spaces everywhere
            "     define   (  '$const_name'    ,  'oof' )", // more than one space everywhere
            "define (\"$const_name\", 'oof')",              // Double quotes
        ];

        foreach ($test_strings as $test_string) {
            $this->assertEquals(
                preg_match($pattern, $test_string), 1,
                "define pattern matched $test_string"
            );
        }
    }

    public function testConfTransformTablePrefixPattern() {
        $pattern = \WpInstaller\Core::_conf_transform_table_prefix_pattern();

        $test_strings = [
            '$table_prefix="foo"',          // No spaces
            ' $table_prefix = "foo" ',      // Spaces everywhere
            ' $table_prefix = "foo" ',      // Spaces everywhere
            '  $table_prefix  =  "foo"   ', // More than one space everywhere
            '$table_prefix=\'foo\'',          // No spaces
        ];

        foreach ($test_strings as $test_string) {
            $this->assertEquals(
                preg_match($pattern, $test_string), 1,
                "table_prefix pattern matched $test_string"
            );
        }
    }

    public function testConfTransformSerializeValue () {
        $constant = "Number 2";
        $value = 123;

        //testing that an integer value serializes correctly
        $serialized_value = \WpInstaller\Core::_conf_transform_serialize_value($constant, $value);
        $this->assertTrue($serialized_value === $value, "integer value serialized correctly");

        //testing that an boolean value serializes correctly
        $value = false;
        $serialized_value = \WpInstaller\Core::_conf_transform_serialize_value($constant, $value);
        $this->assertTrue($serialized_value === 'false', "boolean value serialized correctly");

        $value = true;
        $serialized_value = \WpInstaller\Core::_conf_transform_serialize_value($constant, $value);
        $this->assertTrue($serialized_value === 'true', "boolean value serialized correctly");

        //testing that an NULL value serializes correctly
        $value = NULL;
        $serialized_value = \WpInstaller\Core::_conf_transform_serialize_value($constant, $value);
        $this->assertTrue($serialized_value === 'NULL', "NULL value serialized correctly");

        //testing that an string serializes correctly
        $value = "foo'bar";
        $serialized_value = \WpInstaller\Core::_conf_transform_serialize_value($constant, $value);
        $this->assertEquals($serialized_value, "'foo\'bar'", "string value serialized correctly");

        //testing that an unrecognized type throws
        $value = new \Exception('!');
        try{
            $serialized_value = \WpInstaller\Core::_conf_transform_serialize_value($constant, $value);
        }
        catch (\Exception $e) {
            $this->assertInstanceOf(Exception::class, $e,"string value serialized correctly");
        }
    }

}
?>
Back to Directory File Manager