作者:renegar
项目:silexcs
/**
* @dataProvider provideIncorrectValues
* @expectedException RuntimeException
*/
public function testGetSessionDataIncorrectSessionData($value)
{
$cookie = new Cookie('TEST', $value);
$client = new Client(new Application());
$client->getCookieJar()->set($cookie);
$this->getSessionData($client, 'TEST');
}
作者:jsmith0
项目:silex-annotation-provide
protected function makeRequest($method, $uri, $annotationOptions = array())
{
$this->getClient($annotationOptions);
$this->client->request($method, $uri, array(), array(), $this->requestOptions);
$response = $this->client->getResponse();
return $response;
}
作者:sev2
项目:flyaround_s
/**
* test login
*/
public function testLoginSuccess()
{
$data = array('username' => 'user', 'password' => 'password');
$this->client->request('POST', $this->getUrl('api_login_check'), $data);
$this->assertJsonResponse($this->client->getResponse(), 200);
$response = json_decode($this->client->getResponse()->getContent(), true);
$this->assertArrayHasKey('token', $response);
// check token from query string work
$client = static::createClient();
$client->request('HEAD', $this->getUrl('api_ping', array($this->queryParameterName => $response['token'])));
$this->assertJsonResponse($client->getResponse(), 200, false);
// check token work
$client = static::createClient();
$client->setServerParameter('HTTP_Authorization', sprintf('%s %s', $this->authorizationHeaderPrefix, $response['token']));
$client->request('HEAD', $this->getUrl('api_ping'));
$this->assertJsonResponse($client->getResponse(), 200, false);
// check token works several times, as long as it is valid
$client = static::createClient();
$client->setServerParameter('HTTP_Authorization', sprintf('%s %s', $this->authorizationHeaderPrefix, $response['token']));
$client->request('HEAD', $this->getUrl('api_ping'));
$this->assertJsonResponse($client->getResponse(), 200, false);
// check a bad token does not work
$client = static::createClient();
$client->setServerParameter('HTTP_Authorization', sprintf('%s %s', $this->authorizationHeaderPrefix, $response['token'] . 'changed'));
$client->request('HEAD', $this->getUrl('api_ping'));
$this->assertJsonResponse($client->getResponse(), 401, false);
// check error if no authorization header
$client = static::createClient();
$client->request('HEAD', $this->getUrl('api_ping'));
$this->assertJsonResponse($client->getResponse(), 401, false);
}
作者:evaneo
项目:silex-jwt-provide
public function testDoesNotReturn401IfValidToken()
{
$this->register('chain');
$jwt = JWT::encode(['sub' => 'John'], 'secret', 'HS256');
$client = new Client($this->app);
$client->request('GET', '/?jwt=' . $jwt);
$response = $client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
}
作者:renegar
项目:ai
/**
* @dataProvider provideData
*/
public function testValidJsonData($label, $data, $expectedResponse)
{
$this->app['aiv.input'] = new \AIV\Input\SymfonyRequest\JSONInput();
$client = new Client($this->app, []);
$label = 'Test Case: ' . $label;
$client->request('POST', '/', [], [], [], json_encode(['test-name' => $data]));
$response = $client->getResponse();
$this->assertTrue($response->isOk(), $label);
$this->assertContains($expectedResponse, $response->getContent(), $label);
}
作者:nlegof
项目:Phraseane
/**
* @dataProvider provideExceptionsAndCode
*/
public function testError($exception, $code)
{
$app = new Application('test');
$app['dispatcher']->addSubscriber(new ApiExceptionHandlerSubscriber($app));
$app->get('/', function () use($exception) {
throw $exception;
});
$client = new Client($app);
$client->request('GET', '/');
$this->assertEquals($code, $client->getResponse()->getStatusCode());
}
作者:luisbrit
项目:Phraseane
private function request($accept)
{
$app = new Application(Application::ENV_TEST);
$app['dispatcher']->addSubscriber(new ContentNegotiationSubscriber($app['negotiator'], $app['phraseanet.content-negotiation.priorities']));
$app->get('/content/negociation', function () {
return '';
});
$client = new Client($app);
$client->request('GET', '/content/negociation', array(), array(), array('HTTP_Accept' => $accept));
return $client->getResponse();
}
作者:renegar
项目:weblet-clien
public function getAccessToken(Client $client)
{
$app = $this->app;
$this->assertArrayHasKey('session.storage.handler', $app, 'Renegare\\SilexCSH\\CookieSessionServiceProvider has not been registered.');
$sessionStorageHandler = $app['session.storage.handler'];
$this->assertInstanceOf('Renegare\\SilexCSH\\CookieSessionHandler', $sessionStorageHandler, 'Can only support Renegare\\SilexCSH\\CookieSessionHandler sessions');
$cookie = $client->getCookieJar()->get($sessionStorageHandler->getCookieName());
$sessionData = unserialize(unserialize($cookie->getValue())[1]);
$token = unserialize($sessionData['_security_app']);
return $token;
}
作者:nlegof
项目:Phraseane
private function request($accept)
{
$app = new Application('test');
$app['dispatcher']->addSubscriber(new ContentNegotiationSubscriber($app));
$app->get('/content/negociation', function () {
return '';
});
$client = new Client($app);
$client->request('GET', '/content/negociation', array(), array(), array('HTTP_Accept' => $accept));
return $client->getResponse();
}
作者:JeroenDeDau
项目:QueryrAP
protected function assertLinkRel(Client $client, string $linkRel, string $expected)
{
$this->assertTrue($client->getResponse()->isSuccessful(), 'request is successful');
foreach ($client->getResponse()->headers->get('Link', null, false) as $linkValue) {
if (strpos($linkValue, 'rel="' . $linkRel . '"') !== false) {
$this->assertSame($expected, $linkValue);
return;
}
}
$this->fail('No link with rel "' . $linkRel . '" found.');
}
作者:nlegof
项目:Phraseane
/**
* @param array $conf
* @param string $method
* @param array $extraHeaders
*
* @return \Symfony\Component\HttpFoundation\Response
*/
private function request(array $conf, $method = 'GET', array $extraHeaders = [])
{
$app = new Application('test');
$app['phraseanet.configuration']['api_cors'] = $conf;
$app['dispatcher']->addSubscriber(new ApiCorsSubscriber($app));
$app->get('/api/v1/test-route', function () {
return '';
});
$client = new Client($app);
$client->request($method, '/api/v1/test-route', [], [], array_merge($extraHeaders, ['HTTP_Origin' => $this->origin]));
return $client->getResponse();
}
作者:romainneutro
项目:BadFaith-ServiceProvide
public function testGetVariants()
{
$preferred = null;
$app = new Application();
$app->register(new BadFaithServiceProvider());
$app->get('/', function (Application $app) use(&$preferred) {
$preferred = $app['bad-faith']->headerLists['accept_language']->getPreferred();
});
$client = new Client($app, array());
$client->request('GET', '/', array(), array(), array('HTTP_ACCEPT_ENCODING' => 'gzip,deflate,sdch', 'HTTP_ACCEPT_LANGUAGE' => 'de-DE,en;q=0.8'));
$this->assertEquals('de-DE', $preferred->pref);
}
作者:nlegof
项目:Phraseane
/**
* @dataProvider provideExceptionsAndCode
*/
public function testErrorOnOtherRoutes($exception, $code, $contentType)
{
$app = new Application('test');
unset($app['exception_handler']);
$app['dispatcher']->addSubscriber(new ApiOauth2ErrorsSubscriber(PhraseaExceptionHandler::register(), $this->createTranslatorMock()));
$app->get('/', function () use($exception) {
throw $exception;
});
$client = new Client($app);
$this->setExpectedException(get_class($exception));
$client->request('GET', '/');
}
作者:nlegof
项目:Phraseane
public function testItCanBeDisabled()
{
$app = new Application();
$app['exception_handler'] = new PhraseaExceptionHandlerSubscriber(PhraseaExceptionHandler::register());
$app->get('/', function () {
throw new \Exception();
});
$app['exception_handler']->disable();
$client = new Client($app);
$this->setExpectedException('\\Exception');
$client->request('GET', '/');
}
作者:nlegof
项目:Phraseane
public function testNoHeaderNoRedirection()
{
$app = new Application();
unset($app['exception_handler']);
$app['dispatcher']->addSubscriber(new FirewallSubscriber());
$app->get('/', function () {
throw new HttpException(500);
});
$client = new Client($app);
$this->setExpectedException('Symfony\\Component\\HttpKernel\\Exception\\HttpException');
$client->request('GET', '/');
}
作者:nlegof
项目:Phraseane
public function testErrorOnOtherExceptions()
{
$app = new Application('test');
$app['bridge.account'] = $this->getMockBuilder('Bridge_Account')->disableOriginalConstructor()->getMock();
unset($app['exception_handler']);
$app['dispatcher']->addSubscriber(new BridgeExceptionSubscriber($app));
$app->get('/', function () {
throw new \InvalidArgumentException();
});
$client = new Client($app);
$this->setExpectedException('\\InvalidArgumentException');
$client->request('GET', '/');
}
作者:luisbrit
项目:Phraseane
public function testCookieIsSet()
{
$client = new Client(self::$DI['app']);
$client->request('GET', '/', [], [], ['HTTP_ACCEPT_LANGUAGE' => 'fr-FR,fr;q=0.9']);
$settedCookie = null;
foreach ($client->getResponse()->headers->getCookies() as $cookie) {
if ($cookie->getName() === 'locale') {
$settedCookie = $cookie;
break;
}
}
$this->assertNotNull($settedCookie);
$this->assertEquals('fr', $settedCookie->getValue());
}
作者:mimi
项目:silex-documentation-provide
/**
* @dataProvider dataProviderHTMLSyntax
* @test
*/
public function should_use_title_and_resources_if_html($syntax, $dir, $extension)
{
// GIVEN
$this->app->register(new DocumentationProvider(), array("documentation.dir" => __DIR__ . "/datas/" . $dir, "documentation.url" => '/doc', "documentation.extension" => $extension, "documentation.home" => 'index', "documentation.syntax" => $syntax, "documentation.title" => 'My Documentation', "documentation.styles" => array('/components/bootstrap/css/bootstrap.min.css'), "documentation.scripts" => array('/components/jquery/jquery.min.js', '/components/bootstrap/js/bootstrap.min.js')));
$client = new Client($this->app);
// WHEN
$crawler = $client->request('GET', '/doc');
// THEN
$this->assertTrue($client->getResponse()->isOk());
$this->assertContains('text/html', $client->getResponse()->headers->get('Content-Type'));
$this->assertCount(1, $crawler->filter("title"));
$this->assertCount(1, $crawler->filter("link"));
$this->assertCount(2, $crawler->filter("script"));
}
作者:kumatc
项目:silex-json-body-provide
/**
* @test
*/
public function notReplaceIfBodyContentIsNotJson()
{
$self = $this;
$body = array("number" => 123, "string" => "foo", "array" => array(5, 27, 42), "object" => (object) array("bar" => "baz"), "true" => true, "false" => false);
$this->app->register(new JsonBodyProvider());
$this->app->post("/", function (Request $req) use($self) {
$self->assertCount(0, $req->request);
return "Done.";
});
$client = new Client($this->app);
$client->request('POST', '/', array(), array(), array('CONTENT_TYPE' => 'application/json'), json_encode($body) . "..broken!!!");
$response = $client->getResponse();
$this->assertEquals("Done.", $response->getContent());
}
作者:nlegof
项目:Phraseane
public function testAllowedIpsAreSetWhenEmpty()
{
$configuration = $this->getConfigurationMock();
$configuration->expects($this->once())->method('isSetup')->will($this->returnValue(true));
$configuration->expects($this->once())->method('offsetExists')->with('trusted-proxies')->will($this->returnValue(false));
$app = new Application();
$app['dispatcher']->addSubscriber(new TrustedProxySubscriber($configuration));
$app->get('/', function () {
return 'data';
});
$client = new Client($app);
$client->request('GET', '/');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
$this->assertEquals([], Request::getTrustedProxies());
}