Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: austcms/aust
...
head fork: austcms/aust
compare: bugfix_select_1n_flexfields
Checking mergeability… Don’t worry, you can still create the pull request.
  • 11 commits
  • 34 files changed
  • 0 commit comments
  • 2 contributors
Showing with 1,127 additions and 39 deletions.
  1. +1 −1  core/class/Aust.php
  2. +139 −0 core/class/Hook.php
  3. +76 −0 core/class/HookBase.php
  4. +119 −10 core/class/Image.php
  5. +19 −0 core/config/installation/dbschema.php
  6. +4 −0 core/config/variables.php
  7. +72 −0 core/hooks/email_sender/EmailSenderHook.php
  8. +7 −0 core/hooks/email_sender/configuration.php
  9. +30 −0 core/hooks/sql_executer/SqlExecuterHook.php
  10. +7 −0 core/hooks/sql_executer/configuration.php
  11. +1 −1  core/inc/conf_modulos.inc.php
  12. +9 −0 core/inc/hooks.inc.php
  13. +55 −0 core/inc/hooks.inc/_form.inc.php
  14. +13 −0 core/inc/hooks.inc/edit.inc.php
  15. +78 −0 core/inc/hooks.inc/index.inc.php
  16. +12 −0 core/inc/hooks.inc/new.inc.php
  17. +20 −0 core/inc/hooks.inc/save.inc.php
  18. +8 −8 core/libs/ajax.php
  19. +52 −0 core/user_interface/css/configurations_variables.css
  20. +4 −1 core/user_interface/ui.php
  21. +24 −0 modulos/cadastro/Cadastro.php
  22. +2 −1  modulos/cadastro/controller/mod_controller.php
  23. +9 −0 modulos/cadastro/core/config/config.php
  24. +8 −6 modulos/cadastro/js/ajax.php
  25. +3 −2 modulos/cadastro/models/CadastroSetup.php
  26. +8 −0 modulos/cadastro/view/mod/actions.php
  27. +1 −2  modulos/cadastro/view/mod/form.php
  28. +0 −1  modulos/cadastro/view/mod/listing_table.php
  29. +1 −1  tests/config/database.php
  30. +27 −0 tests/core/class/HookTest.php
  31. +68 −5 tests/core/class/ImageTest.php
  32. +128 −0 tests/hooks/EmailSenderTest.php
  33. +122 −0 tests/hooks/SqlExecuterTest.php
  34. BIN  tests/test_files/image_sample.jpg
View
2  core/class/Aust.php
@@ -640,7 +640,7 @@ public function pegaInformacoesDeEstrutura( $austNode ) {
/**
* Busca na tabela do Aust onde o id é igual à estrutura requisitada.
*/
- $result = $this->conexao->query("SELECT * FROM ".Registry::read("austTable")." WHERE id='".$austNode."'" );
+ $result = $this->conexao->query("SELECT * FROM categorias WHERE id='".$austNode."'" );
return $result;
}
View
139 core/class/Hook.php
@@ -0,0 +1,139 @@
+<?php
+/**
+ * Manage Hooks
+ *
+ * This class manages installation of hooks, not performing the Hooks.
+ * See HookBase for the hooks' superclass.
+ */
+class Hook
+{
+
+ function __construct()
+ {
+
+ }
+
+ /*
+ * PERFORM
+ */
+ /**
+ * perform()
+ *
+ */
+ function perform($params = array()){
+ if( empty($params['when']) ) return false;
+ if( $params['when'] == 'approve_record' &&
+ !is_array($params['self']) ){
+ return false;
+ }
+
+ $austNode = $_GET['aust_node'];
+
+ $sql = "SELECT * FROM hooks WHERE node_id='".$austNode."' AND when_action='".$params['when']."'";
+ $hooks = Connection::getInstance()->query($sql);
+
+ if( is_array($params['self']) ){
+ foreach( $params['self'] as $self ){
+ $this->performInEachSelf($self, $hooks);
+ }
+ }
+ }
+
+ function performInEachSelf($self, $hooks){
+ foreach( $hooks as $hook ){
+ $hookObject = $this->instantiateHookEngine($hook['hook_engine']);
+ $hookObject->perform($self, $hook);
+ }
+ }
+
+ /*
+ * Each HookEngine has a class. This method return its
+ * instantiation.
+ */
+ function instantiateHookEngine($engineName = ''){
+ if( empty($engineName) )
+ return false;
+
+ include(HOOKS_DIR.$engineName."/configuration.php");
+ $className = $configuration["className"];
+ include_once(HOOKS_DIR.$engineName."/".$className.".php");
+ $object = new $className();
+ return $object;
+ }
+ /*
+ * Reading and Saving
+ */
+ /*
+ * Returns a list of engines available for usage.
+ */
+ function loadHookEngines(){
+ $result = array();
+ foreach( glob(HOOKS_DIR."*") as $folder ){
+ if( !file_exists($folder."/configuration.php") )
+ continue;
+
+ include($folder."/configuration.php");
+ $result[basename($folder)] = array(
+ "configuration" => $configuration
+ );
+ }
+
+ return $result;
+ }
+
+ /*
+ * Saves a hook, be it new or update.
+ */
+ function save($post){
+ $new = false;
+ if( empty($post['id']) )
+ $new = true;
+
+ $post['hook_engine'] = addslashes($post['hook_engine']);
+ $post['when_action'] = addslashes($post['when_action']);
+ $post['description'] = addslashes($post['description']);
+ $post['perform'] = addslashes($post['perform']);
+
+ if( $new ){
+ $sql = "INSERT INTO hooks
+ (hook_engine, when_action, node_id, description, perform)
+ VALUES
+ ('".$post['hook_engine']."', '".$post['when_action']."', '".$post['node_id']."', '".$post['description']."', '".$post['perform']."')";
+ } else {
+ $sql = "UPDATE hooks
+ SET
+ when_action = '".$post['when_action']."',
+ node_id = '".$post['node_id']."',
+ description = '".$post['description']."',
+ perform = '".$post['perform']."'
+ WHERE
+ id = '".$_POST['id']."'";
+ }
+
+ $connection = Connection::getInstance();
+ if( $connection->exec($sql) )
+ return true;
+ else
+ return false;
+ }
+
+ /*
+ * Returns all the Hooks created.
+ */
+ function allHooks(){
+ $sql = 'SELECT * FROM hooks ORDER BY hook_engine';
+ return Connection::getInstance()->query($sql);
+ }
+
+ function getStructureName($nodeId){
+ $st = Aust::getInstance()->pegaInformacoesDeEstrutura($nodeId);
+ $st = reset($st);
+ return $st["nome"];
+ }
+
+ function find($id){
+ $sql = "SELECT * FROM hooks WHERE id='{$id}'";
+ return Connection::getInstance()->query($sql);
+ }
+}
+?>
View
76 core/class/HookBase.php
@@ -0,0 +1,76 @@
+<?php
+/**
+ * Hooks' superclass
+ *
+ * This class has methods shared between all Hooks.
+ */
+class HookBase
+{
+
+ function cleanUpText($perform){
+ $perform = preg_replace('/\{.*?\}/', '', $perform);
+ return $perform;
+ }
+
+ /**
+ * Parses everything sql()
+ */
+ function getSqlFunction($perform){
+
+ /*
+ * matches everything {self.field_name}
+ */
+ preg_match_all('/sql\((.*?)\)/', $perform, $data);
+
+ foreach( $data[1] as $sql ){
+ $query = Connection::getInstance()->query($sql);
+ $queryResults = array();
+ foreach( $query as $field ){
+ $queryResults[] = reset($field);
+ }
+
+ $resultString = implode(';', $queryResults);
+
+ $perform = str_replace('sql('.$sql.')', $resultString, $perform);
+ }
+
+ $result = $perform;
+ return $result;
+ }
+
+ /**
+ * Parses everything {self.field_name}
+ */
+ function getSelfData($self, $austNode, $perform){
+
+ $selfObject = Aust::getInstance()->getStructureInstance($austNode);
+ $selfQuery = $selfObject->load(
+ array(
+ 'metodo' => 'edit',
+ 'categorias' => $austNode,
+ 'austNode' => $austNode,
+ 'id' => $self
+ )
+ );
+ if( empty($selfQuery) )
+ return false;
+
+ $selfQuery = reset($selfQuery);
+
+ /*
+ * matches everything {self.field_name}
+ */
+ preg_match_all('/\{self.(.*?)}/', $perform, $selfData);
+
+ foreach( $selfData[1] as $field ){
+ if( !array_key_exists($field, $selfQuery) )
+ continue;
+
+ $perform = str_replace('{self.'.$field.'}', $selfQuery[$field], $perform);
+ }
+
+ $result = $perform;
+ return $result;
+ }
+}
+?>
View
129 core/class/Image.php
@@ -111,7 +111,7 @@ function path(){
* @param array $file O mesmo formato vindo do formulário
* @return mixed Retorna o endereço do arquivo salvo
*/
- public function upload($file = ""){
+ public function upload($file = "", $customFilename = ""){
if( empty($file) )
return false;
@@ -125,13 +125,16 @@ public function upload($file = ""){
/*
* Gera um nome único para a imagem SHA1
*/
- if( $this->filenameType == "sha1" )
+ if( !empty($customFilename) )
+ $fileName = $customFilename;
+ else if( $this->filenameType == "sha1" )
$fileName = sha1(uniqid(time())) . "." . $this->getExtension($file["name"]);
else if( $this->filenameType == "md5" )
$fileName = md5(uniqid(time())) . "." . $this->getExtension($file["name"]);
else
$fileName = $file["name"];
-
+
+ $fileName = str_replace(" ", "", $fileName);
/*
* Caminho de onde a imagem ficará
*/
@@ -155,11 +158,13 @@ public function upload($file = ""){
$this->lastSize = $file["size"];
$this->lastType = $file["type"];
$this->lastFilename = $file["name"];
-
/*
* UPLOAD DA IMAGEM
*/
- if( move_uploaded_file($file["tmp_name"], $filePath) ){
+ $uploadedFile = copy($file["tmp_name"], $filePath);
+ unlink($file["tmp_name"]);
+
+ if( $uploadedFile ){
$this->lastSystemPath = $systemFilePath;
$this->lastWebPath = $webFilePath;
@@ -184,8 +189,10 @@ public function upload($file = ""){
* @param string $height Valor padrão de altura
* @return array
*/
- function resample($files, $width = "1280", $height = "1024"){
-
+ function resample($files, $dimensions = "1280x1024"){
+ $dimensions = $this->getResampleDimensions($files, $dimensions);
+ $largurad = $dimensions['width'];
+ $alturad = $dimensions['height'];
/*
* Toma dados de $files
*/
@@ -219,13 +226,13 @@ function resample($files, $width = "1280", $height = "1024"){
/*
* Configura o tamanho da nova imagem
- */
+ *
if($largurao > $width)
$largurad = $width;
else
$largurad = $largurao; // definir a altura da miniatura em px
-
- $alturad = ($alturao*$largurad)/$largurao; // calcula a largura da imagem a partir da altura da miniatura
+*/
+// $alturad = ($alturao*$largurad)/$largurao; // calcula a largura da imagem a partir da altura da miniatura
$nova = imagecreatetruecolor($largurad,$alturad); // criar uma imagem em branco
// PNG ou GIF, ajusta transparência
@@ -271,6 +278,108 @@ function resample($files, $width = "1280", $height = "1024"){
}
+ public function getDimensions($filePath){
+
+ if( is_string($filePath) )
+ $extension = $this->getExtension($filePath);
+ else if( is_array($filePath) ){
+ $extension = $this->getExtension($filePath['name']);
+ $filePath = $filePath["tmp_name"];
+ }
+
+ if( $extension == "jpeg" || $extension == "jpg" )
+ $image = imagecreatefromjpeg($filePath);
+ else if( $extension == "png" || $extension == "png" )
+ $image = imagecreatefrompng($filePath);
+ else
+ return false;
+
+ $result["width"] = imagesx($image);
+ $result["height"] = imagesy($image);
+ return $result;
+ }
+
+ public function getResampleDimensions($filePath, $wantedDimensions = false){
+
+ $dimensions = $this->getDimensions($filePath);
+ $originalWidth = $dimensions['width'];
+ $originalHeight = $dimensions['height'];
+
+ if( !$wantedDimensions ){
+ return array(
+ 'width' => $originalWidth,
+ 'height' => $originalHeight
+ );
+ }
+
+ $dimensions = trim($wantedDimensions);
+ $noWidth = ( substr($dimensions, 0, 1) == "x" );
+ $widthHeight = explode("x", $dimensions);
+
+ if( $noWidth ){
+ $wantedWidth = false;
+ $wantedHeight = $widthHeight[1];
+ } else {
+ $wantedWidth = $widthHeight[0];
+ $wantedHeight = false;
+ if( !empty($widthHeight[1]) ){
+ $wantedHeight = $widthHeight[1];
+ }
+ }
+
+ if( is_numeric($wantedWidth) &&
+ $wantedWidth > $originalWidth
+ ){
+ $wantedWidth = $originalWidth;
+ }
+ if( is_numeric($wantedHeight) &&
+ $wantedHeight > $originalHeight
+ ){
+ $wantedHeight = $originalHeight;
+ }
+
+ if( empty($height) || empty($width) ){
+ if( !empty($wantedWidth) && empty($wantedHeight) ){
+ $ratio = $originalWidth / $wantedWidth;
+ $height = $originalHeight / $ratio;
+ $width = $wantedWidth;
+ }
+ else if( empty($wantedWidth) && !empty($wantedHeight) ){
+ $ratio = $originalHeight / $wantedHeight;
+ $width = $originalWidth / $ratio;
+ $height = $wantedHeight;
+ }
+ else if( !empty($wantedWidth) && !empty($wantedHeight) ){
+ $ratio = $originalWidth / $wantedWidth;
+ $height = $originalHeight / $ratio;
+
+ if( $height > $originalHeight ){
+ $wantedHeight = $originalHeight;
+ $height = $originalHeight;
+ $ratio = $originalHeight / $wantedHeight;
+ $width = $originalWidth / $ratio;
+ }
+
+ if( empty($width) )
+ $width = $wantedWidth;
+ if( empty($height) )
+ $height = $wantedHeight;
+ }
+ else {
+ return array(
+ "width" => false,
+ "height" => false
+ );
+ }
+ }
+
+ return array(
+ 'width' => $width,
+ 'height' => $height
+ );
+
+ }
+
/*
*
* VALIDAÇÃO
View
19 core/config/installation/dbschema.php
@@ -96,6 +96,25 @@
);
+$dbSchema['hooks'] = array(
+ 'id' => 'int NOT NULL auto_increment',
+ 'hook_engine' => 'varchar(240)',
+ 'when_action' => 'varchar(240)',
+ 'node_id' => 'int',
+ 'configuration' => 'text', // key-value configuration in json format
+ 'description' => 'text',
+ 'perform' => 'text',
+ 'public' => 'bool default "0"',
+ 'admin_id' => 'varchar(120)',
+ 'order_nr' => 'int',
+ 'dbSchemaTableProperties' => array(
+ 'PRIMARY KEY' => '(id)',
+ 'UNIQUE' => 'id (id)',
+ 'INDEX' => '(when_action)',
+ 'INDEX' => '(node_id)',
+ )
+);
+
$dbSchema['categorias'] = array(
'id' => 'int NOT NULL auto_increment',
'nome' => 'varchar(240)',
View
4 core/config/variables.php
@@ -79,6 +79,10 @@
*/
define("BASECODE_JS", LIB_DIR."js/");
/**
+ * Diretório dos Hooks
+ */
+ define('HOOKS_DIR', CORE_DIR.'hooks/');
+ /**
* Diretório dos módu1os
*/
define('MODULES_DIR', THIS_TO_BASEURL.'modulos/');
View
72 core/hooks/email_sender/EmailSenderHook.php
@@ -0,0 +1,72 @@
+<?php
+class EmailSenderHook extends HookBase
+{
+ function perform($self, $options){
+
+ $austNode = $options['node_id'];
+ if( $options['when_action'] == "approve_record" ){
+ $selfObject = Aust::getInstance()->getStructureInstance($austNode);
+ $sql = "SELECT approved FROM ".$selfObject->LeTabelaDaEstrutura($austNode)." WHERE id='".$self."'";
+ $query = Connection::getInstance()->query($sql);
+
+ if( empty($query) )
+ return false;
+ if( $query[0]['approved'] == "1" )
+ return true;
+ }
+
+ $options['perform'] = $this->getSelfData($self, $options['node_id'], $options['perform']);
+ $options['perform'] = $this->getSqlFunction($options['perform']);
+
+
+ $to = $this->to($options['perform']);
+ $subject = $this->subject($options['perform']);
+ $from = $this->from($options['perform']);
+
+ $options['perform'] = $this->cleanUpText($options['perform']);
+ $options['perform'] = nl2br($options['perform']);
+ if( empty($to) ) return false;
+ if( empty($from) ) $from = "";
+ if( empty($subject) ) $subject = "";
+
+ $to = explode(";", $to);
+
+ foreach( $to as $email ){
+ if( !mail($email, $subject, $options['perform'], "MIME-Version: 1.1\nContent-type: text/html; charset=utf-8\nFrom: ".$from."\nReply-To: ".$from."", "-r".$from) ){
+ mail( $email, $subject, $options['perform'], "MIME-Version: 1.1\nContent-type: text/html; charset=utf-8\nFrom: ".$from."\nReply-To: ".$from."\nReturn-Path: ".$from);
+ }
+ }
+
+ return true;
+ }
+
+ function to($options){
+ $options = $this->getSqlFunction($options);
+ preg_match('/\{to:(.*)}/', $options, $matches);
+
+ if( !empty($matches[1]) ){
+ return str_replace(";;", ";", $matches[1]);
+ }
+ return false;
+ }
+
+ function from($options){
+ preg_match('/\{from:(.*)}/', $options, $matches);
+
+ if( !empty($matches[1]) )
+ return str_replace(";;", ";", $matches[1]);
+
+ return false;
+ }
+
+ function subject($options){
+ preg_match('/\{subject:(.*)}/', $options, $matches);
+
+ if( !empty($matches[1]) ){
+ return str_replace(";;", ";", $matches[1]);
+ }
+ return false;
+ }
+
+}
+?>
View
7 core/hooks/email_sender/configuration.php
@@ -0,0 +1,7 @@
+<?php
+$configuration = array(
+ "name" => "Email Sender",
+ "className" => "EmailSenderHook"
+);
+?>
+
View
30 core/hooks/sql_executer/SqlExecuterHook.php
@@ -0,0 +1,30 @@
+<?php
+class SqlExecuterHook extends HookBase
+{
+
+ function perform($self, $options){
+
+ $austNode = $options['node_id'];
+ if( $options['when_action'] == "approve_record" ){
+ $selfObject = Aust::getInstance()->getStructureInstance($austNode);
+ $sql = "SELECT approved FROM ".$selfObject->LeTabelaDaEstrutura($austNode)." WHERE id='".$self."'";
+ $query = Connection::getInstance()->query($sql);
+
+ if( empty($query) )
+ return false;
+ if( $query[0]['approved'] == "1" )
+ return true;
+ }
+
+ $options['perform'] = $this->getSelfData($self, $options['node_id'], $options['perform']);
+
+
+ $options['perform'] = $this->cleanUpText($options['perform']);
+ $options['perform'] = str_replace('INSERTINTO', 'INSERT INTO', $options['perform']);
+
+ Connection::getInstance()->query(stripslashes($options['perform']) );
+ return true;
+ }
+
+}
+?>
View
7 core/hooks/sql_executer/configuration.php
@@ -0,0 +1,7 @@
+<?php
+$configuration = array(
+ "name" => "SQL executer",
+ "className" => "SqlExecuterHook"
+);
+?>
+
View
2  core/inc/conf_modulos.inc.php
@@ -310,7 +310,7 @@
<option value="<?php echo $moduloDB["valor"] ?>">
<?php echo $moduloDB["nome"] ?>
</option>
- <?
+ <?php
}
unset($moduloDB);
View
9 core/inc/hooks.inc.php
@@ -0,0 +1,9 @@
+<div id="structure_configuration">
+ <?php
+ if( empty($_GET['action']) )
+ $_GET['action'] = 'index';
+
+ include(INC_DIR."hooks.inc/".$_GET['action'].".inc.php");
+ ?>
+ <br />
+</div>
View
55 core/inc/hooks.inc/_form.inc.php
@@ -0,0 +1,55 @@
+<form action="adm_main.php?section=hooks&action=save" method="POST" class="simples">
+
+ <?php if( !empty($data["id"]) ){ ?>
+ <input type="hidden" name="id" value="<?php echo $data["id"] ?>" />
+ <?php } ?>
+ <input type="hidden" name="hook_engine" value="<?php echo $_GET["hook_engine"] ?>" />
+
+ <?php if( !empty($data) ){ ?>
+ <div class="field" style="margin-bottom: 10px">
+ <label for="when_action">Engine</label>
+ <?php echo $data['hook_engine']; ?>
+ </div>
+ <?php } ?>
+
+ <div class="field">
+ <label for="when_action">Quando o usuário: </label>
+ <select name="when_action" id="when_action">
+ <option value="delete_record" <?php if(@$data['when_action']=='delete_record') echo "selected='selected'" ?>>excluir um registro</option>
+ <option value="approve_record" <?php if(@$data['when_action']=='approve_record') echo "selected='selected'" ?>>aprovar um registro</option>
+ <option value="save_record" <?php if(@$data['when_action']=='save_record') echo "selected='selected'" ?>>salvar um registro</option>
+ </select>
+ </div>
+ <div class="field">
+ <label for="node_id">Relacionado a uma estrutura:</label>
+ <?php $structures = Aust::getInstance()->getStructures(); ?>
+ <select name="node_id">
+ <?php foreach( $structures as $site){ ?>
+
+ <optgroup label="<?php echo $site["Site"]["nome"] ?>">
+ <?php foreach( $site["Structures"] as $structure ){ ?>
+ <option value="<?php echo $structure["id"]; ?>" <?php if(@$data['node_id']==$structure["id"]) echo "selected='selected'" ?>>
+ &nbsp;&nbsp;&nbsp;&nbsp;<?php echo $structure["nome"]; ?>
+ </option>
+ <?php } ?>
+ </optgroup>
+
+ <?php } ?>
+ </select>
+ </div>
+ <div class="field">
+ <label for="description">Descrição</label>
+ <textarea name="description" id="description" rows="5"><?php echo @$data['description'] ?></textarea>
+ </div>
+ <div class="field">
+ <label for="perform">Realizar seguinte ação</label>
+ <textarea name="perform" id="perform" rows="17"><?php echo @$data['perform'] ?></textarea>
+ <span class="explanation">
+ Campo <em>Perform</em>.
+ </span>
+ </div>
+ <br>
+ <div class="field">
+ <input type="submit" value="Enviar" name="submit" />
+ </div>
+</form>
View
13 core/inc/hooks.inc/edit.inc.php
@@ -0,0 +1,13 @@
+<div class="title_column">
+ <h2>
+ Editar Hook
+ </h2>
+</div>
+
+<?php
+$hook = new Hook();
+$data = $hook->find($_GET["id"]);
+$data = reset($data);
+
+include(INC_DIR."hooks.inc/_form.inc.php");
+?>
View
78 core/inc/hooks.inc/index.inc.php
@@ -0,0 +1,78 @@
+<div class="title_column">
+ <h2>
+ Hooks
+ </h2>
+</div>
+
+<?php
+$hooksClass = new Hook();
+$hooks = $hooksClass->loadHookEngines();
+if( !empty($hooks) && is_array($hooks) ){
+ ?>
+
+ <div class="configuration_variables config_items">
+
+ <div class="header">Engines disponíveis</div>
+ <?php
+ foreach( $hooks as $hook => $attributes ){
+ ?>
+
+ <div class="item">
+ <label class="configuration_variable_label" for="<?php echo $key ?>_input">
+ <?php echo $attributes["configuration"]["name"] ?>
+ </label>
+ <div class="input">
+ <a href="adm_main.php?section=hooks&action=new&hook_engine=<?php echo $hook ?>">Novo</a>
+ </div>
+ </div>
+
+ <?php
+ }
+ ?>
+
+ </div>
+ <?php
+}
+?>
+
+<?php
+$hooksList = $hooksClass->allHooks();
+if( !empty($hooksList) && is_array($hooksList) ){
+ ?>
+ <br />
+ <div class="configuration_variables config_items">
+
+ <div class="header">Hooks</div>
+ <?php
+ foreach( $hooksList as $attributes ){
+ if( empty($attributes["hook_engine"]) )
+ continue;
+ ?>
+
+ <div class="item">
+ <label class="configuration_variable_label" for="<?php echo $key ?>_input">
+ <?php
+ echo $attributes["description"]."<br>";
+ echo "<strong>".$attributes["hook_engine"]."</strong>";
+ if( !empty($attributes["node_id"]) ){
+ echo ', '.$hooksClass->getStructureName( $attributes["node_id"] );
+ }
+ if( !empty($attributes["when_action"]) ){
+ echo ', when '.$attributes["when_action"];
+ }
+
+ ?>
+ </label>
+ <div class="input">
+ <a href="adm_main.php?section=hooks&action=edit&hook_engine=<?php echo $hook ?>&id=<?php echo $attributes["id"] ?>">Editar</a>
+ </div>
+ </div>
+
+ <?php
+ }
+ ?>
+
+ </div>
+ <?php
+}
+?>
View
12 core/inc/hooks.inc/new.inc.php
@@ -0,0 +1,12 @@
+<div class="title_column">
+ <h2>
+ Hooks
+ </h2>
+</div>
+
+<?php
+$hooksObject = new Hook();
+$hook = $hooksObject->instantiateHookEngine($_GET["hook_engine"]);
+
+include(INC_DIR."hooks.inc/_form.inc.php")
+?>
View
20 core/inc/hooks.inc/save.inc.php
@@ -0,0 +1,20 @@
+<?php
+$object = new Hook();
+$saved = $object->save($_POST);
+
+if( $saved ){
+
+ header("Location: adm_main.php?section=hooks&action=index");
+ exit();
+} else {
+ ?>
+ <p>
+ Ocorreu um erro e o Hook não pôde ser criado.
+ </p>
+ <?php
+ $_GET['hook_engine'] = $_POST['hook_engine'];
+ $data = $_POST;
+ include INC_DIR."hooks.inc/new.inc.php";
+}
+
+?>
View
16 core/libs/ajax.php
@@ -24,7 +24,7 @@
/**
* Carrega as configurações de conexão do banco de dados
*/
-include(THIS_TO_BASEURL.CONFIG_DIR.'database.php');
+include(CONFIG_DIR.'database.php');
/**
@@ -32,14 +32,14 @@
* Carrega classes automaticamente
*
*/
- include_once(THIS_TO_BASEURL.CLASS_DIR.'_carrega_classes.inc.php');
+ include_once(CLASS_DIR.'_carrega_classes.inc.php');
/**
* Configurações do core do sistema
*/
-include(THIS_TO_BASEURL.CONFIG_DIR.'core.php');
-include(THIS_TO_BASEURL.CORE_CONFIG_DIR.'core.php');
+include(CONFIG_DIR.'core.php');
+include(CORE_CONFIG_DIR.'core.php');
header("Content-Type: text/html; charset=".$aust_charset['view']);
@@ -49,12 +49,12 @@
/**
* Métodos usados pelo sistema
*/
-include(THIS_TO_BASEURL.LIB_DIR.'functions/func.php');
-include(THIS_TO_BASEURL.LIB_DIR.'functions/func_content.php');
-include(THIS_TO_BASEURL.LIB_DIR.'functions/func_text_format.php');
+include(LIB_DIR.'functions/func.php');
+include(LIB_DIR.'functions/func_content.php');
+include(LIB_DIR.'functions/func_text_format.php');
// aust_func
-include(THIS_TO_BASEURL.LIBS_DIR.'aust/aust_func.php');
+include(LIBS_DIR.'aust/aust_func.php');
// Conexão
$conexao = Connection::getInstance();
View
52 core/user_interface/css/configurations_variables.css
@@ -0,0 +1,52 @@
+
+.configuration_variables .header {
+ background: #ddd;
+ padding: 10px;
+ font-weight: bold;
+}
+
+ .configuration_variables .item {
+ background: #f4f4f4;
+ border-bottom: 1px solid #eaeaea;
+ border-top: 1px solid #fefefe;
+ padding: 0 10px;
+ margin: 0;
+ display: table;
+ width: 700px;
+ }
+ .configuration_variables .item:hover { background: #f6f6f6; }
+ .configuration_variables .item .configuration_variable_label {
+ float: left; width: 45%; cursor: pointer; padding: 10px 0px;
+ }
+ .configuration_variables .item div.input {
+ float: left; width: 55%; padding: 10px 0px;
+ }
+
+ .configuration_variables .item .input .sub_item {
+ display: table;
+ width: 99%;
+ padding: 5px 0 5px 0;
+ border-bottom: 1px solid #eaeaea;
+ border-top: 1px solid #fefefe;
+ }
+ .input .sub_item:first-child {
+ border-top: 0 !important;
+ }
+ .input .sub_item:last-child {
+ border-bottom: 0 !important;
+ }
+
+ .configuration_variables .item .sub_labels {
+ float: left; width: 50%;
+ text-align: right;
+ margin: 0 5px 5px 0;
+ }
+ .configuration_variables .item .sub_inputs {
+ float: left; width: 40%;
+ }
+ .item .sub_item span.hint {
+ float: right !important;
+ opacity: 0.5;
+ }
+
+ .configuration_variables input[type=submit] { margin: 10px; }
View
5 core/user_interface/ui.php
@@ -154,7 +154,10 @@
<br />
<span class="para_webmaster">Para Webmasters:</span><a href="adm_main.php?section=conf_modulos" class="restrito">Configurar Módulos</a>
<a href="adm_main.php?section=categorias" class="restrito">Categorias</a>
- <a href="adm_main.php?section=import_export_structures" class="restrito">Importar/Exportar Estruturas</a>
+ <a href="adm_main.php?section=hooks" class="restrito">Hooks</a>
+ <!--
+ <a href="adm_main.php?section=import_export_structures" class="restrito">Importar/Exportar Estruturas</a>
+ -->
<?php
if( Registry::read('debugLevel') > 1 ){
View
24 modulos/cadastro/Cadastro.php
@@ -459,6 +459,7 @@ function uploadAndSaveImages($images, $lastInsertId, $options = array()){
foreach( $imagesField as $field=>$images ){
foreach( $images as $key=>$value ){
+ $originalValue = $value;
if( empty($value['name']) OR
empty($value['size']) OR
empty($value['tmp_name'])
@@ -470,6 +471,7 @@ function uploadAndSaveImages($images, $lastInsertId, $options = array()){
* Realiza upload e salva os dados
*/
$imageHandler->prependedPath = $this->getStructureConfig('image_save_path');
+
$value = $imageHandler->resample($value);
$finalName = $imageHandler->upload($value);
@@ -504,6 +506,25 @@ function uploadAndSaveImages($images, $lastInsertId, $options = array()){
";
$this->connection->exec($sql);
+ $shouldCache = $this->getFieldConfig($field, "image_automatic_cache_sizes");
+ if( !empty($shouldCache) ){
+
+ $cacheSizes = explode(';', $shouldCache);
+ $newValue = $value;
+ foreach( $cacheSizes as $sizeString ){
+ $newValue['tmp_name'] = $finalName["systemPath"];
+
+ $newFilename = 'cached_'.$sizeString."_".$finalName['new_filename'];
+ $newFilename = str_replace(" ", "", $newFilename);
+ $processingTemporaryFile = dirname( $newValue["tmp_name"])."/processing_".$newFilename;
+
+ copy( $newValue["tmp_name"], $processingTemporaryFile );
+ $newValue["tmp_name"] = $processingTemporaryFile;
+ $imageHandler->resample($newValue, $sizeString);
+ $imageHandler->upload($newValue, $newFilename);
+ }
+ }
+
}
}
}
@@ -970,6 +991,9 @@ public function loadSql($param = array()){
$searchField = (empty($param['search_field'])) ? '' : $param['search_field'];
$w = (empty($param['id'])) ? '' : $param['id'];
+ if( !empty($categorias) && !is_array($categorias) )
+ $categorias = array($categorias => '');
+
/**
* Se $categorias estiver vazio (nunca deverá acontecer)
*/
View
3  modulos/cadastro/controller/mod_controller.php
@@ -321,7 +321,8 @@ public function save(){
$files = $this->modulo->files;
// insert date
- $table = reset(array_keys($this->data));
+ $table = array_keys($this->data);
+ $table = reset($table);
if( empty($w) )
$this->data[$table]['created_on'] = date("Y-m-d H:i:s");
View
9 modulos/cadastro/core/config/config.php
@@ -171,6 +171,15 @@
"inputType" => "checkbox",
'help' => 'Este campo de imagem tem descrição? ',
),
+ 'image_automatic_cache_sizes' => array(
+ 'field_type' => 'images',
+ "value" => "",
+ "label" => "Cache das imagens",
+ "inputType" => "text",
+ 'help' => 'Defina quais os tamanhos devem ser cacheados automaticamente '.
+ 'inserida. Use ; para definir os tamanhos, e.g. 150x100; 100x75. '.
+ 'Neste exemplo, duas imagens serão cacheadas.'
+ ),
/*
* Tem imagem secundária?
*/
View
14 modulos/cadastro/js/ajax.php
@@ -29,16 +29,16 @@
/**
* Classes do sistema
*/
-include(THIS_TO_BASEURL.CLASS_DIR."_carrega_classes.inc.php");
+include(CLASS_LOADER);
/**
* Propriedades editáveis do sistema. Carrega todas as configurações da aplicação
*/
/**
* Configurações de conexão do banco de dados
*/
-include(THIS_TO_BASEURL.CONFIG_DIR."database.php");
+include(CONFIG_DIR."database.php");
-include(THIS_TO_BASEURL.LIB_DIR."aust/aust_func.php");
+include(LIB_DIR."aust/aust_func.php");
/**
* Conexão principal
*/
@@ -47,15 +47,15 @@
/**
* Configurações do core do sistema
*/
- include(THIS_TO_BASEURL.CONFIG_DIR."core.php");
+ include(CONFIG_DIR."core.php");
/**
* Permissões de tipos de usuários relacionados à navegação
*/
- include(THIS_TO_BASEURL.CONFIG_DIR."nav_permissions.php");
+ include(CONFIG_DIR."nav_permissions.php");
/**
* Carrega o CORE
*/
- include(THIS_TO_BASEURL.CORE_DIR.'load_core.php');
+ include(CORE_DIR.'load_core.php');
include('../index.php');
@@ -140,6 +140,8 @@
$sql = $modulo->loadSql($param);
// echo '<br><br>'.$sql .'<br>';
+ $modulo->austNode = $austNode;
+ $fieldsConfiguration = $modulo->getFields(null, true);
$resultado = $modulo->connection->query($sql, "ASSOC");
View
5 modulos/cadastro/models/CadastroSetup.php
@@ -103,7 +103,7 @@ static function getInstance(){
*
* Métodos que executam todas as funções de instalação
*/
- function createStructure($params){
+ function createStructure($params = array()){
$this->start();
if( !empty($params['austNode']) )
@@ -428,7 +428,8 @@ function getFieldOrder($field = ''){
$sql = "SELECT MAX(ordem) as ordem
FROM cadastros_conf
WHERE categorias_id='".$this->austNode."'";
- $query = reset($this->connection->query($sql));
+ $conn = $this->connection->query($sql);
+ $query = reset($conn);
if( empty($query['ordem']) )
$this->fieldOrder = 1;
View
8 modulos/cadastro/view/mod/actions.php
@@ -76,6 +76,14 @@
* APROVAR usuário
*/
} elseif(!empty($_POST['aprovar']) and !empty($_POST['itens'])){
+
+ $hookParams = array(
+ 'when' => 'approve_record',
+ 'self' => $_POST['itens'],
+ );
+ $hook = new Hook;
+ $hook->perform($hookParams);
+
/*
* Identificar tabela que deve ser excluida
*/
View
3  modulos/cadastro/view/mod/form.php
@@ -240,10 +240,9 @@
* RELACIONAL UM PARA UM
*/
if( $valor["tipo"]["especie"] == "relacional_umparaum" ){
- $sql = "SELECT id, ".$valor["tipo"]["tabelaReferenciaCampo"]." FROM ".$valor["tipo"]["tabelaReferencia"] ." ORDER BY ".$valor["tipo"]["tabelaReferenciaCampo"] ." LIMIT 50";
+ $sql = "SELECT id, ".$valor["tipo"]["tabelaReferenciaCampo"]." FROM ".$valor["tipo"]["tabelaReferencia"] ." WHERE id>=".($valor['valor']-5)." ORDER BY id LIMIT 200";
$selectValues = $conexao->query($sql);
- //$select["selected"] = "3";
$inputType = "select";
foreach($selectValues as $tabelaReferenciaResult){
$select["options"][ $tabelaReferenciaResult["id"] ] = $tabelaReferenciaResult[ $valor["tipo"]["tabelaReferenciaCampo"] ];
View
1  modulos/cadastro/view/mod/listing_table.php
@@ -1,5 +1,4 @@
<?php
-
if( empty($_GET['section']) )
$_GET['section'] = 'conteudo';
View
2  tests/config/database.php
@@ -9,7 +9,7 @@ class DATABASE_CONFIG
{
static $dbConn = array(
'server' => '127.0.0.1',
- 'database' => 'aust',
+ 'database' => 'aust_test_v0_2',
'username' => 'root',
'password' => '',
'encoding' => 'utf8',
View
27 tests/core/class/HookTest.php
@@ -0,0 +1,27 @@
+<?php
+require_once 'tests/config/auto_include.php';
+
+class HookTest extends PHPUnit_Framework_TestCase
+{
+
+ public function setUp(){
+ $this->obj = new Hook;
+ }
+
+ function testLoadHookEngineDirectories(){
+ $this->assertArrayHasKey( 'email_sender', $this->obj->loadHookEngines() );
+ }
+
+ function testGetStructureName(){
+ Connection::getInstance()->exec("INSERT INTO categorias (nome) VALUES ('Test777')");
+ $stId = Connection::getInstance()->lastInsertId();
+ $this->assertEquals( 'Test777', $this->obj->getStructureName($stId) );
+ }
+
+ function testWhenAndSelf(){
+ $this->assertFalse( $this->obj->perform() );
+ $this->assertFalse( $this->obj->perform(array()) );
+ $this->assertFalse( $this->obj->perform(array('when' => 'approve_record', 'self' => 'hey')) );
+ }
+}
+?>
View
73 tests/core/class/ImageTest.php
@@ -1,13 +1,8 @@
<?php
-require_once 'PHPUnit/Framework.php';
-
-#####################################
require_once 'tests/config/auto_include.php';
require_once 'config/nav_permissions.php';
-#####################################
-
class ImageTest extends PHPUnit_Framework_TestCase
{
@@ -53,6 +48,74 @@ function testValidation(){
}
+ function testGetDimensions(){
+ $image = "tests/test_files/image_sample.jpg";
+ $result = $this->obj->getDimensions($image);
+ $this->assertInternalType('array', $result);
+ $this->assertEquals("100", $result["width"]);
+ $this->assertEquals("80", $result["height"]);
+ }
+
+ function testGetResampleDimensions(){
+ $image = "tests/test_files/image_sample.jpg";
+
+ $result = $this->obj->getResampleDimensions($image, "200x160");
+ $this->assertInternalType('array', $result);
+ $this->assertEquals("100", $result["width"]);
+ $this->assertEquals("80", $result["height"]);
+
+ $result = $this->obj->getResampleDimensions($image);
+ $this->assertInternalType('array', $result);
+ $this->assertEquals("100", $result["width"]);
+ $this->assertEquals("80", $result["height"]);
+
+ $result = $this->obj->getResampleDimensions($image, "200x");
+ $this->assertInternalType('array', $result);
+ $this->assertEquals("100", $result["width"]);
+ $this->assertEquals("80", $result["height"]);
+
+ $result = $this->obj->getResampleDimensions($image, "80x40");
+ $this->assertInternalType('array', $result);
+ $this->assertEquals("80", $result["width"]);
+ $this->assertEquals("64", $result["height"]);
+
+ $result = $this->obj->getResampleDimensions($image, "80x");
+ $this->assertInternalType('array', $result);
+ $this->assertEquals("80", $result["width"]);
+ $this->assertEquals("64", $result["height"]);
+
+ $result = $this->obj->getResampleDimensions($image, "80");
+ $this->assertInternalType('array', $result);
+ $this->assertEquals("80", $result["width"]);
+ $this->assertEquals("64", $result["height"]);
+
+ $result = $this->obj->getResampleDimensions($image, "50x");
+ $this->assertInternalType('array', $result);
+ $this->assertEquals("50", $result["width"]);
+ $this->assertEquals("40", $result["height"]);
+
+ $result = $this->obj->getResampleDimensions($image, " 50x ");
+ $this->assertInternalType('array', $result);
+ $this->assertEquals("50", $result["width"]);
+ $this->assertEquals("40", $result["height"]);
+
+ $result = $this->obj->getResampleDimensions($image, "x40");
+ $this->assertInternalType('array', $result);
+ $this->assertEquals("50", $result["width"]);
+ $this->assertEquals("40", $result["height"]);
+
+ $result = $this->obj->getResampleDimensions($image, " x40");
+ $this->assertInternalType('array', $result);
+ $this->assertEquals("50", $result["width"]);
+ $this->assertEquals("40", $result["height"]);
+
+ $result = $this->obj->getResampleDimensions($image, "50");
+ $this->assertInternalType('array', $result);
+ $this->assertEquals("50", $result["width"]);
+ $this->assertEquals("40", $result["height"]);
+
+ }
+
function testIsImage(){
$params = array(
array(
View
128 tests/hooks/EmailSenderTest.php
@@ -0,0 +1,128 @@
+<?php
+require_once 'tests/config/auto_include.php';
+include_once 'modulos/cadastro/Cadastro.php';
+include_once HOOKS_DIR.'email_sender/EmailSenderHook.php';
+
+class EmailSenderTest extends PHPUnit_Framework_TestCase
+{
+
+ public function setUp(){
+ $modelName = 'CadastroSetup';
+ $mod = 'Cadastro';
+ include_once 'modulos/'.$mod.'/'.MOD_MODELS_DIR.$modelName.'.php';
+ $this->structure = new $modelName;
+
+
+ $this->obj = new EmailSenderHook();
+
+ $this->createStructure();
+ }
+
+ function createStructure(){
+ Connection::getInstance()->exec("DELETE FROM admins");
+ Connection::getInstance()->exec("DELETE FROM categorias");
+ Connection::getInstance()->exec("DELETE FROM testunit");
+
+ $sql = "INSERT INTO admins (nome, login, email, senha) VALUES ('Alexandre', 'kurko', 'my_email@gmail.com', '123')";
+ Connection::getInstance()->exec($sql);
+ $this->lastAdmin = Connection::getInstance()->lastInsertId();
+
+ Connection::getInstance()->exec("INSERT INTO categorias (nome,classe) VALUES ('TestePai777','categoria-chefe')");
+ $lastInsert = Connection::getInstance()->lastInsertId();
+
+ $params = array(
+ 'name' => 'TestUnit',
+ 'father' => $lastInsert,
+ 'class' => 'estrutura',
+ 'type' => 'cadastro',
+ 'author' => 1,
+ 'fields' => array(
+ array(
+ 'name' => 'Name',
+ 'type' => 'string',
+ 'description' => 'haha777',
+ ),
+ array(
+ 'name' => 'Email',
+ 'type' => 'string',
+ 'description' => 'haha777',
+ ),
+ ),
+ 'options' => array(
+ 'approval' => 'haha777',
+ 'pre_password' => 'haha777',
+ 'description' => 'haha777',
+ ),
+
+ );
+
+ $result = $this->structure->createStructure($params);
+ $austNode = $this->structure->austNode;
+ $this->austNode = $austNode;
+ $austNodeIsNumeric = is_numeric($austNode);
+ $this->assertTrue($austNodeIsNumeric);
+
+ Connection::getInstance()->exec("DELETE FROM testunit");
+ Connection::getInstance()->exec("INSERT INTO testunit(name,email) VALUES ('Other user','email2@gmail.com')");
+ Connection::getInstance()->exec("INSERT INTO testunit(name,email) VALUES ('Alexandre','email@gmail.com')");
+ $this->selfId = Connection::getInstance()->lastInsertId();
+ }
+
+ function testSetUp(){
+ $this->assertTrue($this->lastAdmin > 0);
+ }
+
+ function testPerform(){
+
+ }
+
+ function testCleanUpText(){
+ $perform = "Configuration: {to:sql(SELECT email FROM testunit)} more {hey} text.";
+ $expected = "Configuration: more text.";
+ $this->assertEquals( $expected, $this->obj->cleanUpText($perform) );
+ }
+
+ function testTo(){
+ $perform = "Configuration: {to:sql(SELECT email FROM testunit)} more text.";
+ $expected = "email2@gmail.com;email@gmail.com";
+ $this->assertEquals( $expected, $this->obj->to($perform) );
+ }
+
+ function testFrom(){
+ $perform = "Configuration: {from:lualualua} more text.";
+ $expected = "lualualua";
+ $this->assertEquals( $expected, $this->obj->from($perform) );
+ }
+
+ function testSubject(){
+ $perform = "Configuration: {subject:hahaha} more text.";
+ $expected = "hahaha";
+ $this->assertEquals( $expected, $this->obj->subject($perform) );
+ }
+
+ function testSqlFunction(){
+ $perform = "Not to the script {to:sql(SELECT email FROM testunit)}";
+ $expected = "Not to the script {to:email2@gmail.com;email@gmail.com}";
+ $this->assertEquals( $expected, $this->obj->getSqlFunction($perform) );
+
+ $perform = "Your new email is: sql(SELECT email FROM testunit LIMIT 1)";
+ $expected = "Your new email is: email2@gmail.com";
+ $this->assertEquals( $expected, $this->obj->getSqlFunction($perform) );
+ }
+
+
+ function testSelfData(){
+ $perform = "{to:sql(SELECT a.email FROM admin a WHERE id={self.id} OR login='{self.email}')}";
+ $expected = "{to:sql(SELECT a.email FROM admin a WHERE id=".$this->selfId." OR login='email@gmail.com')}";
+ $this->assertEquals( $expected, $this->obj->getSelfData($this->selfId, $this->austNode, $perform) );
+
+ $perform = "hey {to:self.email)} haha";
+ $expected = "hey {to:self.email)} haha";
+ $this->assertEquals( $expected, $this->obj->getSelfData($this->selfId, $this->austNode, $perform) );
+
+ $perform = "hey {to:{self.email})} haha";
+ $expected = "hey {to:email@gmail.com)} haha";
+ $this->assertEquals( $expected, $this->obj->getSelfData($this->selfId, $this->austNode, $perform) );
+ }
+}
+?>
View
122 tests/hooks/SqlExecuterTest.php
@@ -0,0 +1,122 @@
+<?php
+require_once 'tests/config/auto_include.php';
+include_once 'modulos/cadastro/Cadastro.php';
+include_once HOOKS_DIR.'sql_executer/SqlExecuterHook.php';
+
+class SqlExecuterTest extends PHPUnit_Framework_TestCase
+{
+
+ public function setUp(){
+ $modelName = 'CadastroSetup';
+ $mod = 'Cadastro';
+ include_once 'modulos/'.$mod.'/'.MOD_MODELS_DIR.$modelName.'.php';
+ $this->structure = new $modelName;
+
+
+ $this->obj = new SqlExecuterHook();
+
+ $this->createStructure();
+ }
+
+ function createStructure(){
+ Connection::getInstance()->exec("DELETE FROM admins");
+ Connection::getInstance()->exec("DELETE FROM categorias");
+ Connection::getInstance()->exec("DELETE FROM testunit");
+
+ $sql = "INSERT INTO admins (nome, login, email, senha) VALUES ('Alexandre', 'kurko', 'my_email@gmail.com', '123')";
+ Connection::getInstance()->exec($sql);
+ $this->lastAdmin = Connection::getInstance()->lastInsertId();
+
+ Connection::getInstance()->exec("INSERT INTO categorias (nome,classe) VALUES ('TestePai777','categoria-chefe')");
+ $lastInsert = Connection::getInstance()->lastInsertId();
+
+ $params = array(
+ 'name' => 'TestUnit',
+ 'father' => $lastInsert,
+ 'class' => 'estrutura',
+ 'type' => 'cadastro',
+ 'author' => 1,
+ 'fields' => array(
+ array(
+ 'name' => 'Name',
+ 'type' => 'string',
+ 'description' => 'haha777',
+ ),
+ array(
+ 'name' => 'Email',
+ 'type' => 'string',
+ 'description' => 'haha777',
+ ),
+ ),
+ 'options' => array(
+ 'approval' => 'haha777',
+ 'pre_password' => 'haha777',
+ 'description' => 'haha777',
+ ),
+
+ );
+
+ $result = $this->structure->createStructure($params);
+ $austNode = $this->structure->austNode;
+ $this->austNode = $austNode;
+ $austNodeIsNumeric = is_numeric($austNode);
+ $this->assertTrue($austNodeIsNumeric);
+
+ Connection::getInstance()->exec("DELETE FROM testunit");
+ Connection::getInstance()->exec("INSERT INTO testunit(name,email) VALUES ('Other user','email2@gmail.com')");
+ Connection::getInstance()->exec("INSERT INTO testunit(name,email) VALUES ('Alexandre','email@gmail.com')");
+ $this->selfId = Connection::getInstance()->lastInsertId();
+ }
+
+ function testSetUp(){
+ $this->assertTrue($this->lastAdmin > 0);
+ }
+
+ function testPerform(){
+ $perform = array(
+ 'hook_engine' => 'sql_executer',
+ 'when_action' => 'approve_record',
+ 'node_id' => $this->austNode,
+ 'perform' => "UPDATE testunit SET name='lxndr' WHERE id='{self.id}'"
+ );
+ $changed = Connection::getInstance()->query("SELECT name FROM testunit WHERE id='".$this->selfId."'");
+ $this->assertEquals( "Alexandre", $changed[0]["name"] );
+
+ $this->obj->perform($this->selfId, $perform);
+
+ $changed = Connection::getInstance()->query("SELECT name FROM testunit WHERE id='".$this->selfId."'");
+ $this->assertEquals( "lxndr", $changed[0]["name"] );
+ }
+
+ function testCleanUpText(){
+ $perform = "Configuration: {to:sql(SELECT email FROM testunit)} more {hey} text.";
+ $expected = "Configuration: more text.";
+ $this->assertEquals( $expected, $this->obj->cleanUpText($perform) );
+ }
+
+ function testSqlFunction(){
+ $perform = "Not to the script {to:sql(SELECT email FROM testunit)}";
+ $expected = "Not to the script {to:email2@gmail.com;email@gmail.com}";
+ $this->assertEquals( $expected, $this->obj->getSqlFunction($perform) );
+
+ $perform = "Your new email is: sql(SELECT email FROM testunit LIMIT 1)";
+ $expected = "Your new email is: email2@gmail.com";
+ $this->assertEquals( $expected, $this->obj->getSqlFunction($perform) );
+ }
+
+
+ function testSelfData(){
+ $perform = "{to:sql(SELECT a.email FROM admin a WHERE id={self.id} OR login='{self.email}')}";
+ $expected = "{to:sql(SELECT a.email FROM admin a WHERE id=".$this->selfId." OR login='email@gmail.com')}";
+ $this->assertEquals( $expected, $this->obj->getSelfData($this->selfId, $this->austNode, $perform) );
+
+ $perform = "hey {to:self.email)} haha";
+ $expected = "hey {to:self.email)} haha";
+ $this->assertEquals( $expected, $this->obj->getSelfData($this->selfId, $this->austNode, $perform) );
+
+ $perform = "hey {to:{self.email})} haha";
+ $expected = "hey {to:email@gmail.com)} haha";
+ $this->assertEquals( $expected, $this->obj->getSelfData($this->selfId, $this->austNode, $perform) );
+ }
+}
+?>
View
BIN  tests/test_files/image_sample.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

No commit comments for this range

Something went wrong with that request. Please try again.