Пример #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);
 }
Пример #2
0
 /**
  * A test to make sure that comments can be correctly tracked
  *
  * @test
  */
 public function talkIsCorrectlyCommentedOn()
 {
     // Create some reusable values
     $talkId = uniqid();
     $comment = 'Test Comment';
     // Create a TalkComment and mapper, then add the mapper to $app
     $talkComment = m::mock('OpenCFP\\Domain\\Entity\\TalkComment');
     $talkComment->shouldReceive('set')->andSet('talk_id', $talkId);
     $talkComment->shouldReceive('set')->andSet('comment', $comment);
     $talkComment->shouldReceive('set')->andSet('user_id', uniqid());
     $talkCommentMapper = m::mock('OpenCFP\\Domain\\Entity\\Mapper\\TalkComment');
     $talkCommentMapper->shouldReceive('get')->andReturn($talkComment);
     $talkCommentMapper->shouldReceive('save');
     // Override our mapper with the double
     $spot = m::mock('Spot\\Locator');
     $spot->shouldReceive('mapper')->with('OpenCFP\\Domain\\Entity\\TalkComment')->andReturn($talkCommentMapper);
     $this->app['spot'] = $spot;
     // Create a session object
     $this->app['session'] = new Session(new MockFileSessionStorage());
     // Use our pre-configured Application object
     ob_start();
     $this->app->run();
     ob_end_clean();
     // Create our Request object
     $req = m::mock('Symfony\\Component\\HttpFoundation\\Request');
     $req->shouldReceive('get')->with('id')->andReturn($talkId);
     $req->shouldReceive('get')->with('comment')->andReturn($comment);
     // Execute the controller and capture the output
     $controller = new \OpenCFP\Http\Controller\Admin\TalksController();
     $controller->setApplication($this->app);
     $response = $controller->commentCreateAction($req);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\RedirectResponse', $response);
 }
Пример #3
0
 /**
  * Verify that not found talk redirects and sets flash error message
  *
  * @test
  */
 public function talkNotFoundHasFlashMessage()
 {
     $talkId = uniqid();
     // Override our mapper with the double
     $spot = m::mock('Spot\\Locator');
     $spot->shouldReceive('mapper')->with(\OpenCFP\Domain\Entity\Talk::class)->andReturn([]);
     $this->app['spot'] = $spot;
     // Create a session object
     $this->app['session'] = new Session(new MockFileSessionStorage());
     // Use our pre-configured Application object
     ob_start();
     $this->app->run();
     ob_end_clean();
     // Create our Request object
     $req = m::mock('Symfony\\Component\\HttpFoundation\\Request');
     $req->shouldReceive('get')->with('id')->andReturn($talkId);
     // Execute the controller and capture the output
     $controller = new \OpenCFP\Http\Controller\Admin\TalksController();
     $controller->setApplication($this->app);
     $response = $controller->viewAction($req);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\RedirectResponse', $response);
     $this->assertContains('Could not find requested talk', $this->app['session']->get('flash'));
 }