function testCanUserCreate()
 {
     $this->resetTransactions();
     $app = MapasCulturais\App::i();
     /*
      * Guest users CANNOT create entities.
      */
     $this->user = null;
     foreach ($this->entities as $class => $plural) {
         if ($class === 'Agent') {
             continue;
         }
         $this->assertPermissionDenied(function () use($class) {
             $entity = $this->getNewEntity($class);
             $entity->save(true);
         }, "Asserting that the guest user CANNOT create {$plural}.");
     }
     /*
      * Super Admins CAN create entities
      */
     $this->user = '******';
     foreach ($this->entities as $class => $plural) {
         $this->assertPermissionGranted(function () use($class) {
             $entity = $this->getNewEntity($class);
             $entity->save(true);
         }, "Asserting that a super admin user CAN create {$plural}.");
     }
     /*
      * Normal users CANNOT create entities to another users
      */
     $this->user = '******';
     $another_user = $this->getRandomEntity('User', 'e.id != ' . $app->user->id);
     foreach ($this->entities as $class => $plural) {
         $this->assertPermissionDenied(function () use($class, $another_user) {
             $entity = $this->getNewEntity($class);
             if ($class === 'Agent') {
                 $entity->user = $another_user;
             } else {
                 $entity->ownerId = $another_user->profile->id;
             }
             $entity->save(true);
         }, "Asserting that a normal user CANNOT create {$plural} to another user.");
     }
     /*
      * Super Admins CAN create entities to another users
      */
     $this->user = '******';
     foreach ($this->entities as $class => $plural) {
         $this->assertPermissionGranted(function () use($class, $another_user) {
             $entity = $this->getNewEntity($class);
             if ($class === 'Agent') {
                 $entity->user = $another_user;
             } else {
                 $entity->ownerId = $another_user->profile->id;
             }
             $entity->save(true);
         }, "Asserting that a super admin user CAN create {$plural} to another user.");
     }
 }
Example #2
0
function fetchTerms($taxonomy, $entity_class, $entity_id)
{
    $conn = MapasCulturais\App::i()->em->getConnection();
    $terms = $conn->fetchAll("" . "SELECT t.term " . "FROM term t, term_relation tr " . "WHERE t.id = tr.term_id AND t.taxonomy = {$taxonomy} AND tr.object_type = 'MapasCulturais\\Entities\\{$entity_class}' AND tr.object_id = {$entity_id}");
    return implode(', ', array_map(function ($e) {
        return $e['term'];
    }, $terms));
}
<?php

$app = MapasCulturais\App::i();
//plugin Em Cartaz
// TODO: Mover arquivo de template de views/panel/em-cartaz.php para a pasta de plugins
$defaultFrom = new DateTime("first day of next month");
$defaultTo = new DateTime("last day of next month");
$app->hook('GET(panel.em-cartaz)', function () use($app, $defaultFrom, $defaultTo) {
    $this->requireAuthentication();
    if (!$app->user->is('admin') && !$app->user->is('staff')) {
        //throw new MapasCulturais\Exceptions\PermissionDenied;
        $app->pass();
    }
    $this->render('em-cartaz', array('content' => '', 'from' => isset($this->getData['from']) ? new DateTime($this->getData['from']) : $defaultFrom, 'to' => isset($this->getData['to']) ? new DateTime($this->getData['to']) : $defaultTo));
});
$app->hook('panel.menu:after', function () use($app) {
    if (!$app->user->is('admin') && !$app->user->is('staff')) {
        return;
    }
    $a_class = $this->template == 'panel/em-cartaz' ? 'active' : '';
    $url = $app->createUrl('panel', 'em-cartaz');
    echo "<li><a class='{$a_class}' href='{$url}'><span class='icon icon-em-cartaz'></span> Em Cartaz</a></li>";
});
$app->hook('GET(panel.em-cartaz-<<download|preview>>)', function () use($app, $defaultFrom, $defaultTo) {
    if (!$app->user->is('admin') && !$app->user->is('staff')) {
        //throw new MapasCulturais\Exceptions\PermissionDenied;
        $app->pass();
    }
    $from = isset($this->getData['from']) ? new DateTime($this->getData['from']) : $defaultFrom;
    $to = isset($this->getData['to']) ? new DateTime($this->getData['to']) : $defaultTo;
    $phpWord = new \PhpOffice\PhpWord\PhpWord();
Example #4
0
<?php

require_once __DIR__ . '/protected/application/bootstrap.php';
MapasCulturais\App::i()->run();
 protected function tearDown()
 {
     $app = MapasCulturais\App::i();
     $app->em->rollback();
     parent::tearDown();
 }
<?php

define('DB_UPDATES_FILE', realpath(__DIR__ . '/../') . '/db-updates.php');
$time_start = microtime(true);
$save_log = isset($argv[1]) && $argv[1];
if ($save_log) {
    ob_start();
}
require __DIR__ . '/../application/bootstrap.php';
if ($save_log) {
    $log = ob_get_clean();
}
$time_end = microtime(true);
$execution_time = number_format($time_end - $time_start, 4);
$exec_time = "\n=================================================\ndb updates executed in {$execution_time} seconds.\n=================================================\n";
if ($save_log && $log) {
    $log_path = MapasCulturais\App::i()->config['app.log.path'];
    $log_filename = 'db-updates-' . date('Y.m.d-H.i.s') . '.log';
    file_put_contents($log_path . $log_filename, $exec_time . $log);
} else {
    echo $exec_time;
}
<?php

require __DIR__ . '/../application/bootstrap.php';
echo MapasCulturais\App::i()->view->themeFolder . '/assets/';