/**
  * Test middleware overrides response content type to html
  */
 public function testResponseContentTypeIsOverriddenToHtml()
 {
     Slim_Environment::mock(array('SCRIPT_NAME' => '/index.php', 'PATH_INFO' => '/foo'));
     $app = new Slim(array('log.enabled' => false));
     $app->get('/foo', function () use($app) {
         $app->contentType('application/json;charset=utf-8');
         //<-- set content type to something else
         throw new Exception('Test Message', 100);
     });
     $mw = new Slim_Middleware_PrettyExceptions();
     $mw->setApplication($app);
     $mw->setNextMiddleware($app);
     $mw->call();
     $response = $app->response();
     $this->assertEquals('text/html', $response['Content-Type']);
 }
예제 #2
0
파일: SlimTest.php 프로젝트: ntdt/Slim
 /**
  * Test Slim::contentType
  *
  * Pre-conditions:
  * You have initialized a Slim app and set the Content-Type
  * HTTP response header.
  *
  * Post-conditions:
  * The Response content type header is set correctly.
  */
 public function testSlimContentType(){
     Slim::init();
     Slim::contentType('image/jpeg');
     $this->assertEquals(Slim::response()->header('Content-Type'), 'image/jpeg');
 }
예제 #3
0
<?php

require "Slim/Slim.php";
$app = new Slim();
$app->contentType('application/json');
//$app->post('/{lado1}/{lado2}/{lado3}', function($lado1, $lado2, $lado3) use($app) {
$app->post('/calcular', function () use($app) {
    //$request = $app->request();
    //$body = $request->getBody();
    //$input = json_decode($body);
    //$lado1 = $input->lado1;
    //$lado2 = $input->lado2;
    //$lado3 = $input->lado3;
    //print_r();
    $lado1 = $app->request()->params("lado1");
    $lado2 = $app->request()->params("lado2");
    $lado3 = $app->request()->params("lado3");
    if ($lado1 <= 0 || $lado2 <= 0 || $lado3 <= 0) {
        echo json_encode(array('status' => false, 'lado1' => $lado1, 'lado2' => $lado2, 'lado3' => $lado3, 'resultado' => "Lado menor ou igual a zero"));
    } else {
        if ($lado1 == $lado2 && $lado2 == $lado3) {
            echo json_encode(array('status' => true, 'lado1' => $lado1, 'lado2' => $lado2, 'lado3' => $lado3, 'resultado' => "O triângulo é Equilátero"));
        } else {
            if ($lado1 == $lado2 || $lado2 == $lado3 || $lado3 == $lado1) {
                echo json_encode(array('status' => true, 'lado1' => $lado1, 'lado2' => $lado2, 'lado3' => $lado3, 'resultado' => "O triângulo é Isósceles"));
            } else {
                echo json_encode(array('status' => true, 'lado1' => $lado1, 'lado2' => $lado2, 'lado3' => $lado3, 'resultado' => "O triângulo é Escaleno"));
            }
        }
    }
});
예제 #4
0
파일: SlimTest.php 프로젝트: rs3d/Slimplr
 /**
  * Test content type
  */
 public function testContentType()
 {
     $s = new Slim();
     $s->get('/bar', function () use($s) {
         $s->contentType('application/json');
     });
     $s->call();
     list($status, $header, $body) = $s->response()->finalize();
     $this->assertEquals('application/json', $header['Content-Type']);
 }
 /**
  * Constructor
  *
  * @param   Slim $app
  * @return  void
  */
 public function __construct(\Slim\Slim $app)
 {
     $this->app = $app;
     $this->app->contentType('application/json');
     $this->response = $this->app->response();
 }
예제 #6
0
// https://github.com/briannesbitt/Slim-ContextSensitiveLoginLogout/blob/master/index.php
require "libs/autoloader.php";
//Autoload para as classes próprias
require "libs/Simplepie/autoloader.php";
//Autoload para as Classes do SimplePie, para leitura de RSS
require "libs/Slim/Slim.php";
//Micro-framework Slim, para gerenciamento de rotas e alguns Helpers
include "app/funcoes.php";
//Funções próprias, como CSS, Javascript e Meta
include "app/config.php";
//Configurações gerais do sistema, através de Constantes.
date_default_timezone_set('America/Sao_Paulo');
$autoloader = new Autoloader();
$app = new Slim();
$app->contentType('text/html; charset=utf-8');
$app->add(new Slim_Middleware_SessionCookie(array('secret' => '98897qwer65465qwe9r79qw9e354as68dh56k6lks6df8g', 'expires' => '60 minutes')));
$authenticate = function ($app) {
    return function () use($app) {
        if (!isset($_SESSION['dehbora']['user'])) {
            $_SESSION['dehbora']['urlRedirect'] = $app->request()->getPathInfo();
            $app->flash('error', 'Você precisa se logar.');
            $app->redirect(URL_BASE . '/inicial');
        }
    };
};
$app->hook('slim.before.dispatch', function () use($app) {
    $user = null;
    if (isset($_SESSION['dehbora']['user'])) {
        $user = $_SESSION['dehbora']['user'];
    }
예제 #7
0
 /**
  * Test Slim::contentType
  *
  * Pre-conditions:
  * Slim app instantiated;
  * Content-Type header is set using helper method;
  *
  * Post-conditions:
  * The Response content type header is set correctly;
  */
 public function testSlimContentType()
 {
     $app = new Slim();
     $app->contentType('image/jpeg');
     $this->assertEquals('image/jpeg', $app->response()->header('Content-Type'));
 }
예제 #8
0
 /**
  * Test content type
  */
 public function testContentType()
 {
     $s = new Slim();
     $s->get('/bar', function () use($s) {
         $s->contentType('application/json');
     });
     $env = $s->environment();
     list($status, $header, $body) = $s->call($env);
     $this->assertEquals('application/json', $header['Content-Type']);
 }