!C99Shell v. 2.1 [PHP 8 Update] [02.02.2022]!

Software: Apache/2.4.53 (Unix) OpenSSL/1.1.1o PHP/7.4.29 mod_perl/2.0.12 Perl/v5.34.1. PHP/7.4.29 

uname -a: Linux vps-2738122-x 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64 

uid=1(daemon) gid=1(daemon) grupos=1(daemon) 

Safe-mode: OFF (not secure)

/opt/apex_tdfonline/php/lib/rest/tests/lib/   drwxr-xr-x
Free 11.85 GB of 61.93 GB (19.14%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Feedback    Self remove    Logout    


Viewing file:     rest_filtro_sqlTest.php (9.46 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php

namespace rest\tests\lib;

use 
rest\lib\rest_filtro_sql;
use 
rest\rest;

class 
rest_filtro_sqlTest extends \PHPUnit_Framework_TestCase
{


    protected 
$request;

    
/**
     * @var rest_filtro_sql
     */
    
protected $filtro;

    protected function 
setUp()
    {
        
parent::setUp();
        
$this->request $this->get_mock_request();
    }

    
/**
     * @expectedException rest\lib\rest_error
     */
    
public function testParametroIncorrecto()
    {
        
$param "nombre";
        
$this->filtro->agregar_campo($param);
        
$this->agregar_parametro_request($param'no_existe;pepe');
        
$this->assertEquals("nombre = pepe"trim($this->filtro->get_sql_where()));
    }


    public function 
testParametroInexistente()
    {
        
$param "nombre";
        
$this->filtro->agregar_campo($param);
        
$this->request->expects($this->once())
            ->
method('get')
            ->
with($this->equalTo($param))
            ->
will($this->returnValue(''));

        
$this->assertEquals("1 = 1"trim($this->filtro->get_sql_where()));
    }

    public function 
testLimit()
    {
        
$this->request->expects($this->exactly(2))
            ->
method('get')
            ->
with($this->logicalOr($this->equalTo('limit'), $this->equalTo('page')))
            ->
will($this->returnCallback(function ($param) {
                if (
$param == 'limit') {
                    return 
5;
                } else {
                    return 
1;
                }
            }));

        
$this->assertEquals("LIMIT 5 OFFSET 0"trim($this->filtro->get_sql_limit()));
    }

    public function 
testLimitSinPage()
    {
        
$this->request->expects($this->exactly(2))
            ->
method('get')
            ->
with($this->logicalOr($this->equalTo('limit'), $this->equalTo('page')))
            ->
will($this->returnCallback(function ($param) {
                if (
$param == 'limit') {
                    return 
5;
                } else {
                    return 
'';
                }
            }));

        
$this->assertEquals("LIMIT 5"trim($this->filtro->get_sql_limit()));
    }

    public function 
testLimitSinLimit()
    {
        
$this->request->expects($this->exactly(1))
            ->
method('get')
            ->
with($this->logicalOr($this->equalTo('limit'), $this->equalTo('page')))
            ->
will($this->returnCallback(function ($param) {
                if (
$param == 'limit') {
                    return 
'';
                } else {
                    return 
10;
                }
            }));

        
$this->assertEquals(""trim($this->filtro->get_sql_limit()));
    }


    public function 
testOrderBy()
    {

        
$this->filtro->agregar_campo_ordenable('nombre');
        
$this->filtro->agregar_campo_ordenable('apellido');

        
$this->agregar_parametro_request('order''+apellido,-nombre');

        
$this->assertEquals("ORDER BY apellido ASC, nombre DESC"trim($this->filtro->get_sql_order_by()));
    }

    public function 
testOrderByVacio()
    {

        
$this->filtro->agregar_campo('nombre');
        
$this->filtro->agregar_campo('apellido');
//        $this->agregar_parametro_request('order', '+apellido,-"and=1=1');

        
$this->assertEquals(""trim($this->filtro->get_sql_order_by()));
    }

    
/**
     * @expectedException rest\lib\rest_error
     */
    
public function testOrderByInvalido()
    {

        
$this->filtro->agregar_campo('nombre');
        
$this->filtro->agregar_campo('apellido');

        
$this->agregar_parametro_request('order''+apellido,-"and=1=1');

        
$this->assertEquals("ORDER BY apellido ASC, nombre DESC"trim($this->filtro->get_sql_order_by()));
    }

    
/**
     * @expectedException rest\lib\rest_error
     */
    
public function testLimitError()
    {
        
$this->request->expects($this->exactly(2))
            ->
method('get')
            ->
with($this->logicalOr($this->equalTo('limit'), $this->equalTo('page')))
            ->
will($this->returnCallback(function ($param) {
                if (
$param == 'limit') {
                    return 
5;
                } else {
                    return 
0;
                }
            }));

        
$this->assertEquals("LIMIT 5 OFFSET 0"trim($this->filtro->get_sql_limit()));
    }

    public function 
testDefaultFiltro()
    {
        
$param "nombre";
        
$this->filtro->agregar_campo($paramNULL'es_igual_a;pepe');
        
$this->agregar_parametro_request('nombre''');

        
$this->assertEquals("$param = pepe"trim($this->filtro->get_sql_where()));
    }

    public function 
testDefaultNoUsado()
    {
        
$param "nombre";
        
$this->filtro->agregar_campo($paramNULL'es_igual_a;pepe');
        
$this->agregar_parametro_request('nombre''es_igual_a;jose');
        
$this->assertEquals("nombre = jose"trim($this->filtro->get_sql_where()));
    }

    public function 
testFiltroLocal()
    {
        
$param "nombre";
        
$this->filtro->agregar_campo_local($paramnull'es_igual_a;pepe' );
        
$this->agregar_parametro_request('nombre'''0); //mock del quote

        
$this->assertEquals("nombre = pepe"trim($this->filtro->get_sql_where()));
    }

    public function 
testFlagSi()
    {
        
$param "activo";
        
$this->filtro->agregar_campo_flag($param'fecha > now'''0);
        
$this->agregar_parametro_request($param1); //mock del quote
        
$this->assertEquals('fecha > now'trim($this->filtro->get_sql_where()));
    }

    public function 
testFlagNo()
    {
        
$param "activo";
        
$this->filtro->agregar_campo_flag($param'fecha > now''no'0);
        
$this->agregar_parametro_request($param0); //mock del quote
        
$this->assertEquals('no'trim($this->filtro->get_sql_where()));
    }

    public function 
testFlagDef()
    {
        
$param "activo";
        
$this->filtro->agregar_campo_flag($param'fecha > now''no'0);
        
$this->agregar_parametro_request($paramnull1);
        
$this->assertEquals('no'trim($this->filtro->get_sql_where()));
    }

    public function 
testSimpleSi()
    {
        
$param "activo";
        
$this->filtro->agregar_campo_simple($param'estado = %s''A');
        
$this->agregar_parametro_request($param'C');
        
$this->assertEquals('estado = C'trim($this->filtro->get_sql_where()));
    }

    public function 
testSimpleDef()
    {
        
$param "activo";
        
$this->filtro->agregar_campo_simple($param,  'estado = %s''A');
        
$this->agregar_parametro_request($paramnull);
        
$this->assertEquals('estado = A'trim($this->filtro->get_sql_where()));
    }

    public function 
testWhereIgual()
    {
        
$param "nombre";
        
$this->filtro->agregar_campo($param);
        
$this->agregar_parametro_request($param'es_igual_a;pepe');
        
$this->assertEquals("nombre = pepe"trim($this->filtro->get_sql_where()));
    }

    public function 
testWhereDistinto()
    {
        
$param "nombre";
        
$this->filtro->agregar_campo($param);
        
$this->agregar_parametro_request($param'es_distinto_de;pepe');
        
$this->assertEquals("nombre <> pepe"trim($this->filtro->get_sql_where()));
    }

    public function 
testWhereEntre()
    {
        
$param "nombre";
        
$this->filtro->agregar_campo($param);
        
$this->agregar_parametro_request($param'entre;pepe;juan');
        
$this->assertEquals("nombre BETWEEN pepe AND juan"trim($this->filtro->get_sql_where()));
    }

    public function 
testWhereMayorQue()
    {
        
$param "nombre";
        
$this->filtro->agregar_campo($param);
        
$this->agregar_parametro_request($param'es_mayor_que;pepe');
        
$this->assertEquals("nombre > pepe"trim($this->filtro->get_sql_where()));
    }

    public function 
testWhereMayorIgualQue()
    {
        
$param "nombre";
        
$this->filtro->agregar_campo($param);
        
$this->agregar_parametro_request($param'es_mayor_igual_que;pepe');
        
$this->assertEquals("nombre >= pepe"trim($this->filtro->get_sql_where()));
    }


    public function 
testWhereMenorQue()
    {
        
$param "nombre";
        
$this->filtro->agregar_campo($param);
        
$this->agregar_parametro_request($param'es_menor_que;pepe');
        
$this->assertEquals("nombre < pepe"trim($this->filtro->get_sql_where()));
    }

    public function 
testWhereMenorIgualQue()
    {
        
$param "nombre";
        
$this->filtro->agregar_campo($param);
        
$this->agregar_parametro_request($param'es_menor_igual_que;pepe');
        
$this->assertEquals("nombre <= pepe"trim($this->filtro->get_sql_where()));
    }

    public function 
testWhereDesde()
    {
        
$param "nombre";
        
$this->filtro->agregar_campo($param);
        
$this->agregar_parametro_request($param'desde;pepe');
        
$this->assertEquals("nombre >= pepe"trim($this->filtro->get_sql_where()));
    }

    public function 
testWhereHasta()
    {
        
$param "nombre";
        
$this->filtro->agregar_campo($param);
        
$this->agregar_parametro_request($param'hasta;pepe');
        
$this->assertEquals("nombre <= pepe"trim($this->filtro->get_sql_where()));
    }

    public function 
testWhereContiene()
    {
        
$param "nombre";
        
$this->filtro->agregar_campo($param);
        
$this->agregar_parametro_request($param'contiene;pepe');
        
$this->assertEquals("nombre ILIKE %pepe%"trim($this->filtro->get_sql_where()));
    }

    public function 
testWhereNOContiene()
    {
        
$param "nombre";
        
$this->filtro->agregar_campo($param);
        
$this->agregar_parametro_request($param'no_contiene;pepe');
        
$this->assertEquals("nombre NOT ILIKE %pepe%"trim($this->filtro->get_sql_where()));
    }

    public function 
testWhereComienza()
    {
        
$param "nombre";
        
$this->filtro->agregar_campo($param);
        
$this->agregar_parametro_request($param'comienza_con;pepe');
        
$this->assertEquals("nombre ILIKE pepe%"trim($this->filtro->get_sql_where()));
    }

    public function 
testWhereTermina()
    {
        
$param "nombre";
        
$this->filtro->agregar_campo($param);
        
$this->agregar_parametro_request($param'termina_con;pepe');
        
$this->assertEquals("nombre ILIKE %pepe"trim($this->filtro->get_sql_where()));
    }


    
/**
     * @return \PHPUnit_Framework_MockObject_MockObject
     */
    
protected function get_mock_request()
    {
        
$r = new rest(array());

        
$this->filtro $this->getMockBuilder('rest\lib\rest_filtro_sql')
            ->
disableOriginalConstructor()
            ->
setMethods(array('quote'))
            ->
getMock();

        
$request $this->getMockBuilder('rest\http\respuesta_rest')
            ->
disableOriginalConstructor()
            ->
getMock();
        
$r->container['request'] = $request;

        return 
$request;
    }


    protected function 
agregar_parametro_request($param$valor$cantidad_llamados 1)
    {
        
$this->request->expects($this->exactly($cantidad_llamados))
            ->
method('get')
            ->
with($this->equalTo($param))
            ->
will($this->returnValue($valor));

        
$this->filtro->expects($this->any())
            ->
method('quote')
            ->
will($this->returnArgument(0));
    }
}
 

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.1 [PHP 8 Update] [02.02.2022] maintained byC99Shell Github | Generation time: 0.5078 ]--