Esempio n. 1
0
 /**
  * Test that the index page grabs a collection of talks
  * and successfully displays them
  *
  * @test
  */
 public function indexPageDisplaysTalksCorrectly()
 {
     $app = new Application(BASE_PATH, Environment::testing());
     ob_start();
     $app->run();
     ob_end_clean();
     // Create a pretend user
     $user = m::mock('StdClass');
     $user->shouldReceive('hasPermission')->with('admin')->andReturn(true);
     $user->shouldReceive('getId')->andReturn(1);
     // Create a test double for Sentry
     $sentry = m::mock('StdClass');
     $sentry->shouldReceive('check')->andReturn(true);
     $sentry->shouldReceive('getUser')->andReturn($user);
     $app['sentry'] = $sentry;
     // Create an in-memory database
     $cfg = new \Spot\Config();
     $cfg->addConnection('sqlite', ['dbname' => 'sqlite::memory', 'driver' => 'pdo_sqlite']);
     $app['spot'] = new \Spot\Locator($cfg);
     // Create a fake request
     $req = m::mock('Symfony\\Component\\HttpFoundation\\Request');
     $req->shouldReceive('get')->with('page')->andReturn(1);
     $req->shouldReceive('get')->with('sort')->andReturn('title');
     $req->shouldReceive('getRequestUri')->andReturn('foo');
     $this->createTestData($app['spot']);
     $controller = new \OpenCFP\Http\Controller\Admin\TalksController();
     $controller->setApplication($app);
     $response = $controller->indexAction($req, $app);
     $this->assertContains('Test Title', (string) $response);
     $this->assertContains('Test User', (string) $response);
 }
 /**
  * Test that index action displays a form that allows the user to reset
  * their password
  *
  * @test
  */
 public function indexDisplaysCorrectForm()
 {
     $app = new Application(BASE_PATH, Environment::testing());
     $app['session'] = new Session(new MockFileSessionStorage());
     $app['form.csrf_provider'] = new SessionCsrfProvider($app['session'], 'secret');
     ob_start();
     $app->run();
     ob_end_clean();
     $controller = new OpenCFP\Http\Controller\ForgotController();
     $controller->setApplication($app);
     $response = $controller->indexAction();
     // Get the form object and verify things look correct
     $this->assertContains('<form id="forgot"', (string) $response);
     $this->assertContains('<input type="hidden" id="forgot__token"', (string) $response);
     $this->assertContains('<input id="form-forgot-email"', (string) $response);
 }
 /**
  * Test that the index page returns a list of talks associated
  * with a specific user and information about that user as well
  *
  * @test
  */
 public function indexDisplaysUserAndTalks()
 {
     $app = new Application(BASE_PATH, Environment::testing());
     $app['session'] = new Session(new MockFileSessionStorage());
     // Set things up so Sentry believes we're logged in
     $user = m::mock('StdClass');
     $user->shouldReceive('id')->andReturn(1);
     $user->shouldReceive('getId')->andReturn(1);
     $user->shouldReceive('hasAccess')->with('admin')->andReturn(true);
     // Create a test double for Sentry
     $sentry = m::mock('StdClass');
     $sentry->shouldReceive('check')->times(3)->andReturn(true);
     $sentry->shouldReceive('getUser')->andReturn($user);
     $app['sentry'] = $sentry;
     // Create a test double for a talk in profile
     $talk = m::mock('StdClass');
     $talk->shouldReceive('title')->andReturn('Test Title');
     $talk->shouldReceive('id')->andReturn(1);
     $talk->shouldReceive('type', 'category', 'created_at');
     // Create a test double for profile
     $profile = m::mock('StdClass');
     $profile->shouldReceive('name')->andReturn('Test User');
     $profile->shouldReceive('photo', 'company', 'twitter', 'airport', 'bio', 'info', 'transportation', 'hotel');
     $profile->shouldReceive('talks')->andReturn([$talk]);
     $speakerService = m::mock('StdClass');
     $speakerService->shouldReceive('findProfile')->andReturn($profile);
     $app['application.speakers'] = $speakerService;
     ob_start();
     $app->run();
     // Fire before handlers... boot...
     ob_end_clean();
     // Instantiate the controller and run the indexAction
     $controller = new \OpenCFP\Http\Controller\DashboardController();
     $controller->setApplication($app);
     $response = $controller->showSpeakerProfile();
     $this->assertContains('Test Title', (string) $response);
     $this->assertContains('Test User', (string) $response);
 }
 /**
  * @test
  */
 public function it_hides_transportation_and_hotel_when_doing_an_online_conference()
 {
     $faker = $this->getFaker();
     $app = new Application(BASE_PATH, Environment::testing());
     $app['session'] = new Session(new MockFileSessionStorage());
     // Specify configuration to enable `online_conference` settings.
     // TODO Bake something like this as a trait. Dealing with mocking
     // TODO services like configuration and template rending is painful.
     $config = $app['config']['application'];
     $config['online_conference'] = true;
     /* @var Twig_Environment $twig */
     $twig = $app['twig'];
     $twig->addGlobal('site', $config);
     // There's some global before filters that call Sentry directly.
     // We have to stub that behaviour here to have it think we are not admin.
     // TODO This stuff is everywhere. Bake it into a trait for testing in the short-term.
     $user = m::mock('stdClass');
     $user->shouldReceive('hasPermission')->with('admin')->andReturn(true);
     $user->shouldReceive('getId')->andReturn(1);
     $user->shouldReceive('id')->andReturn(1);
     $user->shouldReceive('hasAccess')->with('admin')->andReturn(false);
     $sentry = m::mock(Sentry::class);
     $sentry->shouldReceive('check')->andReturn(true);
     $sentry->shouldReceive('getUser')->andReturn($user);
     $app['sentry'] = $sentry;
     $app['user'] = $user;
     // Create a test double for SpeakerProfile
     // We  have benefit of being able to stub an application
     // service for this.
     $profile = $this->stubProfileWith(['getTalks' => [], 'getName' => $faker->name, 'getEmail' => $faker->companyEmail, 'getCompany' => $faker->company, 'getTwitter' => $faker->userName, 'getInfo' => $faker->text, 'getBio' => $faker->text, 'getTransportation' => true, 'getHotel' => true, 'getAirport' => 'RDU', 'getPhoto' => '']);
     $speakersDouble = m::mock(\OpenCFP\Application\Speakers::class)->shouldReceive('findProfile')->andReturn($profile)->getMock();
     $app['application.speakers'] = $speakersDouble;
     ob_start();
     $app->run();
     // Fire before handlers... boot...
     ob_end_clean();
     // Instantiate the controller and run the indexAction
     $controller = new \OpenCFP\Http\Controller\DashboardController();
     $controller->setApplication($app);
     $response = (string) $controller->showSpeakerProfile();
     $this->assertNotContains('Need Transportation', $response);
     $this->assertNotContains('Need Hotel', $response);
 }
Esempio n. 5
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use OpenCFP\Application;
use OpenCFP\Environment;
$basePath = realpath(dirname(__DIR__));
$environment = Environment::fromEnvironmentVariable();
$app = new Application($basePath, $environment);
$app->run();
Esempio n. 6
0
 /**
  * @param string $route  Route name to redirect to
  * @param int    $status
  *
  * @return RedirectResponse
  */
 public function redirectTo($route, $status = 302)
 {
     return $this->app->redirect($this->url($route), $status);
 }
Esempio n. 7
0
 /** @test */
 public function it_should_resolve_configuration_path_based_on_environment()
 {
     $this->sut = new Application(BASE_PATH, Environment::testing());
     $this->assertTrue($this->sut->isTesting());
     $this->assertContains('testing.yml', $this->sut->configPath());
 }
Esempio n. 8
0
 private function registerGlobalErrorHandler(Application $app)
 {
     $app->error(function (\Exception $e, $code) use($app) {
         /** @var Request $request */
         $request = $app['request'];
         if (in_array('application/json', $request->getAcceptableContentTypes())) {
             $headers = [];
             if ($e instanceof HttpExceptionInterface) {
                 $code = $e->getStatusCode();
                 $headers = $e->getHeaders();
             }
             if ($e instanceof OAuthException) {
                 $code = $e->httpStatusCode;
                 $headers = $e->getHttpHeaders();
             }
             return new JsonResponse(['error' => $e->getMessage()], $code, $headers);
         }
         /* @var Twig_Environment $twig */
         $twig = $app['twig'];
         switch ($code) {
             case Response::HTTP_UNAUTHORIZED:
                 $message = $twig->render('error/401.twig');
                 break;
             case Response::HTTP_FORBIDDEN:
                 $message = $twig->render('error/403.twig');
                 break;
             case Response::HTTP_NOT_FOUND:
                 $message = $twig->render('error/404.twig');
                 break;
             default:
                 $message = $twig->render('error/500.twig');
         }
         return new Response($message, $code);
     });
 }