Esempio n. 1
0
 /**
  * @test
  */
 public function it_should_run_and_have_output()
 {
     $this->sut = new Application(BASE_PATH, Environment::testing());
     $this->sut['session'] = new Session(new MockFileSessionStorage());
     // We start an output buffer because the Application sends its response to
     // the output buffer as a Symfony Response.
     ob_start();
     $this->sut->run();
     $output = ob_get_clean();
     $this->assertNotEmpty($output);
 }
Esempio n. 2
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);
 }
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
 /**
  * @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;
     $app['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('stdClass');
     $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);
 }