setSelectionWindow_DBSource('PROV_TEST','select cpro, dpro from tcom_provincias'); $this->v = new gvHidraSelectionWindow('campotpl','PROV_TEST',array()); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. * * @access protected */ protected function tearDown() { } /** * @todo Implement testSetDependencia(). */ public function testSetDependencia() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @todo Implement testSetQueryMode(). */ public function testSetQueryMode() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @todo Implement testGetNombreVentana(). */ public function testGetNombreVentana() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @todo Implement testGetDescripcionVentana(). */ public function testGetDescripcionVentana() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @todo Implement test_procesarDefinicion(). */ public function test_procesarDefinicion() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @todo Implement testAbrirVentanaSeleccion(). */ public function testAbrirVentanaSeleccion() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @todo Implement testBuscarVentanaSeleccion(). */ public function testBuscarVentanaSeleccion() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } public function test_concatenarCamposSelect() { $v = $this->v; $d = array('phptype'=>'oci8'); $consulta = 'select a,b '; $this->assertEquals('', $v->_concatenarCamposSelect($d,$consulta),'select sin from'); $consulta = 'a,b from tabla where a=2'; $this->assertEquals('', $v->_concatenarCamposSelect($d,$consulta),'from sin select'); $consulta = 'select from ...'; $this->assertEquals('', $v->_concatenarCamposSelect($d,$consulta),'sin campos en select'); $consulta = 'select a from ...'; // columnas $this->assertEquals(' a ', $v->_concatenarCamposSelect($d,$consulta),'un campo'); $consulta = 'select a,b from ...'; $this->assertEquals(" concat(concat( a,' '),b ) ",$v->_concatenarCamposSelect($d,$consulta),'dos campos'); $consulta = 'select a from t1, (select subc from subtabla) t2...'; $this->assertEquals(' a ', $v->_concatenarCamposSelect($d,$consulta),'un campo con subconsulta'); // funciones $consulta = 'select funcion(),a from tabla'; $this->assertEquals(" concat(concat( funcion(),' '),a ) ", $v->_concatenarCamposSelect($d,$consulta),'funcion al principio'); $consulta = 'select a,funcion() from tabla'; $this->assertEquals(" concat(concat( a,' '),funcion() ) ", $v->_concatenarCamposSelect($d,$consulta),'funcion al final'); $consulta = 'select a,funcion(),c from tabla'; $this->assertEquals(" concat(concat( concat(concat( a,' '),funcion()) ,' '),c ) ", $v->_concatenarCamposSelect($d,$consulta),'funcion en medio'); $consulta = 'select funcion(p1,p2),a from tabla'; $this->assertEquals(" concat(concat( funcion(p1,p2),' '),a ) ", $v->_concatenarCamposSelect($d,$consulta),'funcion al principio con parametros'); $consulta = 'select funcion(p1,nvl(t,v)),a from tabla'; $this->assertEquals(" concat(concat( funcion(p1,nvl(t,v)),' '),a ) ", $v->_concatenarCamposSelect($d,$consulta),'funciones anidadas'); $consulta = 'select concat(a,concat(b,c)) as "calculado",a from tabla'; $this->assertSame(" concat(concat( concat(a,concat(b,c)) ,' '),a ) ", $v->_concatenarCamposSelect($d,$consulta),'funcion concat con alias'); $consulta = 'select concat(a,concat(b,c)),a from tabla'; $this->assertSame(" concat(concat( concat(a,concat(b,c)),' '),a ) ", $v->_concatenarCamposSelect($d,$consulta),'funcion concat sin alias'); $consulta = 'select funcion (a) from tabla'; $this->assertSame(" concat(concat( funcion ,' '),(a) ) ", $v->_concatenarCamposSelect($d,$consulta),'funcion con parentesis separado no funciona'); // constantes $consulta = 'select 1,a from tabla'; $this->assertEquals(" concat(concat( 1,' '),a ) ", $v->_concatenarCamposSelect($d,$consulta),'constante numerica'); $consulta = "select 'cte',a from tabla"; $this->assertEquals(" concat(concat( 'cte',' '),a ) ", $v->_concatenarCamposSelect($d,$consulta),'constante texto'); // columnas con prefijo de tabla $consulta = "select tabla.a, b from tabla"; $this->assertEquals(" concat(concat( tabla.a,' '),b ) ", $v->_concatenarCamposSelect($d,$consulta),'columna con prefijo'); // expresiones $consulta = "select (1+2), b from tabla"; $this->assertEquals(" concat(concat( (1+2),' '),b ) ", $v->_concatenarCamposSelect($d,$consulta),'expresion aritmetica'); // alias de campo $consulta = 'select a as "col1", b from tabla'; $this->assertEquals(" concat(concat( a ,' '),b ) ", $v->_concatenarCamposSelect($d,$consulta),'alias al principio'); $consulta = 'select a, b as "col1" from tabla'; $this->assertEquals(" concat(concat( a,' '),b ) ", $v->_concatenarCamposSelect($d,$consulta),'alias al final'); $consulta = 'select a, b as "col1",c from tabla'; $this->assertEquals(" concat(concat( concat(concat( a,' '),b ) ,' '),c ) ", $v->_concatenarCamposSelect($d,$consulta),'alias en medio'); $consulta = "SELECT col as \"P.1-P.2\" FROM tabla"; $this->assertEquals(" col ", $v->_concatenarCamposSelect($d,$consulta),'alias complejo'); $consulta = "SELECT col as \"P 2\" FROM tabla"; $this->assertEquals(" col ", $v->_concatenarCamposSelect($d,$consulta),'alias con espacio'); $consulta = 'select a as col_1, b from tabla'; $this->assertEquals(" concat(concat( a ,' '),b ) ", $v->_concatenarCamposSelect($d,$consulta),'alias sin comillas dobles'); $d = array('phptype'=>'pgsql'); $consulta = 'select 1,a from tabla'; $this->assertEquals(" coalesce(coalesce(text( 1),'')||' ','')||coalesce(text(a ),'') ", $v->_concatenarCamposSelect($d,$consulta),'constante numerica con postgresql'); } /** * comprobamos que ninguna select de VS devuelva '', que es un error */ public function test_concatenarCamposSelect2() { $conf = ConfigFramework::getConfig(); $lista = $conf->getVSKeys(); $d = array('phptype'=>'oci8'); foreach($lista as $valor) { $vs = $conf->getDefVS($valor); if (empty($vs['class'])) $this->assertNotEquals('', $this->v->_concatenarCamposSelect($d,$vs['consulta']),'ventana seleccion: '.$valor); } } } ?>