示例#1
0
 protected function setup()
 {
     $this->app = new Application(BASE_PATH, Environment::testing());
     ob_start();
     $this->app->run();
     ob_end_clean();
     // Override things so that Spot2 is using in-memory tables
     $cfg = new \Spot\Config();
     $cfg->addConnection('sqlite', ['dbname' => 'sqlite::memory', 'driver' => 'pdo_sqlite']);
     $this->app['spot'] = new \Spot\Locator($cfg);
     // Initialize the talk table in the sqlite database
     $talk_mapper = $this->app['spot']->mapper('OpenCFP\\Domain\\Entity\\Talk');
     $talk_mapper->migrate();
     // Set things up so Sentry believes we're logged in
     $user = m::mock('StdClass');
     $user->shouldReceive('getId')->andReturn(uniqid());
     $user->shouldReceive('getLogin')->andReturn(uniqid() . '@grumpy-learning.com');
     // Create a test double for Sentry
     $sentry = m::mock('StdClass');
     $sentry->shouldReceive('check')->andReturn(true);
     $sentry->shouldReceive('getUser')->andReturn($user);
     $this->app['sentry'] = $sentry;
     // Create a test double for sessions so we can control what happens
     $this->app['session'] = new SessionDouble();
     // Create our test double for the request object
     $this->req = m::mock('Symfony\\Component\\HttpFoundation\\Request');
 }
示例#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);
 }
示例#3
0
 protected function setup()
 {
     $this->app = new Application(BASE_PATH, Environment::testing());
     $cfp = new \Spot\Config();
     $cfg = new \Spot\Config();
     $cfg->addConnection('sqlite', ['dbname' => 'sqlite::memory', 'driver' => 'pdo_sqlite']);
     $this->app['spot'] = new \Spot\Locator($cfg);
 }
示例#4
0
 protected function setup()
 {
     $this->app = new Application(BASE_PATH, Environment::testing());
     // Create an in-memory database
     $cfg = new \Spot\Config();
     $cfg->addConnection('sqlite', ['dbname' => 'sqlite::memory', 'driver' => 'pdo_sqlite']);
     $this->app['spot'] = new \Spot\Locator($cfg);
     $this->mapper = $this->app['spot']->mapper('OpenCFP\\Domain\\Entity\\Talk');
     $this->mapper->migrate();
 }
示例#5
0
文件: TalkTest.php 项目: GeeH/opencfp
 protected function setUp()
 {
     $this->app = new Application(BASE_PATH, Environment::testing());
     $cfg = new \Spot\Config();
     $cfg->addConnection('sqlite', ['dbname' => 'sqlite::memory', 'driver' => 'pdo_sqlite']);
     $this->app['spot'] = new \Spot\Locator($cfg);
     $this->mapper = $this->app['spot']->mapper(\OpenCFP\Domain\Entity\Talk::class);
     foreach ($this->entities as $entity) {
         $this->app['spot']->mapper('OpenCFP\\Domain\\Entity\\' . $entity)->migrate();
     }
 }
 /**
  * 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');
     $controller = new OpenCFP\Http\Controller\ForgotController($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);
 }
示例#7
0
 protected function setUp()
 {
     $this->app = new Application(BASE_PATH, Environment::testing());
     // Create an in-memory database
     $cfg = new \Spot\Config();
     $cfg->addConnection('sqlite', ['dbname' => 'sqlite::memory', 'driver' => 'pdo_sqlite']);
     $this->app['spot'] = new \Spot\Locator($cfg);
     $this->mapper = $this->app['spot']->mapper(\OpenCFP\Domain\Entity\Favorite::class);
     $this->mapper->migrate();
     // Create a talk
     $talk_mapper = $this->app['spot']->mapper(\OpenCFP\Domain\Entity\Talk::class);
     $data = ['title' => 'Favorite Entity Test', 'description' => 'This is a stubbed talk for a Favorite Entity Test', 'user_id' => 1];
     $talk_mapper->migrate();
     $this->talk = $talk_mapper->create($data);
 }
示例#8
0
 public function setup()
 {
     // Create our Application object
     $this->app = new Application(BASE_PATH, Environment::testing());
     // Create a test double for our User entity
     $user = m::mock('OpenCFP\\Domain\\Entity\\User');
     $user->shouldReceive('hasPermission')->with('admin')->andReturn(true);
     $user->shouldReceive('getId')->andReturn(1);
     $user->shouldReceive('hasAccess')->with('admin')->andReturn(true);
     // Create a test double for our Sentry object
     $sentry = m::mock('Cartalyst\\Sentry\\Sentry');
     $sentry->shouldReceive('check')->andReturn(true);
     $sentry->shouldReceive('getUser')->andReturn($user);
     $this->app['sentry'] = $sentry;
     $this->app['user'] = $user;
 }
 /**
  * @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);
 }
 /**
  * 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);
 }
示例#11
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();
示例#12
0
 /** @test */
 public function it_fails_when_given_an_invalid_environment_string()
 {
     $this->setExpectedException('InvalidArgumentException');
     Environment::fromString('foo');
 }
示例#13
0
 /**
  * Tells if application is in testing environment.
  * @return boolean
  */
 public function isTesting()
 {
     return $this['env']->equals(Environment::testing());
 }
示例#14
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());
 }
示例#15
0
 public function testAdminDemoteSuccess()
 {
     // Create our input and output dependencies
     $input = $this->createInputInterfaceWithEmail('*****@*****.**');
     $output = $this->createOutputInterface();
     /**
      * Create a mock User that has admin access and a removeGroup
      * method that is stubbed out
      */
     $user = Mockery::mock('\\stdClass');
     $user->shouldReceive('hasAccess')->with('admin')->andReturn(true);
     $user->shouldReceive('removeGroup');
     /**
      * Create a Sentry object that also returns an ID that represents
      * an admin group provider. Number doesn't matter for this particular
      * test
      */
     $sentry = Mockery::mock('\\Cartalyst\\Sentry\\Sentry');
     $sentry->shouldReceive('getUserProvider->findByLogin')->andReturn($user);
     $sentry->shouldReceive('getGroupProvider->findByName')->with('Admin')->andReturn(1);
     // Create our command object and inject our application
     $app = new \OpenCFP\Application(BASE_PATH, Environment::testing());
     $app['sentry'] = $sentry;
     $command = new \OpenCFP\Console\Command\AdminDemoteCommand();
     $command->setApp($app);
     $response = $command->execute($input, $output);
     $this->assertEquals($response, 0);
 }