<commit_before><?php
/**
 * @group Model_Db
 */
class Vps_Model_DbWithConnection_Test extends PHPUnit_Framework_TestCase
{
    private $_tableName;
    public function setUp()
    {
        $this->_tableName = 'test'.uniqid();
        $sql = "CREATE TABLE $this->_tableName (
            `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
            `test1` VARCHAR( 200 ) NOT NULL,
            `test2` VARCHAR( 200 ) NOT NULL  
        ) ENGINE = INNODB";
        Vps_Registry::get('db')->query($sql);
        $m = new Vps_Model_Db(array(
            'table' => $this->_tableName
        ));
        $r = $m->createRow();
        $r->test1 = '1x1';
        $r->test2 = '1';
        $r->save();
    }

    public function tearDown()
    {
        Vps_Registry::get('db')->query("DROP TABLE {$this->_tableName}");
    }

    public function testIt()
    {
        $model = new Vps_Model_Db(array(
            'table' => $this->_tableName
        ));
        $this->assertEquals('1x1', $model->getRow(1)->test1);
    }
}<commit_msg>brute-force test für escaping<commit_after><?php
/**
 * @group Model_Db
 */
class Vps_Model_DbWithConnection_Test extends PHPUnit_Framework_TestCase
{
    private $_tableName;
    public function setUp()
    {
        $this->_tableName = 'test'.uniqid();
        $sql = "CREATE TABLE $this->_tableName (
            `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
            `test1` VARCHAR( 200 ) NOT NULL,
            `test2` VARCHAR( 200 ) NOT NULL  
        ) ENGINE = INNODB";
        Vps_Registry::get('db')->query($sql);
        $m = new Vps_Model_Db(array(
            'table' => $this->_tableName
        ));
        $r = $m->createRow();
        $r->test1 = '1x1';
        $r->test2 = '1';
        $r->save();
    }

    public function tearDown()
    {
        Vps_Registry::get('db')->query("DROP TABLE {$this->_tableName}");
    }

    public function testIt()
    {
        $model = new Vps_Model_Db(array(
            'table' => $this->_tableName
        ));
        $this->assertEquals('1x1', $model->getRow(1)->test1);
    }

    /**
     * @group slow
     */
    public function testEscapingBruteForce()
    {
        $model = new Vps_Model_Db(array(
            'table' => $this->_tableName
        ));
        for($i=0;$i<1000;$i++) {
            $v = '';
            for($j=0;$j<10;$j++) {
                $v .= chr(rand(0, 255));
            }
            $s = $model->select()->whereEquals('test1', $v);
            $model->getRow($s);

            $s = $model->select()->where(new Vps_Model_Select_Expr_Equals('test1', $v));
            $model->getRow($s);
        }
    }
}
{'fraction_non_alphanumeric': 0.1664145234493192, 'fraction_numerical': 0.018154311649016642, 'mean_word_length': 1.9819616685456596, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1776552', 'n_tokens_mistral': 903, 'n_tokens_neox': 865, 'n_words': 162}