From 8f87639b36eb29502d6422c395635ec82ddd2001 Mon Sep 17 00:00:00 2001 From: bjverde Date: Sun, 7 Feb 2021 23:27:32 -0300 Subject: [PATCH] :hammer: BASE update version 5.0.0-alpha22 --- .../FormDin5/helpers/ArrayHelper.class.php | 28 +++ .../FormDin5/helpers/FormDinHelper.class.php | 26 ++- .../FormDin5/helpers/ValidateHelper.class.php | 44 +++++ .../FormDinFields/TFormDinFileField.class.php | 176 +++++++++++++++++ .../TFormDinGenericField.class.php | 77 +++++++- .../FormDinFields/TFormDinMemoField.class.php | 59 ++++-- .../FormDinGrid/TFormDinGridAction.class.php | 12 ++ .../FormDin5/webform/TFormDin.class.php | 187 +++++++++++++++--- .../FormDin5/webform/TFormDinGrid.class.php | 26 ++- .../webform/TFormDinMessage.class.php | 17 +- .../FormDin5/helpers/ArrayHelperTest.php | 42 +++- .../FormDin5/helpers/FormDinHelperTest.php | 2 +- .../FormDin5/helpers/ValidateHelperTest.php | 35 ++++ .../FormDinFields/TFormDinFileFieldTest.php | 83 ++++++++ .../FormDinFields/TFormDinMemoFieldTest.php | 34 +++- .../widget/FormDin5/webform/TFormDinTest.php | 57 ++++++ 16 files changed, 824 insertions(+), 81 deletions(-) create mode 100644 FormDin5/lib/widget/FormDin5/webform/FormDinFields/TFormDinFileField.class.php create mode 100644 FormDin5/tests/lib/widget/FormDin5/webform/FormDinFields/TFormDinFileFieldTest.php diff --git a/FormDin5/lib/widget/FormDin5/helpers/ArrayHelper.class.php b/FormDin5/lib/widget/FormDin5/helpers/ArrayHelper.class.php index 348cd635..89d50049 100644 --- a/FormDin5/lib/widget/FormDin5/helpers/ArrayHelper.class.php +++ b/FormDin5/lib/widget/FormDin5/helpers/ArrayHelper.class.php @@ -834,6 +834,34 @@ public static function convertArray2OutputFormat($arrayData,$outputFormat = Arra } return $result; } + //-------------------------------------------------------------------------------- + /** + * Recebe um array do tipo ArrayHelper::TYPE_ADIANTI, ArrayHelper::TYPE_PDO, ArrayHelper::TYPE_FORMDIN + * para um array TYPE_PHP no formato 'KEY=VALUE,KEY=VALUE' + * + * @param array $arrayData - 1: Array de entrada + * @param string $keyColumn - 2: String nome da coluna chave + * @param string $valueColumn - 3: String nome da coluna valor + * @param const $typeCase - 4: Type Case. Default = PDO::CASE_NATURAL, PDO::CASE_UPPER, PDO::CASE_LOWER + * @return array + */ + public static function convertArray2PhpKeyValue($arrayData,$keyColumn,$valueColumn,$typeCase = PDO::CASE_NATURAL) + { + ValidateHelper::isString($keyColumn,__METHOD__,__LINE__); + ValidateHelper::isString($valueColumn,__METHOD__,__LINE__); + $arrayData = ArrayHelper::convertArray2OutputFormat($arrayData,ArrayHelper::TYPE_PDO,$typeCase); + if( !array_key_exists($keyColumn, $arrayData[0]) ) { + throw new InvalidArgumentException(TFormDinMessage::ERROR_TYPE_WRONG); + } + if( !array_key_exists($valueColumn, $arrayData[0]) ) { + throw new InvalidArgumentException(TFormDinMessage::ERROR_TYPE_WRONG); + } + $arrayResult = array(); + foreach( $arrayData as $key => $arrayInterno ) { + $arrayResult[ $arrayInterno[$keyColumn] ] = $arrayInterno[$valueColumn]; + } + return $arrayResult; + } } ?> \ No newline at end of file diff --git a/FormDin5/lib/widget/FormDin5/helpers/FormDinHelper.class.php b/FormDin5/lib/widget/FormDin5/helpers/FormDinHelper.class.php index 655004cd..cadd6acf 100644 --- a/FormDin5/lib/widget/FormDin5/helpers/FormDinHelper.class.php +++ b/FormDin5/lib/widget/FormDin5/helpers/FormDinHelper.class.php @@ -58,7 +58,7 @@ class FormDinHelper { - const FORMDIN_VERSION = '5.0.0-alpha20'; + const FORMDIN_VERSION = '5.0.0-alpha22'; const GRID_SIMPLE = 'GRID_SIMPLE'; const GRID_SCREEN_PAGINATION = 'GRID_SCREEN_PAGINATION'; const GRID_SQL_PAGINATION = 'GRID_SQL_PAGINATION'; @@ -234,6 +234,15 @@ public static function issetOrNotZero($variable,$testZero=true) /** * @codeCoverageIgnore + * Alias da função debug. + * Para depuração. Exibe o modulo a linha e a variável/objeto solicitado + * Retirado do FormDin 4.9.0 + * https://github.com/bjverde/formDin/blob/master/base/includes/funcoes.inc + * + * @param [type] $mixExpression váriavel que irá mostrar o resultado + * @param string $strComentario Titulo que irá aparecer + * @param boolean $boolExit + * @return void */ public static function d( $mixExpression,$strComentario='Debug', $boolExit=FALSE ) { @@ -245,6 +254,11 @@ public static function d( $mixExpression,$strComentario='Debug', $boolExit=FALSE * função para depuração. Exibe o modulo a linha e a variável/objeto solicitado * Retirado do FormDin 4.9.0 * https://github.com/bjverde/formDin/blob/master/base/includes/funcoes.inc + * + * @param [type] $mixExpression váriavel que irá mostrar o resultado + * @param string $strComentario Titulo que irá aparecer + * @param boolean $boolExit + * @return void */ public static function debug( $mixExpression,$strComentario='Debug', $boolExit=FALSE ) { ini_set ( 'xdebug.max_nesting_level', 150 ); @@ -265,17 +279,21 @@ public static function debug( $mixExpression,$strComentario='Debug', $boolExit=F echo ''; echo ''; } else { + echo '
'; echo '
'; echo ""; echo "
".$strComentario."
" ;
+            echo "file: ".$arrBacktrace[0]['file']."\n";
+            echo "line: ".$arrBacktrace[0]['line']."\n";
+            /*
             foreach ( $arrBacktrace[0] as $strAttribute => $mixValue ) {
                 if( !is_array($mixValue) ) {
                     echo "" . $strAttribute . " ". $mixValue ."\n";
                 }
             }
-            echo "

"; - echo ''.$strComentario.''."\n";; - echo '
';
+            */
+            echo "
"; + echo "
"; if( is_object($mixExpression) ) { var_dump( $mixExpression ); } else { diff --git a/FormDin5/lib/widget/FormDin5/helpers/ValidateHelper.class.php b/FormDin5/lib/widget/FormDin5/helpers/ValidateHelper.class.php index 9a56bcc4..2e5e4ca4 100644 --- a/FormDin5/lib/widget/FormDin5/helpers/ValidateHelper.class.php +++ b/FormDin5/lib/widget/FormDin5/helpers/ValidateHelper.class.php @@ -60,6 +60,14 @@ public static function methodLine($method,$line,$nameMethodValidate) } } + public static function isString($string,$method,$line) + { + self::methodLine($method, $line, __METHOD__); + if( empty($string) || !is_string($string) ){ + throw new InvalidArgumentException(TFormDinMessage::ERROR_TYPE_NOT_STRING.'See the method: '.$method.' in the line: '.$line); + } + } + public static function isNumeric($id,$method,$line) { self::methodLine($method, $line, __METHOD__); @@ -140,6 +148,18 @@ public static function typeErrorMsg($typeErroMsg) return $complemento; } //-------------------------------------------------------------------------------- + /** + * Usado para fazer a validação de um parametro do metodo da migração do FormDin4 para o FormDin5 + * + * @param string $paramName nome do parametro + * @param [type] $paramValue valor informado + * @param const $typeErro ValidateHelper::NOTICIE, ValidateHelper::WARNING e ValidateHelper::ERROR + * @param const $typeErroMsg + * @param [type] $class + * @param [type] $method + * @param string $line + * @return void + */ public static function validadeParam($paramName,$paramValue,$typeErro,$typeErroMsg,$class,$method,$line) { $test = isset($paramValue) && !empty($paramValue); @@ -157,6 +177,30 @@ public static function validadeParam($paramName,$paramValue,$typeErro,$typeErroM } } //-------------------------------------------------------------------------------- + /** + * Usado para fazer a validação de um metodo da migração do FormDin4 para o FormDin5 + * + * @param const $typeErro ValidateHelper::NOTICIE, ValidateHelper::WARNING e ValidateHelper::ERROR + * @param const $typeErroMsg + * @param const $method + * @param string $complementoMsg + * @param string $file + * @param string $line + */ + public static function validadeMethod($typeErro,$typeErroMsg,$method,$complementoMsg,$file,$line) + { + $complemento = self::typeErrorMsg($typeErroMsg); + $complemento = !empty($complementoMsg)?$complemento.' '.$complementoMsg:$complemento; + + $msg = TFormDinMessage::ERROR_FD5_PARAM_MIGRA + .' O metodo: '.$method + .$complemento + .', no arquivo: '.$file + .', na linha: '.$line + ; + self::triggerError($msg,$typeErro); + } + //-------------------------------------------------------------------------------- public static function migrarMensage($mensagem,$typeErro,$typeErroMsg,$class,$method,$line,$arquivo=null) { $test = isset($mensagem) && !empty($mensagem); diff --git a/FormDin5/lib/widget/FormDin5/webform/FormDinFields/TFormDinFileField.class.php b/FormDin5/lib/widget/FormDin5/webform/FormDinFields/TFormDinFileField.class.php new file mode 100644 index 00000000..a7c4e25b --- /dev/null +++ b/FormDin5/lib/widget/FormDin5/webform/FormDinFields/TFormDinFileField.class.php @@ -0,0 +1,176 @@ + + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Formdin. + * + * O Framework Formdin é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ + + +/** + * Classe para criação campo com mascará + * ------------------------------------------------------------------------ + * Esse é o FormDin 5, que é uma reconstrução do FormDin 4 Sobre o Adianti 7.X + * os parâmetros do metodos foram marcados com: + * + * NOT_IMPLEMENTED = Parâmetro não implementados, talvez funcione em + * verões futuras do FormDin. Não vai fazer nada + * DEPRECATED = Parâmetro que não vai funcionar no Adianti e foi mantido + * para o impacto sobre as migrações. Vai gerar um Warning + * FORMDIN5 = Parâmetro novo disponivel apenas na nova versão + * ------------------------------------------------------------------------ + * + * @author Reinaldo A. Barrêto Junior + */ +class TFormDinFileField extends TFormDinGenericField +{ + private $maxSize; + private $maxSizeKb; + private $allowedFileTypes; + private $msgUploadException; + + + /** + * Campo de uso geral para insersão manual de códigos html na página + * ------------------------------------------------------------------------ + * Esse é o FormDin 5, que é uma reconstrução do FormDin 4 Sobre o Adianti 7.X + * os parâmetros do metodos foram marcados veja documentação da classe para + * saber o que cada marca singinifica. + * ------------------------------------------------------------------------ + * + * Se o label for null, não será criado o espaço referente a ele no formulário, para criar + * um label invisível defina como "" o seu valor + * + * criado o espaço + * @param string $strName - 01: ID do campo + * @param string $strValue - 02: Texto HTML que irá aparece dentro + * @param boolean $boolRequired - 03: Obrigatorio + * @param mixed $strAllowedFileTypes - 04: Tipos de arquivos. String separado por virgular ou array + * @param string $strIncludeFile - 05: NOT_IMPLEMENTED Arquivo que será incluido + * @param string $strLabel - 06: Label do campo + * @param string $strWidth - 07: NOT_IMPLEMENTED + * @param string $strHeight - 09: NOT_IMPLEMENTED + * @param boolean $enableFileHandling -13: FORMDIN5 Habilita barra de progresso + * @param boolean $enablePopover -14: FORMDIN5 Habilita o preview + * @return THtml Field + */ + public function __construct( string $id + , string $label + , $boolRequired = false + , $strAllowedFileTypes=null + , $intSize=null + , $strMaxSize=null + , $enableFileHandling = false + , $enablePopover = false + ) + { + $this->setAllowedFileTypes( $strAllowedFileTypes ); + + $adiantiObj = new TFile($label); + $adiantiObj->setAllowedExtensions( $this->getAllowedFileTypes() ); + //$adiantiObj->enableFileHandling(); + //$adiantiObj->enablePopover(); + $this->enableFileHandling($enableFileHandling); + if( $enablePopover==true ){ + $this->enablePopover(); + } + + $post = $adiantiObj->getPostData(); + //FormDinHelper::debug($post); + + $label = is_null($label)?'':$label; + parent::__construct($adiantiObj,$id,$label,$boolRequired,null,null); + + return $this->getAdiantiObj(); + } + + public function setAllowedFileTypes($strNewFileTypes=null) + { + if( is_string($strNewFileTypes) ){ + $strNewFileTypes = strtolower($strNewFileTypes); + $strNewFileTypes = explode(',',$strNewFileTypes); + } + $this->allowedFileTypes = $strNewFileTypes; + } + public function getAllowedFileTypes() + { + return $this->allowedFileTypes; + } + + public function setCompleteAction(TAction $action) + { + return $this->getAdiantiObj()->setCompleteAction($action); + } + public function setErrorAction(TAction $action) + { + return $this->getAdiantiObj()->setErrorAction($action); + } + + /** + * Habilita barra de progresso + * + * @param boolean $enableFileHandling + */ + public function enableFileHandling($enableFileHandling=true) + { + if( $enableFileHandling==true ){ + $this->getAdiantiObj()->enableFileHandling(); + } + } + + /** + * Habilita o preview + * + * @param string $title titulo + * @param string $content + */ + public function enablePopover($title = null, $content = '') + { + $this->getAdiantiObj()->enablePopover($title,$content); + } + + /** + * Define a classe de serviço que irá processar o upload dos arquivos. O Valor padrão é AdiantiUploaderService + * + * @param string $service + */ + public function setService($service) + { + $this->getAdiantiObj()->setService($service); + } + +} \ No newline at end of file diff --git a/FormDin5/lib/widget/FormDin5/webform/FormDinFields/TFormDinGenericField.class.php b/FormDin5/lib/widget/FormDin5/webform/FormDinFields/TFormDinGenericField.class.php index a55c1938..70189eee 100644 --- a/FormDin5/lib/widget/FormDin5/webform/FormDinFields/TFormDinGenericField.class.php +++ b/FormDin5/lib/widget/FormDin5/webform/FormDinFields/TFormDinGenericField.class.php @@ -203,6 +203,58 @@ public function setPlaceHolder($placeholder){ public function getPlaceHolder(){ return $this->getAdiantiObj()->placeholder; } + //----------------------------------------------------------------------------- + /** + * Método para criar ajuda on-line. + * O parametro $strHelpFile recebe o nome de um arquivo com conteudo html/php para ser exibido. + * O arquivo deverá estar no diretório app/resources/ + * + * Poder ser informada tambem o endereço (url) da pagina de help + * + * + * Exemplo01: $nom->setHelpFile('Nome da Pessoa',200,500,'ajuda_form01.html'); + * Exemplo02: $nom->setHelpFile('Nome da Pessoa',200,500,'http://localhost/sistema/texto_ajuda.html'); + * Exemplo03: $nom->setHelpFile('Nome da Pessoa',200,500,'Meu texto de ajuda', null, null, false); + * + * + * @param mixed $strWindowHeader- 01: + * @param mixed $intShowHeight - 02: DEPRECATED: INFORME NULL para remover o Warning + * @param mixed $intShowWidth - 03: DEPRECATED: INFORME NULL para remover o Warning + * @param mixed $strHelpFile - 04: nome do arquivo que será carregado dentro do box + * @param mixed $strButtonImage - 05: imagem que aparecerá na frente do label + * @param boolean $boolReadOnly + * @param boolean $showFile - true mostra o conteudo de um arquivo, FALSE mostra a mensagem de texto informada no $strHelpFile + */ + public function setHelpOnLine( $strWindowHeader = null + , $intShowHeight = null + , $intShowWidth = null + , $strHelpFile = null + , $strButtonImage = null + , $boolReadOnly = null + , $showFile = true) + { + /* + $strHelpFile =is_null( $strHelpFile ) ? $this->getId() : $strHelpFile; + $this->helpFile[0]=$strHelpFile; + + if ( $strHelpFile ) + { + $this->helpFile[1]=is_null( $strWindowHeader ) ? "Ajuda on-line" : $strWindowHeader; + $this->helpFile[2]=is_null( $intShowHeight ) ? 600 : $intShowHeight; + $this->helpFile[3]=is_null( $intShowWidth ) ? 800 : $intShowWidth; + $this->helpFile[4]=is_null( $strButtonImage ) ? $this->getBase().'imagens/icon_help-16x16.png' : $strButtonImage; + $this->helpFile[5]=is_null( $boolReadOnly ) ? false : $boolReadOnly; + $this->helpFile[6]=''; + $this->helpFile[7]=is_null( $showFile ) ? true : $showFile; + if( preg_match('/\.\.\//',$this->getBase()) > 0 ) { + $this->helpFile[6]=APLICATIVO; + } + if ( strpos( $this->helpFile[4], '/' ) === false ) { + $this->helpFile[4] = $this->getBase().'imagens/'.$this->helpFile[4]; + } + } + */ + } //------------------------------------------------------------------------------ /** * Set um Toolpit do FormDin para funcionar com Adianti @@ -262,5 +314,28 @@ public function getClass() { return $this->getAdiantiObj()->getProperty('class'); } - //------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ + /** + * DEPRECADED - change to setClass. + * + * @deprecated + * @codeCoverageIgnore + * + * @param mixed $mixProperty + * @param string $newValue + */ + public function setCss( $mixProperty, $newValue = null ) + { + if( !empty($mixProperty) ){ + $arrBacktrace = debug_backtrace(); + ValidateHelper::validadeMethod(ValidateHelper::WARNING + ,ValidateHelper::MSG_DECREP + ,'setCss' + ,'use o metodo setClass' + ,$arrBacktrace[0]['file'] + ,$arrBacktrace[0]['line'] + ); + } + + } } \ No newline at end of file diff --git a/FormDin5/lib/widget/FormDin5/webform/FormDinFields/TFormDinMemoField.class.php b/FormDin5/lib/widget/FormDin5/webform/FormDinFields/TFormDinMemoField.class.php index d98e49ef..db4e28e1 100644 --- a/FormDin5/lib/widget/FormDin5/webform/FormDinFields/TFormDinMemoField.class.php +++ b/FormDin5/lib/widget/FormDin5/webform/FormDinFields/TFormDinMemoField.class.php @@ -61,6 +61,9 @@ class TFormDinMemoField extends TFormDinGenericField private $showCountChar; private $intMaxLength; + private $adiantiObjTText; //Somente obj Adianti TText + private $adiantiObjFull; //obj Adianti completo com todos os elementos para fazer o memo + /** * Adicionar campo de entrada de texto com multiplas linhas ( memo ) equivalente ao html textarea * ------------------------------------------------------------------------ @@ -88,8 +91,8 @@ public function __construct($id , $label=null , $intMaxLength , $boolRequired=null - , $intColumns='20px' - , $intRows='5px' + , $intColumns='100%' + , $intRows='100%' , $boolNewLine=null , $boolLabelAbove=null , $boolShowCounter=null @@ -98,22 +101,30 @@ public function __construct($id , $placeholder=null , $boolShowCountChar=true) { - $adiantiObj = new TText($id); - parent::__construct($adiantiObj,$id,$label,$boolRequired,$value,$placeholder); - $this->setMaxLength($label,$intMaxLength); + $this->setAdiantiObjTText($id); + parent::__construct($this->getAdiantiObjTText(),$id,$label,$boolRequired,$value,$placeholder); $this->setSize($intColumns, $intRows); + $this->setMaxLength($label,$intMaxLength); $this->setShowCountChar($boolShowCountChar); + $this->setAdiantiObjTFull($id,$boolShowCountChar,$intMaxLength); return $this->getAdiantiObj(); } - public function getFullComponent() + public function setAdiantiObjTText($id){ + $this->adiantiObjTText = new TText($id); + } + public function getAdiantiObjTText(){ + return $this->adiantiObjTText; + } + + private function setAdiantiObjTFull( $idField, $boolShowCountChar,$intMaxLength ) { - $adiantiObj = parent::getAdiantiObj(); - $intMaxLength = $this->getMaxLength(); - if( $this->getShowCountChar() && ($intMaxLength>=1) ){ - $adiantiObj = parent::getAdiantiObj(); - $adiantiObj->setProperty('onkeyup', 'fwCheckNumChar(this,'.$intMaxLength.');'); - $idField = $adiantiObj->getId(); + $adiantiObjTText = $this->getAdiantiObjTText(); + $adiantiObj = null; + if( $boolShowCountChar && ($intMaxLength>=1) ){ + $adiantiObjTText->maxlength = $intMaxLength; + $adiantiObjTText->setId($idField); + $adiantiObjTText->setProperty('onkeyup', 'fwCheckNumChar(this,'.$intMaxLength.');'); $charsText = new TElement('span'); $charsText->setProperty('id',$idField.'_counter'); @@ -125,13 +136,17 @@ public function getFullComponent() $script->setProperty('src', 'app/lib/include/FormDin5.js'); $div = new TElement('div'); - $div->add($adiantiObj); + $div->add($adiantiObjTText); $div->add('
'); $div->add($charsText); $div->add($script); $adiantiObj = $div; } - return $adiantiObj; + $adiantiObj = empty($adiantiObj)?$adiantiObjTText:$adiantiObj; + $this->adiantiObjFull = $adiantiObj; + } + public function getAdiantiObjFull(){ + return $this->adiantiObjFull; } public function setMaxLength($label,$intMaxLength) @@ -147,15 +162,17 @@ public function getMaxLength() return $this->intMaxLength; } - protected function testSize($value) + public function testSize($value) { - if(preg_match(self::REGEX, $value,$output)){ - //FormDinHelper::debug($output); - if($output[2]=='px'){ - $value = $output[1]; + if( !empty($value) ){ + if( preg_match(self::REGEX, $value,$output) ){ + //FormDinHelper::debug($output); + if($output[2]=='px'){ + $value = $output[1]; + } + }else{ + throw new InvalidArgumentException('use % ou px'); } - }else{ - throw new InvalidArgumentException('use % ou px'); } return $value; } diff --git a/FormDin5/lib/widget/FormDin5/webform/FormDinGrid/TFormDinGridAction.class.php b/FormDin5/lib/widget/FormDin5/webform/FormDinGrid/TFormDinGridAction.class.php index ac4ebc6e..077dad11 100644 --- a/FormDin5/lib/widget/FormDin5/webform/FormDinGrid/TFormDinGridAction.class.php +++ b/FormDin5/lib/widget/FormDin5/webform/FormDinGrid/TFormDinGridAction.class.php @@ -107,4 +107,16 @@ public function getImage(){ public function setImage($image){ $this->image = $image; } + //------------------------------------------------------------------------- + public function setDisplayCondition( /*Callable*/ $displayCondition ) + { + $this->getAdiantiObj()->setDisplayCondition($displayCondition); + } + /** + * Returns the action display condition + */ + public function getDisplayCondition() + { + return $this->getAdiantiObj()->getDisplayCondition(); + } } \ No newline at end of file diff --git a/FormDin5/lib/widget/FormDin5/webform/TFormDin.class.php b/FormDin5/lib/widget/FormDin5/webform/TFormDin.class.php index e40f532d..8246a688 100644 --- a/FormDin5/lib/widget/FormDin5/webform/TFormDin.class.php +++ b/FormDin5/lib/widget/FormDin5/webform/TFormDin.class.php @@ -69,7 +69,7 @@ class TFormDin private $listFormElements = array(); /** - * Método construtor da classe do Formulario Padronizado em BoorStrap + * Método construtor da classe do Formulario Padronizado em BootStrap * ------------------------------------------------------------------------ * Esse é o FormDin 5, que é uma reconstrução do FormDin 4 Sobre o Adianti 7.X * os parâmetros do metodos foram marcados veja documentação da classe para @@ -342,10 +342,10 @@ public function show() } /** - * Adciona um Objeto Adianti na lista de objetos que compeen o Formulário. + * Adciona um Objeto Adianti na lista de objetos que compõem o Formulário. * * @param object $obj - 1: objeto Adianti - * @param string $type - 2: Typo confirmo constante + * @param string $type - 2: Type conforme constante. TFormDin::TYPE_FIELD, TYPE_LAYOUT, TYPE_ADIANTI_FIELD_NATIVE * @param object $label - 3: objeto do tipo Label do $obj * @param boolean $boolNewLine - 4: DEFAULT = True = campo em nova linha. FALSE = mesma linha * @param boolean $boolLabelAbove - 5: DEFAULT = FALSE = Label na frente do campo. TRUE = Label sobre o campo @@ -771,7 +771,7 @@ public function addTextField(string $id * @param string $strName - 1: ID do campo * @param string $strLabel - 2: Label * @param integer $intMaxLength - 3: Tamanho maximos - * @param boolean $boolRequired - 4: Obrigatorio + * @param boolean $boolRequired - 4: Campo obrigatório ou não. Default FALSE = não obrigatório, TRUE = obrigatório * @param integer $intColumns - 5: Largura use px ou %, valores inteiros serão multiplicados 1.5 e apresentado em px * @param integer $intRows - 6: Altura use px ou %, valores inteiros serão multiplicados 4 e apresentado em px * @param boolean $boolNewLine - 7: Default TRUE = cria nova linha , FALSE = fica depois do campo anterior @@ -779,7 +779,7 @@ public function addTextField(string $id * @param boolean $boolShowCounter - 9: NOT_IMPLEMENTED Contador de caracteres ! Só funciona em campos não RichText * @param string $strValue - 10: texto preenchido * @param string $boolNoWrapLabel - 11: NOT_IMPLEMENTED - * @param string $placeholder - 12: FORMDIN5 PlaceHolder é um Texto de exemplo + * @param string $placeholder - 12: FORMDIN5 PlaceHolder é um Texto de exemplo`. DEFAULT = true * @param string $boolShowCountChar 13: FORMDIN5 Mostra o contador de caractes. Default TRUE = mostra, FASE = não mostra * @return TFormDinMemoField */ @@ -809,10 +809,8 @@ public function addMemoField( $strName , $placeholder , $boolShowCountChar ); - $objField = $formField->getFullComponent(); - //$objField = $formField->getAdiantiObj(); + $objField = $formField->getAdiantiObjFull(); $label = $formField->getLabel(); - //$this->addFields($label ,$objField ,$boolLabelAbove); $this->addElementFormList($objField,self::TYPE_FIELD,$label,$boolNewLine,$boolLabelAbove); return $formField; } @@ -823,7 +821,7 @@ public function addMemoField( $strName * * @param string $strName - 1: Id do Campo * @param string $strLabel - 2: Label do Campo - * @param boolean $boolRequired - 3: DEFAULT = false não obrigatório + * @param boolean $boolRequired - 3: Campo obrigatório ou não. Default FALSE = não obrigatório, TRUE = obrigatório * @param boolean $boolNewLine - 4: Default TRUE = campo em nova linha, FALSE continua na linha anterior * @param string $strValue - 5: Valor inicial * @param string $strMinValue - 6: Menor data que o campo aceita @@ -877,7 +875,7 @@ public function addDateField( $strName * * @param string $strName - 1: Id do Campo * @param string $strLabel - 2: Label do Campo - * @param boolean $boolRequired - 3: DEFAULT = false não obrigatório + * @param boolean $boolRequired - 3: Campo obrigatório ou não. Default FALSE = não obrigatório, TRUE = obrigatório * @param boolean $boolNewLine - 4: Default TRUE = campo em nova linha, FALSE continua na linha anterior * @param string $strValue - 5: Valor inicial * @param string $strMinValue - 6: Menor data que o campo aceita @@ -935,7 +933,7 @@ public function addDateTimeField( $strName * * @param string $id - 1: ID do campo * @param string $strLabel - 2: Label do campo - * @param boolean $boolRequired - 3: Obrigatorio + * @param boolean $boolRequired - 3: Campo obrigatório ou não. Default FALSE = não obrigatório, TRUE = obrigatório * @param array $itens - 4: Informe um array do tipo "chave=>valor", com maximo de 2 elementos * @param boolean $boolNewLine - 5: Default TRUE = cria nova linha , FALSE = fica depois do campo anterior * @param boolean $boolLabelAbove- 6: Label sobre o campo. Default FALSE = Label mesma linha, TRUE = Label acima @@ -957,6 +955,71 @@ public function addSwitchField(string $id return $formField; } + /** + * Campos para anexar arquivo. Pode ser um carregamento sincrono ou assincrono via ajax. + * ------------------------------------------------------------------------ + * Esse é o FormDin 5, que é uma reconstrução do FormDin 4 Sobre o Adianti 7.X + * os parâmetros do metodos foram marcados veja documentação da classe para + * saber o que cada marca singinifica. + * ------------------------------------------------------------------------ + * + * Será incluido no $_POST 4 elementos com os nomes: + * + * $_POST['strName_temp'] - caminho temporario; + * $_POST['strName_type'] - mime type; + * $_POST['strName_size'] - tamanho em kb; + * $_POST['strName_name'] - nome arquivo; + * + * + * @param string $id - 01: id do campo + * @param string $strLabel - 02: Rotulo do campo que irá aparece na tela + * @param boolean $boolRequired - 03: Campo obrigatório ou não. Default FALSE = não obrigatório, TRUE = obrigatório + * @param mixed $strAllowedFileTypes - 04: Tipos de arquivos. String separado por virgular ou array + * @param string $strMaxFileSize - 05: Input the max size file with K, M for Megabit (Mb) or G for Gigabit (Gb). Example 2M = 2 Mb = 2048Kb. + * @param integer $intFieldSize - 06: NOT_IMPLEMENTED + * @param boolean $boolAsync - 07: NOT_IMPLEMENTED + * @param boolean $boolNewLine - 08: NOT_IMPLEMENTED + * @param string $strJsCallBack - 09: NOT_IMPLEMENTED + * @param boolean $boolLabelAbove - 10: Label sobre o campo. Default FALSE = Label mesma linha, TRUE = Label acima + * @param boolean $boolNoWrapLabel - 11: NOT_IMPLEMENTED + * @param string $strMessageInvalidFileType - 12: NOT_IMPLEMENTED + * @param boolean $enableFileHandling -13: FORMDIN5 Habilita barra de progresso + * @param boolean $enablePopover -14: FORMDIN5 Habilita o preview + * @return TFile|TFileAsync + */ + public function addFileField(string $id + , string $strLabel + , $boolRequired = false + , $strAllowedFileTypes=null + , $strMaxFileSize=null + , $intFieldSize=null + , $boolAsync=null + , $boolNewLine=null + , $strJsCallBack=null + , $boolLabelAbove=true + , $boolNoWrapLabel=null + , $strMessageInvalidFileType=null + , $enableFileHandling=false + , $enablePopover=false + ) + { + $formField = new TFormDinFileField($id + ,$strLabel + ,$boolRequired + ,$strAllowedFileTypes + ,$intFieldSize + ,$strMaxFileSize + ,$enableFileHandling + ,$enablePopover + ); + $objField = $formField->getAdiantiObj(); + $label = $formField->getLabel(); + //$this->addFields($label ,$objField ,$boolLabelAbove); + $this->addElementFormList($objField,self::TYPE_FIELD,$label,$boolNewLine,$boolLabelAbove); + + return $formField; + } + /** * Adicionar campo entrada de dados texto com mascara * ------------------------------------------------------------------------ @@ -971,7 +1034,7 @@ public function addSwitchField(string $id * * @param string $id - 1: id do campo * @param string $strLabel - 2: Rotulo do campo que irá aparece na tela - * @param boolean $boolRequired - 3: Obrigatorio + * @param boolean $boolRequired - 3: Campo obrigatório ou não. Default FALSE = não obrigatório, TRUE = obrigatório * @param string $strMask - 4: A mascara * @param boolean $boolNewLine - 5: Default TRUE = cria nova linha , FALSE = fica depois do campo anterior * @param string $strValue - 6: texto preenchido @@ -1013,7 +1076,7 @@ public function addMaskField( $id * * @param string $strName - 1: id do campo * @param string $strLabel - 2: Rotulo do campo que irá aparece na tela - * @param boolean $boolRequired - 3: True = Obrigatorio; False (Defalt) = Não Obrigatorio + * @param boolean $boolRequired - 3: Campo obrigatório ou não. Default FALSE = não obrigatório, TRUE = obrigatório * @param string $strMinValue - 4: Menor Valor * @param string $strMaxValue - 5: Maior valor * @param string $strMaskType - 6: HM, HMS @@ -1090,9 +1153,9 @@ public function addTimeField( $strName * @param integer $intSize - 09: NOT_IMPLEMENTED Default 1. Num itens que irão aparecer. * @param integer $intWidth - 10: DEPRECATED. Informe NULL para evitar o warning. Largura em Pixels * @param string $strFirstOptionText - 11: NOT_IMPLEMENTED First Key in Display - * @param string $strFirstOptionValue- 12: Frist VALUE in Display, use value NULL for required. Para o valor DEFAULT informe o ID do $mixOptions e $strFirstOptionText = '' e não pode ser null - * @param string $strKeyColumn - 13: NOT_IMPLEMENTED Nome da coluna que será utilizada para preencher os valores das opções - * @param string $strDisplayColumn - 14: NOT_IMPLEMENTED Nome da coluna que será utilizada para preencher as opções que serão exibidas para o usuário + * @param string $strFirstOptionValue- 12: Frist Value in Display, use value NULL for required. Para o valor DEFAULT informe o ID do $mixOptions e $strFirstOptionText = '' e não pode ser null + * @param string $strKeyColumn - 13: Nome da coluna que será utilizada para preencher os valores das opções + * @param string $strDisplayColumn - 14: Nome da coluna que será utilizada para preencher as opções que serão exibidas para o usuário * @param string $boolNoWrapLabel - 15: NOT_IMPLEMENTED * @param string $strDataColumns - 16: NOT_IMPLEMENTED Informações extras do banco de dados que deverão ser adicionadas na tag option do campo select * @return TCombo @@ -1473,16 +1536,64 @@ public function addNumberField( $strName //---------------------------------------------------------------- //---------------------------------------------------------------- //---------------------------------------------------------------- + /** + * @deprecated mantido apenas para diminir o impacto na migração do FormDin 4 para FormDin 5 sobre Adianti 7.1 + * @return void + */ + public function setColumns(){ + $arrBacktrace = debug_backtrace(); + ValidateHelper::validadeMethod(ValidateHelper::WARNING + ,ValidateHelper::MSG_DECREP + ,__METHOD__ + ,null + ,$arrBacktrace[0]['file'] + ,$arrBacktrace[0]['line'] + ); + } + + /** + * @deprecated mantido apenas para diminir o impacto na migração do FormDin 4 para FormDin 5 sobre Adianti 7.1 + * @return void + */ + public function getColumns(){ + $arrBacktrace = debug_backtrace(); + ValidateHelper::validadeMethod(ValidateHelper::WARNING + ,ValidateHelper::MSG_DECREP + ,__METHOD__ + ,null + ,$arrBacktrace[0]['file'] + ,$arrBacktrace[0]['line'] + ); + } + + /** + * @deprecated mantido apenas para diminir o impacto na migração do FormDin 4 para FormDin 5 sobre Adianti 7.1 + * @return void + */ + public function getcolumnWidth(){ + $arrBacktrace = debug_backtrace(); + ValidateHelper::validadeMethod(ValidateHelper::WARNING + ,ValidateHelper::MSG_DECREP + ,__METHOD__ + ,null + ,$arrBacktrace[0]['file'] + ,$arrBacktrace[0]['line'] + ); + } /** * @deprecated mantido apenas para diminir o impacto na migração do FormDin 4 para FormDin 5 sobre Adianti 7.1 * @return void */ public function setShowCloseButton( $boolNewValue=null ){ - ValidateHelper::validadeParam('$boolNewValue',$boolNewValue - ,ValidateHelper::WARNING - ,ValidateHelper::MSG_DECREP - ,__CLASS__,__METHOD__,__LINE__); + $arrBacktrace = debug_backtrace(); + ValidateHelper::validadeMethod(ValidateHelper::WARNING + ,ValidateHelper::MSG_DECREP + ,__METHOD__ + ,null + ,$arrBacktrace[0]['file'] + ,$arrBacktrace[0]['line'] + ); } /** @@ -1490,10 +1601,14 @@ public function setShowCloseButton( $boolNewValue=null ){ * @return void */ public function setFlat($boolNewValue=null){ - ValidateHelper::validadeParam('$boolNewValue',$boolNewValue - ,ValidateHelper::WARNING - ,ValidateHelper::MSG_DECREP - ,__CLASS__,__METHOD__,__LINE__); + $arrBacktrace = debug_backtrace(); + ValidateHelper::validadeMethod(ValidateHelper::WARNING + ,ValidateHelper::MSG_DECREP + ,__METHOD__ + ,null + ,$arrBacktrace[0]['file'] + ,$arrBacktrace[0]['line'] + ); } /** @@ -1501,10 +1616,14 @@ public function setFlat($boolNewValue=null){ * @return void */ public function setMaximize($boolNewValue = null){ - ValidateHelper::validadeParam('$boolNewValue',$boolNewValue - ,ValidateHelper::WARNING - ,ValidateHelper::MSG_DECREP - ,__CLASS__,__METHOD__,__LINE__); + $arrBacktrace = debug_backtrace(); + ValidateHelper::validadeMethod(ValidateHelper::WARNING + ,ValidateHelper::MSG_DECREP + ,__METHOD__ + ,null + ,$arrBacktrace[0]['file'] + ,$arrBacktrace[0]['line'] + ); } /** @@ -1512,9 +1631,13 @@ public function setMaximize($boolNewValue = null){ * @return void */ public function setHelpOnLine(){ - ValidateHelper::validadeParam('$setHelpOnLine',null - ,ValidateHelper::WARNING - ,ValidateHelper::MSG_DECREP - ,__CLASS__,__METHOD__,__LINE__); + $arrBacktrace = debug_backtrace(); + ValidateHelper::validadeMethod(ValidateHelper::WARNING + ,ValidateHelper::MSG_DECREP + ,__METHOD__ + ,null + ,$arrBacktrace[0]['file'] + ,$arrBacktrace[0]['line'] + ); } } \ No newline at end of file diff --git a/FormDin5/lib/widget/FormDin5/webform/TFormDinGrid.class.php b/FormDin5/lib/widget/FormDin5/webform/TFormDinGrid.class.php index a7872089..9ef123dc 100644 --- a/FormDin5/lib/widget/FormDin5/webform/TFormDinGrid.class.php +++ b/FormDin5/lib/widget/FormDin5/webform/TFormDinGrid.class.php @@ -572,7 +572,28 @@ public function addButton( $strRotulo $this->addListGridAction($itemGridAction); return $itemGridAction; } - + //------------------------------------------------------------------------------------ + /** + * Seta o nome de uma função que será usada para desenhar os botões de uma linha da gride. + * Um exemplo tipico é desabilitar determinado botão se o Registro estiver no estado X + * + * Parametros do evento onDrawActionButton + * 1) $rowNum - número da linha corrente + * 2) $button - objeto TButton + * 3) $objColumn - objeto TGrideColum + * 4) $aData - o array de dados da linha ex: $res[''][n] + * Ex: function tratarBotoes($rowNum,$button,$objColumn,$aData); + * + * @param string $newValue + */ + public function setOnDrawActionButton( $newValue = null ) + { + $this->onDrawActionButton = $newValue; + } + public function getOnDrawActionButton() + { + return $this->onDrawActionButton; + } //------------------------------------------------------------------------------------ /** * Campos do form origem que serão atualizados ao selecionar o item desejado. @@ -587,8 +608,7 @@ public function setUpdateFields( $mixUpdateFields = null ) { $mixUpdateFields = ArrayHelper::convertArrayMixUpdate2OutputFormat($mixUpdateFields); $this->updateFields = $mixUpdateFields; - } - //------------------------------------------------------------------------------------ + } /** * Retorna a lista de campos que serão atualizados * diff --git a/FormDin5/lib/widget/FormDin5/webform/TFormDinMessage.class.php b/FormDin5/lib/widget/FormDin5/webform/TFormDinMessage.class.php index 7d05c825..d0bc286e 100644 --- a/FormDin5/lib/widget/FormDin5/webform/TFormDinMessage.class.php +++ b/FormDin5/lib/widget/FormDin5/webform/TFormDinMessage.class.php @@ -76,6 +76,7 @@ class TFormDinMessage { const ERROR_HTML_COLOR_HEXA = 'Informe uma cor HTML no formato hexadecimal. Exemplo #efefef !'; const ERROR_EMPTY_INPUT = 'O Parametro não pode ficar em branco'; + const ERROR_TYPE_NOT_STRING= 'Tipo não é string! '; const ERROR_TYPE_NOT_INT = 'Tipo não númerico! '; const ERROR_TYPE_NOT_ARRAY = 'Tipo não é um array! '; const ERROR_TYPE_ARRAY_EMP = 'O array está vazio! '; @@ -85,7 +86,7 @@ class TFormDinMessage { const ERROR_SQL_PARAM = 'Quantidade de parametros diferente da quantidade utilizada na instrução sql!'; const ERROR_FD5 = 'ERRO FormDin5: '; - const ERROR_FD5_PARAM_MIGRA = Self::ERROR_FD5.' Falha na migração do FormDin 4 para 5.'; + const ERROR_FD5_PARAM_MIGRA = 'Falha na migração do FormDin 4 para 5.'; const ERROR_FD5_OBJ_ADI = Self::ERROR_FD5.' objeto Adianti Fieald não pode ficar em branco.'; const ERROR_FD5_OBJ_BUILDER = Self::ERROR_FD5.' objeto não é um Adianti BootstrapFormBuilder.'; const ERROR_FD5_OBJ_BOOTGRID = Self::ERROR_FD5.' objeto não é um Adianti BootstrapDatagridWrapper.'; @@ -121,7 +122,7 @@ class TFormDinMessage { * ------------------------------------------------------------------------ * * @param string $message - 1: Texto da mensagem pode ser HTML - * @param string $type - 2: 2: FORMDIN5 Type mensagem: DEFAULT=info, error, warning. Use TFormDinMessage::TYPE_ + * @param string $type - 2: FORMDIN5 Type mensagem: DEFAULT=info, error, warning. Use TFormDinMessage::TYPE_ * @param TAction $action - 3: FORMDIN5 Classe TAction do Adianti * @param string $title_msg - 4: FORMDIN5 titulo da mensagem */ @@ -158,14 +159,14 @@ public static function messageTransform($mixMessage){ public static function logRecord(Exception $exception) { - $app = $_SESSION[APLICATIVO]; + $app = $_SESSION[APPLICATION_NAME]; $login = null; $grupo = null; - if( ArrayHelper::has('USER',$_SESSION[APLICATIVO]) ) { - $login = ( ArrayHelper::has('LOGIN', $_SESSION[APLICATIVO]['USER']) ? $_SESSION[APLICATIVO]['USER']['LOGIN']:null ); - $grupo = ( ArrayHelper::has('GRUPO_NOME', $_SESSION[APLICATIVO]['USER']) ? $_SESSION[APLICATIVO]['USER']['GRUPO_NOME']:null ); + if( ArrayHelper::has('USER',$_SESSION[APPLICATION_NAME]) ) { + $login = ( ArrayHelper::has('LOGIN', $_SESSION[APPLICATION_NAME]['USER']) ? $_SESSION[APPLICATION_NAME]['USER']['LOGIN']:null ); + $grupo = ( ArrayHelper::has('GRUPO_NOME', $_SESSION[APPLICATION_NAME]['USER']) ? $_SESSION[APPLICATION_NAME]['USER']['GRUPO_NOME']:null ); } - $log = 'formDin: '.FORMDIN_VERSION.' ,sistem: '.SYSTEM_ACRONYM.' v:'.SYSTEM_VERSION.' ,usuario: '.$login + $log = 'formDin: '.FormDinHelper::version().' ,sistem: '.APPLICATION_NAME.' v:'.SYSTEM_VERSION.' ,usuario: '.$login .PHP_EOL.'type: '.get_class($exception).' ,Code: '.$exception->getCode().' ,file: '.$exception->getFile().' ,line: '.$exception->getLine() .PHP_EOL.'mensagem: '.$exception->getMessage() .PHP_EOL."Stack trace:" @@ -176,7 +177,7 @@ public static function logRecord(Exception $exception) public static function logRecordSimple($message) { - $log = 'formDin: '.FORMDIN_VERSION.' ,sistem: '.SYSTEM_ACRONYM.' v:'.SYSTEM_VERSION + $log = 'formDin: '.FormDinHelper::version().' ,sistem: '.APPLICATION_NAME.' v:'.SYSTEM_VERSION .PHP_EOL.TAB.'mensagem: '.$message; error_log($log); } diff --git a/FormDin5/tests/lib/widget/FormDin5/helpers/ArrayHelperTest.php b/FormDin5/tests/lib/widget/FormDin5/helpers/ArrayHelperTest.php index 5d975f72..4caf2c46 100644 --- a/FormDin5/tests/lib/widget/FormDin5/helpers/ArrayHelperTest.php +++ b/FormDin5/tests/lib/widget/FormDin5/helpers/ArrayHelperTest.php @@ -157,7 +157,7 @@ public function testGetDefaultValue_NotInArray() { $this->assertEquals($esperado, $retorno); } - public function testGetDefaultValue_NotArray() { + public function testGetDefaultVALUE_NotArray() { $esperado = 'x'; $array = 123; $atributeName = 'k'; @@ -934,6 +934,44 @@ public function testConvertArray2OutputFormat_FormDin2FormDin(){ $esperado = $arrayData; $retorno = ArrayHelper::convertArray2OutputFormat($arrayData,ArrayHelper::TYPE_FORMDIN); $this->assertEquals($esperado, $retorno); - } + } + //----------------------------------------------------------------------------------- + //----------------------------------------------------------------------------------- + //----------------------------------------------------------------------------------- + public function testConvertArray2PhpKeyValue_FailKeyColumn(){ + $this->expectException(InvalidArgumentException::class); + $mock = new mockFormDinArray(); + $arrayData = $mock->generateTablePessoaPDO(); + ArrayHelper::convertArray2PhpKeyValue($arrayData,'ID','NOME'); + } + public function testConvertArray2PhpKeyValue_FailValueColumn(){ + $this->expectException(InvalidArgumentException::class); + $mock = new mockFormDinArray(); + $arrayData = $mock->generateTablePessoaPDO(); + ArrayHelper::convertArray2PhpKeyValue($arrayData,'IDPESSOA','NOME'); + } + public function testConvertArray2PhpKeyValue_OkPDO(){ + $esperado[1]='Joao Silva'; + $esperado[2]='Maria Laranja'; + $esperado[3]='Dell'; + $esperado[4]='Microsoft'; + + $mock = new mockFormDinArray(); + $arrayData = $mock->generateTablePessoaPDO(); + $retorno = ArrayHelper::convertArray2PhpKeyValue($arrayData,'IDPESSOA','NMPESSOA'); + + $this->assertEquals($esperado, $retorno); + } + public function testConvertArray2PhpKeyValue_OkAdianti(){ + $esperado[1]='F'; + $esperado[2]='F'; + $esperado[3]='J'; + $esperado[4]='J'; + $mock = new mockFormDinArray(); + $arrayData = $mock->generateTablePessoaAdianti(); + $retorno = ArrayHelper::convertArray2PhpKeyValue($arrayData,'IDPESSOA','TPPESSOA'); + + $this->assertEquals($esperado, $retorno); + } } \ No newline at end of file diff --git a/FormDin5/tests/lib/widget/FormDin5/helpers/FormDinHelperTest.php b/FormDin5/tests/lib/widget/FormDin5/helpers/FormDinHelperTest.php index ab4bc61a..f02605b7 100644 --- a/FormDin5/tests/lib/widget/FormDin5/helpers/FormDinHelperTest.php +++ b/FormDin5/tests/lib/widget/FormDin5/helpers/FormDinHelperTest.php @@ -52,7 +52,7 @@ class FormDinHelperTest extends TestCase { public function testVersion() { - $expected = '5.0.0-alpha20'; + $expected = '5.0.0-alpha22'; $result = FormDinHelper::version(); $this->assertEquals( $expected , $result); } diff --git a/FormDin5/tests/lib/widget/FormDin5/helpers/ValidateHelperTest.php b/FormDin5/tests/lib/widget/FormDin5/helpers/ValidateHelperTest.php index c52c36b2..44483820 100644 --- a/FormDin5/tests/lib/widget/FormDin5/helpers/ValidateHelperTest.php +++ b/FormDin5/tests/lib/widget/FormDin5/helpers/ValidateHelperTest.php @@ -57,6 +57,41 @@ public function testObjTypeTFormDinPdoConnection_FailMethod() { ValidateHelper::objTypeTFormDinPdoConnection($tpdo,$method,$line); } + public function testisString_FailInputInt() { + $this->expectException(InvalidArgumentException::class); + ValidateHelper::isString(1,__METHOD__,__LINE__); + } + public function testisString_FailInputArray() { + $this->expectException(InvalidArgumentException::class); + ValidateHelper::isString(array(),__METHOD__,__LINE__); + } + public function testisString_FailInputObj() { + $this->expectException(InvalidArgumentException::class); + ValidateHelper::isString(new StdClass,__METHOD__,__LINE__); + } + public function testisString_OK() { + $this->expectNotToPerformAssertions(); + ValidateHelper::isString('test',__METHOD__,__LINE__); + } + + public function testIsNumeric_FailInputStringText() { + $this->expectException(InvalidArgumentException::class); + ValidateHelper::isNumeric('1a',__METHOD__,__LINE__); + } + public function testIsNumeric_OKStringNumber() { + $this->expectNotToPerformAssertions(); + ValidateHelper::isNumeric('1',__METHOD__,__LINE__); + } + public function testIsNumeric_FailInputArray() { + $this->expectException(InvalidArgumentException::class); + ValidateHelper::isNumeric(array(),__METHOD__,__LINE__); + } + public function testIsNumeric_FailInputObj() { + $this->expectException(InvalidArgumentException::class); + ValidateHelper::isNumeric(new StdClass,__METHOD__,__LINE__); + } + + public function testObjTypeTFormDinPdoConnection_FailLine() { $this->expectException(InvalidArgumentException::class); $tpdo = null; diff --git a/FormDin5/tests/lib/widget/FormDin5/webform/FormDinFields/TFormDinFileFieldTest.php b/FormDin5/tests/lib/widget/FormDin5/webform/FormDinFields/TFormDinFileFieldTest.php new file mode 100644 index 00000000..ff64c839 --- /dev/null +++ b/FormDin5/tests/lib/widget/FormDin5/webform/FormDinFields/TFormDinFileFieldTest.php @@ -0,0 +1,83 @@ + + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Formdin. + * + * O Framework Formdin é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuí1do na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licen?a Pública Geral GNU/LGPL em portugu?s + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ + +$path = __DIR__.'/../../../../../'; +//require_once $path.'tests/initTest.php'; + +use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Error\Warning; + +class TFormDinFileFieldTest extends TestCase +{ + + private $classTest; + + /** + * Prepares the environment before running a test. + */ + protected function setUp(): void { + parent::setUp(); + if(!defined('APPLICATION_NAME') ) { + define('APPLICATION_NAME', 'phpunit'); + } + $this->classTest = new TFormDinFileField('testFile1','Test Upload Arquivo',true,'GIF,png,XLS,csv'); + } + + /** + * Cleans up the environment after running a test. + */ + protected function tearDown(): void { + $this->classTest = null; + parent::tearDown(); + } + + public function testGetAllowedFileTypes() + { + $expect[] = 'gif'; + $expect[] = 'png'; + $expect[] = 'xls'; + $expect[] = 'csv'; + $result = $this->classTest->getAllowedFileTypes(); + $this->assertEquals($expect, $result); + } + +} \ No newline at end of file diff --git a/FormDin5/tests/lib/widget/FormDin5/webform/FormDinFields/TFormDinMemoFieldTest.php b/FormDin5/tests/lib/widget/FormDin5/webform/FormDinFields/TFormDinMemoFieldTest.php index 16c51108..fcba86b2 100644 --- a/FormDin5/tests/lib/widget/FormDin5/webform/FormDinFields/TFormDinMemoFieldTest.php +++ b/FormDin5/tests/lib/widget/FormDin5/webform/FormDinFields/TFormDinMemoFieldTest.php @@ -73,19 +73,35 @@ public function test_instanceOff() $this->assertInstanceOf(TText::class, $adiantiObj); } - /* public function testTestSize_fail() { - $this->expectException(InvalidArgumentException::class); - - $reflectionMethod = new \ReflectionMethod(TFormDinMemoField::class, 'testSize'); - $reflectionMethod->setAccessible(true); - - $formDinObj = new TFormDinMemoField('p1','html simples',300); + $this->expectNotToPerformAssertions(); + $this->classTest->testSize(null); + } + + public function testTestSize_ok_String100Perent() + { + $result = $this->classTest->testSize('100%'); + $this->assertEquals($result,'100%'); + } - $reflectionMethod->invoke( $formDinObj->testSize(10) ); + public function testTestSize_ok_String100() + { + $result = $this->classTest->testSize('100'); + $this->assertEquals($result,'100'); + } + + public function testTestSize_ok_int100() + { + $result = $this->classTest->testSize(100); + $this->assertEquals($result,100); + } + + public function testTestSize_ok_null() + { + $result = $this->classTest->testSize(null); + $this->assertEquals($result,null); } - */ public function test_readOnly() { diff --git a/FormDin5/tests/lib/widget/FormDin5/webform/TFormDinTest.php b/FormDin5/tests/lib/widget/FormDin5/webform/TFormDinTest.php index e452a196..3ad2b663 100644 --- a/FormDin5/tests/lib/widget/FormDin5/webform/TFormDinTest.php +++ b/FormDin5/tests/lib/widget/FormDin5/webform/TFormDinTest.php @@ -783,5 +783,62 @@ public function testSetAction_methods(){ //$this->assertEquals('Salvar', $listAction[0]->Label); //$this->assertEquals('Limpar', $listAction[0]->Label); } + //------------------------------------------------------------------------- + public function testSetColumns() + { + $this->expectWarning(); + $this->expectErrorMessageMatches('/Falha na migração do FormDin 4 para 5./'); + $classForm = new stdClass(); + $formDin = new TFormDin($classForm,'Phpunit'); + $formDin->setColumns(); + } + public function testGetColumns() + { + $this->expectWarning(); + $this->expectErrorMessageMatches('/Falha na migração do FormDin 4 para 5./'); + $classForm = new stdClass(); + $formDin = new TFormDin($classForm,'Phpunit'); + $formDin->getColumns(true); + } + public function testGetcolumnWidth() + { + $this->expectWarning(); + $this->expectErrorMessageMatches('/Falha na migração do FormDin 4 para 5./'); + $classForm = new stdClass(); + $formDin = new TFormDin($classForm,'Phpunit'); + $formDin->getcolumnWidth(true); + } + public function testSetShowCloseButton() + { + $this->expectWarning(); + $this->expectErrorMessageMatches('/Falha na migração do FormDin 4 para 5./'); + $classForm = new stdClass(); + $formDin = new TFormDin($classForm,'Phpunit'); + $formDin->setShowCloseButton(true); + } + public function testSetFlat() + { + $this->expectWarning(); + $this->expectErrorMessageMatches('/Falha na migração do FormDin 4 para 5./'); + $classForm = new stdClass(); + $formDin = new TFormDin($classForm,'Phpunit'); + $formDin->setFlat(true); + } + public function testSetMaximize() + { + $this->expectWarning(); + $this->expectErrorMessageMatches('/Falha na migração do FormDin 4 para 5./'); + $classForm = new stdClass(); + $formDin = new TFormDin($classForm,'Phpunit'); + $formDin->setMaximize(true); + } + public function testSetHelpOnLine() + { + $this->expectWarning(); + $this->expectErrorMessageMatches('/Falha na migração do FormDin 4 para 5./'); + $classForm = new stdClass(); + $formDin = new TFormDin($classForm,'Phpunit'); + $formDin->setHelpOnLine(); + } } \ No newline at end of file