From 49e101efa1d64659d1f4f8a66aaf447876ae6dce Mon Sep 17 00:00:00 2001 From: Eriksen Costa Paixão Date: Fri, 24 Apr 2009 23:50:46 +0000 Subject: [PATCH] #20 by Eriksen: Corrigido bug que impedia atualizar ou excluir um motivo de afastamento de servidor. --- ieducar/intranet/educar_motivo_afastamento_cad.php | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------- ieducar/intranet/include/pmieducar/clsPmieducarMotivoAfastamento.inc.php | 581 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ieducar/tests/functional/ServidorMotivoAfastamentoWebTest.class.php | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 421 insertions(+), 362 deletions(-) create mode 100644 ieducar/tests/functional/ServidorMotivoAfastamentoWebTest.class.php diff --git a/ieducar/intranet/educar_motivo_afastamento_cad.php b/ieducar/intranet/educar_motivo_afastamento_cad.php index f71a0fd..ced6032 100644 --- a/ieducar/intranet/educar_motivo_afastamento_cad.php +++ b/ieducar/intranet/educar_motivo_afastamento_cad.php @@ -1,36 +1,35 @@ cod_motivo_afastamento ); $registro = $obj->detalhe(); + if( $registro ) { - foreach( $registro AS $campo => $val ) // passa todos os valores obtidos no registro para atributos do objeto + foreach( $registro AS $campo => $val ) // passa todos os valores obtidos no registro para atributos do objeto $this->$campo = $val; $obj_escola = new clsPmieducarEscola( $this->ref_cod_escola ); @@ -93,9 +93,10 @@ class indice extends clsCadastro } $retorno = "Editar"; + $this->ref_cod_instituicao = $registro['ref_cod_instituicao']; } } - $this->ref_cod_escola = $registro["ref_cod_escola"]; + $this->url_cancelar = ($retorno == "Editar") ? "educar_motivo_afastamento_det.php?cod_motivo_afastamento={$registro["cod_motivo_afastamento"]}" : "educar_motivo_afastamento_lst.php"; $this->nome_url_cancelar = "Cancelar"; return $retorno; @@ -141,30 +142,33 @@ class indice extends clsCadastro return false; } - function Editar() - { - @session_start(); - $this->pessoa_logada = $_SESSION['id_pessoa']; - @session_write_close(); - $obj_permissoes = new clsPermissoes(); - $obj_permissoes->permissao_cadastra( 633, $this->pessoa_logada, 7, "educar_motivo_afastamento_lst.php" ); + public function Editar() { + session_start(); + $this->pessoa_logada = $_SESSION['id_pessoa']; + session_write_close(); + + $obj_permissoes = new clsPermissoes(); + $obj_permissoes->permissao_cadastra(633, $this->pessoa_logada, 7, + 'educar_motivo_afastamento_lst.php'); + + $obj = new clsPmieducarMotivoAfastamento($this->cod_motivo_afastamento, + $this->pessoa_logada, NULL, $this->nm_motivo, $this->descricao, NULL, + NULL, 1, $this->ref_cod_instituicao); + + $editou = $obj->edita(); + if ($editou) { + $this->mensagem .= 'Edição efetuada com sucesso.
'; + header('Location: educar_motivo_afastamento_lst.php'); + die(); + } + + $this->mensagem = 'Edição não realizada.
'; + return FALSE; + } - $obj = new clsPmieducarMotivoAfastamento( $this->cod_motivo_afastamento, $this->pessoa_logada, null, $this->nm_motivo, $this->descricao, null, null, 1, $this->ref_cod_escola ); - $editou = $obj->edita(); - if( $editou ) - { - $this->mensagem .= "Edição efetuada com sucesso.
"; - header( "Location: educar_motivo_afastamento_lst.php" ); - die(); - return true; - } - $this->mensagem = "Edição não realizada.
"; - echo ""; - return false; - } function Excluir() { @@ -176,7 +180,9 @@ class indice extends clsCadastro $obj_permissoes->permissao_excluir( 633, $this->pessoa_logada, 7, "educar_motivo_afastamento_lst.php" ); - $obj = new clsPmieducarMotivoAfastamento( $this->cod_motivo_afastamento, $this->pessoa_logada, null, $this->nm_motivo, $this->descricao, null, null, 0, $this->ref_cod_escola ); + $obj = new clsPmieducarMotivoAfastamento($this->cod_motivo_afastamento, + $this->pessoa_logada, NULL, $this->nm_motivo, $this->descricao, NULL, + NULL, 0, $this->ref_cod_instituicao); $excluiu = $obj->excluir(); if( $excluiu ) { diff --git a/ieducar/intranet/include/pmieducar/clsPmieducarMotivoAfastamento.inc.php b/ieducar/intranet/include/pmieducar/clsPmieducarMotivoAfastamento.inc.php index b26ecc5..62dda5d 100644 --- a/ieducar/intranet/include/pmieducar/clsPmieducarMotivoAfastamento.inc.php +++ b/ieducar/intranet/include/pmieducar/clsPmieducarMotivoAfastamento.inc.php @@ -1,232 +1,212 @@ _schema = 'pmieducar.'; + $this->_tabela = "{$this->_schema}motivo_afastamento"; + + $this->_campos_lista = $this->_todos_campos = 'cod_motivo_afastamento, ref_usuario_exc, ref_usuario_cad, nm_motivo, descricao, data_cadastro, data_exclusao, ativo, ref_cod_instituicao'; + + if (is_numeric($ref_usuario_cad)) { + + if (class_exists('clsPmieducarUsuario')) { + $tmp_obj = new clsPmieducarUsuario( $ref_usuario_cad ); + if (method_exists($tmp_obj, 'existe')) { + if ($tmp_obj->existe()) { + $this->ref_usuario_cad = $ref_usuario_cad; + } + } + elseif (method_exists($tmp_obj, 'detalhe')) { + if ($tmp_obj->detalhe()) { + $this->ref_usuario_cad = $ref_usuario_cad; + } + } + } + else { + if ($db->CampoUnico("SELECT 1 FROM pmieducar.usuario WHERE cod_usuario = '{$ref_usuario_cad}'")) { + $this->ref_usuario_cad = $ref_usuario_cad; + } + } + + } + + if (is_numeric($ref_usuario_exc)) { + if (class_exists('clsPmieducarUsuario')) { + $tmp_obj = new clsPmieducarUsuario($ref_usuario_exc); + if (method_exists($tmp_obj, 'existe')) { + if ($tmp_obj->existe()) { + $this->ref_usuario_exc = $ref_usuario_exc; + } + } + elseif (method_exists($tmp_obj, 'detalhe')) { + if ($tmp_obj->detalhe()) { + $this->ref_usuario_exc = $ref_usuario_exc; + } + } + } + else { + if ($db->CampoUnico("SELECT 1 FROM pmieducar.usuario WHERE cod_usuario = '{$ref_usuario_exc}'")) { + $this->ref_usuario_exc = $ref_usuario_exc; + } + } + } + + if (is_numeric($cod_motivo_afastamento)) { + $this->cod_motivo_afastamento = $cod_motivo_afastamento; + } + + if (is_string($nm_motivo)) { + $this->nm_motivo = $nm_motivo; + } + + if (is_string( $descricao)) { + $this->descricao = $descricao; + } + + if (is_string($data_cadastro)) { + $this->data_cadastro = $data_cadastro; + } + + if (is_string($data_exclusao)) { + $this->data_exclusao = $data_exclusao; + } + + if (is_numeric($ativo)) { + $this->ativo = $ativo; + } + + if (is_numeric($ref_cod_instituicao)) { + if (class_exists('clsPmieducarInstituicao')) { + $tmp_obj = new clsPmieducarInstituicao( $ref_cod_instituicao ); + if (method_exists($tmp_obj, 'existe')) { + if ($tmp_obj->existe()) { + $this->ref_cod_instituicao = $ref_cod_instituicao; + } + } + elseif (method_exists($tmp_obj, 'detalhe')) { + if ($tmp_obj->detalhe()) { + $this->ref_cod_instituicao = $ref_cod_instituicao; + } + } + } + else { + if ($db->CampoUnico("SELECT 1 FROM pmieducar.instituicao WHERE cod_instituicao = '{$ref_cod_instituicao}'")) { + $this->ref_cod_instituicao = $ref_cod_instituicao; + } + } + } + + } - /** - * Construtor (PHP 4) - * - * @return object - */ - function clsPmieducarMotivoAfastamento( $cod_motivo_afastamento = null, $ref_usuario_exc = null, $ref_usuario_cad = null, $nm_motivo = null, $descricao = null, $data_cadastro = null, $data_exclusao = null, $ativo = null, $ref_cod_instituicao = null ) - { - $db = new clsBanco(); - $this->_schema = "pmieducar."; - $this->_tabela = "{$this->_schema}motivo_afastamento"; - - $this->_campos_lista = $this->_todos_campos = "cod_motivo_afastamento, ref_usuario_exc, ref_usuario_cad, nm_motivo, descricao, data_cadastro, data_exclusao, ativo, ref_cod_instituicao"; - - if( is_numeric( $ref_usuario_cad ) ) - { - if( class_exists( "clsPmieducarUsuario" ) ) - { - $tmp_obj = new clsPmieducarUsuario( $ref_usuario_cad ); - if( method_exists( $tmp_obj, "existe") ) - { - if( $tmp_obj->existe() ) - { - $this->ref_usuario_cad = $ref_usuario_cad; - } - } - else if( method_exists( $tmp_obj, "detalhe") ) - { - if( $tmp_obj->detalhe() ) - { - $this->ref_usuario_cad = $ref_usuario_cad; - } - } - } - else - { - if( $db->CampoUnico( "SELECT 1 FROM pmieducar.usuario WHERE cod_usuario = '{$ref_usuario_cad}'" ) ) - { - $this->ref_usuario_cad = $ref_usuario_cad; - } - } - } - if( is_numeric( $ref_usuario_exc ) ) - { - if( class_exists( "clsPmieducarUsuario" ) ) - { - $tmp_obj = new clsPmieducarUsuario( $ref_usuario_exc ); - if( method_exists( $tmp_obj, "existe") ) - { - if( $tmp_obj->existe() ) - { - $this->ref_usuario_exc = $ref_usuario_exc; - } - } - else if( method_exists( $tmp_obj, "detalhe") ) - { - if( $tmp_obj->detalhe() ) - { - $this->ref_usuario_exc = $ref_usuario_exc; - } - } - } - else - { - if( $db->CampoUnico( "SELECT 1 FROM pmieducar.usuario WHERE cod_usuario = '{$ref_usuario_exc}'" ) ) - { - $this->ref_usuario_exc = $ref_usuario_exc; - } - } - } - - - if( is_numeric( $cod_motivo_afastamento ) ) - { - $this->cod_motivo_afastamento = $cod_motivo_afastamento; - } - if( is_string( $nm_motivo ) ) - { - $this->nm_motivo = $nm_motivo; - } - if( is_string( $descricao ) ) - { - $this->descricao = $descricao; - } - if( is_string( $data_cadastro ) ) - { - $this->data_cadastro = $data_cadastro; - } - if( is_string( $data_exclusao ) ) - { - $this->data_exclusao = $data_exclusao; - } - if( is_numeric( $ativo ) ) - { - $this->ativo = $ativo; - } - if( is_numeric( $ref_cod_instituicao ) ) - { - if( class_exists( "clsPmieducarInstituicao" ) ) - { - $tmp_obj = new clsPmieducarInstituicao( $ref_cod_instituicao ); - if( method_exists( $tmp_obj, "existe") ) - { - if( $tmp_obj->existe() ) - { - $this->ref_cod_instituicao = $ref_cod_instituicao; - } - } - else if( method_exists( $tmp_obj, "detalhe") ) - { - if( $tmp_obj->detalhe() ) - { - $this->ref_cod_instituicao = $ref_cod_instituicao; - } - } - } - else - { - if( $db->CampoUnico( "SELECT 1 FROM pmieducar.instituicao WHERE cod_instituicao = '{$ref_cod_instituicao}'" ) ) - { - $this->ref_cod_instituicao = $ref_cod_instituicao; - } - } - } - } /** * Cria um novo registro @@ -280,66 +260,73 @@ class clsPmieducarMotivoAfastamento return false; } - /** - * Edita os dados de um registro - * - * @return bool - */ - function edita() - { - if( is_numeric( $this->cod_motivo_afastamento ) && is_numeric( $this->ref_usuario_exc ) && is_numeric( $this->ref_cod_instituicao ) ) - { - $db = new clsBanco(); - $set = ""; - if( is_numeric( $this->ref_usuario_exc ) ) - { - $set .= "{$gruda}ref_usuario_exc = '{$this->ref_usuario_exc}'"; - $gruda = ", "; - } - if( is_numeric( $this->ref_usuario_cad ) ) - { - $set .= "{$gruda}ref_usuario_cad = '{$this->ref_usuario_cad}'"; - $gruda = ", "; - } - if( is_string( $this->nm_motivo ) ) - { - $set .= "{$gruda}nm_motivo = '{$this->nm_motivo}'"; - $gruda = ", "; - } - if( is_string( $this->descricao ) ) - { - $set .= "{$gruda}descricao = '{$this->descricao}'"; - $gruda = ", "; - } - if( is_string( $this->data_cadastro ) ) - { - $set .= "{$gruda}data_cadastro = '{$this->data_cadastro}'"; - $gruda = ", "; - } - $set .= "{$gruda}data_exclusao = NOW()"; - $gruda = ", "; - if( is_numeric( $this->ativo ) ) - { - $set .= "{$gruda}ativo = '{$this->ativo}'"; - $gruda = ", "; - } - if( is_numeric( $this->ref_cod_instituicao ) ) - { - $set .= "{$gruda}ref_cod_instituicao = '{$this->ref_cod_instituicao}'"; - $gruda = ", "; - } + /** + * Atualiza um registro. + * + * @param bool TRUE para que seja gravado a data atual no campo + * data_exclusao + * @return bool + */ + public function edita($setDataExclusao = FALSE) { + if (is_numeric($this->cod_motivo_afastamento) && is_numeric($this->ref_usuario_exc) + && is_numeric($this->ref_cod_instituicao)) { - if( $set ) - { - $db->Consulta( "UPDATE {$this->_tabela} SET $set WHERE cod_motivo_afastamento = '{$this->cod_motivo_afastamento}'" ); - return true; - } - } - return false; - } + $db = new clsBanco(); + $set = ''; + + if (is_numeric($this->ref_usuario_exc)) { + $set .= "{$gruda}ref_usuario_exc = '{$this->ref_usuario_exc}'"; + $gruda = ", "; + } + + if (is_numeric($this->ref_usuario_cad)) { + $set .= "{$gruda}ref_usuario_cad = '{$this->ref_usuario_cad}'"; + $gruda = ", "; + } + + if (is_string($this->nm_motivo)) { + $set .= "{$gruda}nm_motivo = '{$this->nm_motivo}'"; + $gruda = ", "; + } + + if (is_string($this->descricao)) { + $set .= "{$gruda}descricao = '{$this->descricao}'"; + $gruda = ", "; + } + + if (is_string($this->data_cadastro)) { + $set .= "{$gruda}data_cadastro = '{$this->data_cadastro}'"; + $gruda = ", "; + } + + if (is_numeric($this->ativo)) { + $set .= "{$gruda}ativo = '{$this->ativo}'"; + $gruda = ", "; + } + + if (is_numeric($this->ref_cod_instituicao)) { + $set .= "{$gruda}ref_cod_instituicao = '{$this->ref_cod_instituicao}'"; + $gruda = ", "; + } + + // Configura a data de exclusão para a data da execução do comando SQL + if ($setDataExclusao == TRUE) { + $set .= $gruda . ' data_exclusao = NOW()'; + } + + if ($set) { + $db->Consulta( "UPDATE {$this->_tabela} SET $set WHERE + cod_motivo_afastamento = '{$this->cod_motivo_afastamento}'"); + + return TRUE; + } + } + + return FALSE; + } /** * Retorna uma lista filtrados de acordo com os parametros @@ -486,28 +473,29 @@ class clsPmieducarMotivoAfastamento return false; } - /** - * Exclui um registro - * - * @return bool - */ - function excluir() - { - if( is_numeric( $this->cod_motivo_afastamento ) && is_numeric( $this->ref_usuario_exc ) ) - { - /* - delete - $db = new clsBanco(); - $db->Consulta( "DELETE FROM {$this->_tabela} WHERE cod_motivo_afastamento = '{$this->cod_motivo_afastamento}'" ); - return true; - */ - $this->ativo = 0; - return $this->edita(); - } - return false; - } + + /** + * Marca um registro como inativo. + * + * O registro é marcado como inativo para que outros registros que usam + * esta tabela em um relacionamento possam recuperar a informação + * complementar, nesse caso, um motivo de afastamento. + * + * @return bool + */ + public function excluir() { + if (is_numeric($this->cod_motivo_afastamento) && is_numeric($this->ref_usuario_exc)) { + $this->ativo = 0; + + return $this->edita(TRUE); + } + + return FALSE; + } + + /** * Define quais campos da tabela serao selecionados na invocacao do metodo lista @@ -589,5 +577,4 @@ class clsPmieducarMotivoAfastamento return ""; } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/ieducar/tests/functional/ServidorMotivoAfastamentoWebTest.class.php b/ieducar/tests/functional/ServidorMotivoAfastamentoWebTest.class.php new file mode 100644 index 0000000..1776e18 --- /dev/null +++ b/ieducar/tests/functional/ServidorMotivoAfastamentoWebTest.class.php @@ -0,0 +1,66 @@ + + * @since 1.0.1 + * @version SVN: $Id$ + */ + +require_once realpath(dirname(__FILE__) . '/../') . '/FunctionalBaseTest.class.php'; + +class ServidorMotivoAfastamentoWebTest extends FunctionalBaseTest { + + /** + * Os testes a seguir cobrem o bug report #20. + * + * @link http://svn.softwarepublico.gov.br/trac/ieducar/ticket/20 Bug report #20 + * @{ + */ + public function createNewEntry() { + $this->open("/intranet/educar_motivo_afastamento_lst.php"); + $this->clickAndWait("//input[@value=' Novo ']"); + $this->select("ref_cod_instituicao", "label=COBRA Tecnologia"); + $this->type("nm_motivo", "Motivo teste"); + $this->clickAndWait("btn_enviar"); + } + + public function testMotivoAfastamentoUpdate() { + $this->doLogin(); + $this->createNewEntry(); + + $this->open("/intranet/educar_motivo_afastamento_cad.php?cod_motivo_afastamento=1"); + $this->select("ref_cod_instituicao", "label=COBRA Tecnologia"); + $this->type("nm_motivo", "Motivo teste"); + $this->clickAndWait("btn_enviar"); + + $statusMessage = $this->isTextPresent("Edição não realizada."); + $this->assertTrue(!$statusMessage); + $this->doLogout(); + } + + public function testMotivoAfastamentoDelete() { + $this->doLogin(); + + $this->open("/intranet/educar_motivo_afastamento_lst.php"); + $this->clickAndWait("link=Motivo teste"); + $this->clickAndWait("//input[@value=' Editar ']"); + $this->clickAndWait("//input[@value=' Excluir ']"); + $this->assertTrue((bool)preg_match('/^Excluir registro[\s\S]$/',$this->getConfirmation())); + $statusMessage = $this->isTextPresent("Exclusão não realizada."); + $this->assertTrue(!$statusMessage); + + $this->doLogout(); + } + /** + * }@ + */ + +} \ No newline at end of file -- libgit2 0.21.2