public function testControllerNoticeToException() { $this->client = $this->createClient(); $errorOccured = false; $syslogProcessorMock = $this->getMockBuilder('Keboola\\Syrup\\Monolog\\Processor\\SyslogProcessor')->disableOriginalConstructor()->getMock(); $syslogProcessorMock->expects($this->any())->method("processRecord")->with($this->callback(function ($subject) use(&$errorOccured) { if ($subject['message'] == 'Notice: Undefined offset: 3') { $e = $subject['context']['exception']; $errorOccured = true; return $e instanceof \Symfony\Component\Debug\Exception\ContextErrorException; } return true; }))->willReturn(['level' => 100]); $container = $this->client->getContainer(); $container->set('syrup.monolog.syslog_processor', $syslogProcessorMock); $this->client->request('GET', '/tests/notice'); $response = $this->client->getResponse(); $responseJson = json_decode($response->getContent(), true); $this->assertEquals('error', $responseJson['status']); $this->assertEquals('Application error', $responseJson['error']); $this->assertEquals(500, $responseJson['code']); $this->assertArrayHasKey('exceptionId', $responseJson); $this->assertArrayHasKey('runId', $responseJson); $this->assertTrue($errorOccured); }
/** * @depends testPut */ public function testDeleteMultiple() { $data = [2, 3]; $uri = self::$router->generate('post_assets') . '.json'; self::$client->request('DELETE', $uri, ['images' => json_encode($data)]); $this->assertTrue(self::$client->getResponse()->isRedirect()); }
public function testSearchPage() { $this->client->request('GET', '/search?keyword=samsung sync master'); $response = $this->client->getResponse(); $this->assertTrue($response->isSuccessful()); $this->assertEquals('application/json', $response->headers->get('Content-Type')); }
/** * Test token creation and usage */ public function testTokenCreation() { $headers = array('PHP_AUTH_USER' => 'test_key', 'PHP_AUTH_PW' => 'test_secret', 'HTTP_username' => 'p-admin', 'HTTP_password' => 'p-admin'); $this->client->request('GET', '/oauth/access_token?grant_type=password', array(), array(), $headers); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type')); }
public function testPutPlayerAction() { $em = self::$kernel->getContainer()->get('doctrine')->getManager(); $queryBuilder = $em->createQueryBuilder(); $players = $queryBuilder->select('p')->from('DraftBundle:Player', 'p')->setMaxResults(1)->getQuery()->execute(); if (is_array($players)) { $player = $players[0]; } else { $player = $players; } $name = $player->getName(); $team = $player->getNflTeam(); $position = $player->getPosition(); $toEncode = array('name' => 'willy wonka', 'position' => 'QB', 'nflTeam' => 'SF', 'draftYear' => '2016'); $postData = json_encode($toEncode); $this->client->request('PUT', '/api/players/' . $player->getId(), array(), array(), array('CONTENT_TYPE' => 'application/json'), $postData); $response = $this->client->getResponse(); $content = $response->getContent(); $this->assertTrue($response->isSuccessful()); $this->assertEmpty($content); $updatedPlayer = $em->getRepository('DraftBundle:Player')->find($player->getId()); $this->assertEquals('willy wonka', $updatedPlayer->getName()); $updatedPlayer->setName($name); $updatedPlayer->setNflTeam($team); $updatedPlayer->setPosition($position); $em->persist($updatedPlayer); $em->flush(); }
protected function assertApiGetResponse($apiUri, $expectedStatusCode, $expectedJsonString) { static::$client->request('GET', $apiUri); $this->assertStatusCode($expectedStatusCode, static::$client); $responseBody = static::$client->getResponse()->getContent(); static::assertJson($responseBody); static::assertJsonStringEqualsJsonString($expectedJsonString, $responseBody); }
/** * @param string $method * @param array $parameters * @return Page */ public function open($method = 'GET', $parameters = []) { $this->crawler = $this->client->request($method, $this->unmaskUrl($parameters)); if (!in_array($this->client->getResponse()->getStatusCode(), [200, 302])) { throw new \RuntimeException(sprintf("Can't open \"%s\"", $this->getUrl())); } return $this; }
/** * @return Crawler * @throws \Exception */ protected static function loginAsUser() { $uri = self::$container->get('router')->generate('login_route'); $crawler = self::$client->request('GET', $uri); $form = $crawler->selectButton('login_btn')->form(['_username' => 'test', '_password' => '12345678']); self::$client->submit($form); self::assertTrue(self::$client->getResponse()->isRedirection()); return self::$client->followRedirect(); }
/** * Request to API, return result * @param string $url URL of API call * @param string $method HTTP method of API call * @param array $params parameters of POST call * @return array */ protected function callApi($url, $method = 'POST', $params = array()) { $this->httpClient->request($method, $url, [], [], [], json_encode($params)); $response = $this->httpClient->getResponse(); /* @var \Symfony\Component\HttpFoundation\Response $response */ $responseJson = json_decode($response->getContent(), true); $this->assertNotEmpty($responseJson, sprintf("Response of API call '%s' after json decoding should not be empty. Raw response:\n%s\n", $url, $response->getContent())); return $responseJson; }
protected function callApiGet($url = null, $data = array(), $requiredHttpCode = 200) { $method = 'GET'; $this->httpClient->request($method, $url, array()); $response = $this->httpClient->getResponse(); $this->assertEquals($requiredHttpCode, $response->getStatusCode(), sprintf(AbstractTest::ERROR_HTTP_CODE, $method, $url, $response->getContent())); $responseJson = json_decode($response->getContent(), true); // $this->assertNotEmpty($responseJson, sprintf(self::ERROR_EMPTY_REPONSE, $method, $url)); return $responseJson; }
public function testOut() { $this->client->request('GET', '/'); $crawler = $this->client->followRedirect(); $link = $crawler->filter('a#logout')->eq(0)->link(); $this->client->click($link); //suivre redirection vers page login quand click sur 'logout' $this->assertEquals('Sonata\\UserBundle\\Controller\\SecurityFOSUser1Controller::logoutAction', $this->client->getRequest()->attributes->get('_controller')); $this->assertEquals(302, $this->client->getResponse()->getStatusCode()); }
/** * Test for AppBundle\Controller\DefaultController::feedAction * Also test performance - Any PHP used should be limited to 32MB of memory * * @param string $source * @param integer $start * @param integer $amount * @param integer $expectedAmount * * @dataProvider feedDataProvider */ public function testFeed($source, $start, $amount, $expectedAmount) { $this->client->request('GET', '/feed', array('source' => $source, 'start' => $start, 'amount' => $amount)); $response = $this->client->getResponse(); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('application/json', $response->headers->get('Content-type')); $this->assertCount($expectedAmount, json_decode($response->getContent(), true)); $this->assertLessThan(1024 * 1024 * 32, memory_get_peak_usage(true)); // 32 MB }
/** * Overridden _doRequest method * * @param string $request * @param string $location * @param string $action * @param int $version * @param int $one_way * * @return string */ public function __doRequest($request, $location, $action, $version, $one_way = 0) { //save directly in _SERVER array $_SERVER['HTTP_SOAPACTION'] = $action; $_SERVER['CONTENT_TYPE'] = 'application/soap+xml'; //make POST request $this->client->request('POST', (string) $location, array(), array(), array(), (string) $request); unset($_SERVER['HTTP_SOAPACTION']); unset($_SERVER['CONTENT_TYPE']); return $this->client->getResponse()->getContent(); }
public final function run() { $this->prepareDataForRequest(); $this->makeRequest(); $this->response = $this->client->getResponse(); $this->testResponse($this->response); /* Вот этого тут так не должно быть... нельзя жестко завязываться на JSON'e, но пока ситуация терпит */ $this->responseDataObject = json_decode($this->client->getResponse()->getContent(), false, 512, JSON_BIGINT_AS_STRING); $this->testResponseData($this->responseDataObject); $this->testResponseDataWithDataAsserterCallbacks(); }
/** * @return mixed */ protected function getAccessToken() { if (!array_key_exists($this->getUsername(), $this->accessToken)) { $headers = array('PHP_AUTH_USER' => 'test_key', 'PHP_AUTH_PW' => 'test_secret', 'HTTP_username' => $this->getUsername(), 'HTTP_password' => $this->getPassword()); $this->client->request('GET', '/oauth/access_token?grant_type=password', array(), array(), $headers); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type')); $tokenReponse = json_decode($this->client->getResponse()->getContent(), true); $this->accessToken[$this->getUsername()] = $tokenReponse['access_token']; } return $this->accessToken[$this->getUsername()]; }
public function testListAction() { // Request the endpoint $this->client->request('GET', '/instruments', [], [], $this->requestParameters); // Get the Response content $response = $this->client->getResponse(); $content = json_decode($response->getContent()); // Validate Response $this->assertEquals(200, $response->getStatusCode()); $this->assertTrue(!empty($content->data)); $this->assertTrue(is_array($content->data)); }
public function doLogin($username) { /** @var Crawler */ $crawler = $this->client->request('GET', '/login'); /** @var Response */ $response = $this->client->getResponse(); /** @var Form */ $form = $crawler->selectButton('Login')->form(); $form['_username'] = $username; $form['_password'] = '******'; $crawler = $this->client->submit($form); }
public function testFind() { $container = $this->client->getContainer(); $fakeDirectoryUser = ['firstName' => 'first', 'lastName' => 'last', 'email' => 'email', 'telephoneNumber' => 'phone', 'campusId' => 'abc']; $mockUser = m::mock('Ilios\\CoreBundle\\Entity\\User')->shouldReceive('getCampusId')->once()->andReturn('abc')->mock(); $container->mock('ilioscore.directory', 'Ilios\\CoreBundle\\Service\\Directory')->shouldReceive('findByCampusId')->with('abc')->once()->andReturn($fakeDirectoryUser); $container->mock('ilioscore.user.manager', 'Ilios\\CoreBundle\\Entity\\Manager\\User')->shouldReceive('findOneBy')->with(['id' => 1])->once()->andReturn($mockUser); $this->makeJsonRequest($this->client, 'GET', $this->getUrl('ilios_web_directory_find', ['id' => '1']), null, $this->getAuthenticatedUserToken()); $response = $this->client->getResponse(); $content = $response->getContent(); $this->assertEquals(Codes::HTTP_OK, $response->getStatusCode(), var_export($content, true)); $this->assertEquals(array('result' => $fakeDirectoryUser), json_decode($content, true), var_export($content, true)); }
/** * Test form login with invalid user */ public function testLoginWithInvalidUser() { $userName = '******'; $password = '******'; $crawler = $this->client->request('GET', '/login'); $form = $crawler->selectButton('Log in')->form(); $form['_username'] = $userName; $form['_password'] = $password; $this->client->submit($form); $this->assertEquals(302, $this->client->getResponse()->getStatusCode()); $token = $this->client->getContainer()->get('security.token_storage')->getToken(); $this->assertNull($token); }
private function oAuthLogin() { // var_dump(JWT::encode( // [ // 'username' => $this->client_username, 'password' => $this->client_password // ], // $this->client_id // ));die; $this->client->request('POST', 'http://' . $this->url . '/oauth/v2/token', ['client_id' => $this->client_id, 'client_secret' => $this->client_secret, 'api_key' => JWT::encode(['username' => $this->client_username, 'password' => $this->client_password], $this->client_id), 'grant_type' => 'http://' . $this->url . '/grants/api_key']); $response = json_decode($this->client->getResponse()->getContent()); $this->access_token = $response->access_token; $this->refresh_token = $response->refresh_token; }
public function testEdit() { $crawler = $this->client->request('GET', '/member'); $this->assertEquals(Response::HTTP_OK, $this->client->getResponse()->getStatusCode()); $this->assertEquals(1, $crawler->filter('div.app_member_index')->count()); $this->assertGreaterThanOrEqual(1, $crawler->selectLink('Show')->count()); $crawler = $this->client->click($crawler->selectLink('Show')->first()->link()); $this->assertEquals(Response::HTTP_OK, $this->client->getResponse()->getStatusCode()); $this->assertEquals(1, $crawler->filter('div.app_member_show')->count()); $this->assertGreaterThanOrEqual(1, $crawler->selectLink('Edit')->count()); $crawler = $this->client->click($crawler->selectLink('Edit')->first()->link()); $this->assertEquals(Response::HTTP_OK, $this->client->getResponse()->getStatusCode()); $this->assertEquals(1, $crawler->filter('div.app_member_edit')->count()); }
/** * Стандартный тест проверки rest api * * @param $url * @param $method * @param array $param * @param int $code * @param null $obj * * @return mixed */ protected function JsonRequestTest($url, $method, $param = [], $code = 200, $obj = null) { $route = $this->getUrl($url, $param); if (is_null($obj)) { $this->client->request($method, $route); } else { $this->client->request($method, $route, [], [], ['CONTENT_TYPE' => 'application/json'], json_encode($obj)); } $response = $this->client->getResponse(); $this->assertJsonResponse($response, $code); $content = $response->getContent(); $decoded = json_decode($content); return $decoded; }
public function testStatisticsPage() { $this->addBattery("AAA", 10, 'User 1'); $this->addBattery("AAA", 20, 'User 2'); $this->addBattery("AA", 5); $crawler = $this->client->request('GET', '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $batteryTypeAA = $crawler->filter('td[data-type="AA"]'); $this->assertEquals(1, $batteryTypeAA->count()); $this->assertEquals("5", $batteryTypeAA->first()->html()); $batteryTypeAAA = $crawler->filter('td[data-type="AAA"]'); $this->assertEquals(1, $batteryTypeAAA->count()); $this->assertEquals("30", $batteryTypeAAA->first()->html()); }
/** * @dataProvider provideAuthenticatedUrls * @coversNothing * * @param $login * @param $password * @param $url * @param $expectedText */ public function testEmployeeAuthenticatedUrl($url, $data) { $urlBefore = $url; $url = str_replace('[id_school_ecureuil]', self::$fixture->getEntityId('school-ecureuils'), $url); $url = str_replace('[id_school_notredame]', self::$fixture->getEntityId('school-nddf'), $url); $url = str_replace('[id_school_roland]', self::$fixture->getEntityId('school-rg'), $url); foreach ($data as $expected) { $codeStatus = $expected[0]; $login = $expected[1]['login']; $password = $expected[1]['passwd']; self::$client = static::createClient(array(), array('PHP_AUTH_USER' => $login, 'PHP_AUTH_PW' => $password)); self::$client->request('GET', $url); $this->assertEquals($codeStatus, self::$client->getResponse()->getStatusCode(), "For : " . $urlBefore . " and user : '******' - ensure status is " . $codeStatus); } }
public function testRegisterActions() { $urls = array('/register', '/register/check-email', '/register/confirm/17368237462', '/register/confirmed'); foreach ($urls as $url) { /** @var Crawler */ $crawler = $this->client->request('GET', '/register'); /** @var Response */ $response = $this->client->getResponse(); // $response->getStatusCode() will be MOVED_PERMANENTLY (301) // if the register line is removed from security.yaml. $this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode()); $this->assertStringEndsWith('/login', $response->headers->get('location')); $this->assertGreaterThan(0, $crawler->filter('html:contains("Redirecting")')->count()); } }
/** * @group failing * @runInSeparateProcess */ public function testSecuredEventWithImpersonatingUser() { $this->client = $this->createAuthenticatedClient('admin'); $name = 'simple.event'; $crawler = $this->client->request('GET', "/some-secure-url/{$name}?_switch_user=user"); $this->assertTrue($this->client->getResponse()->isSuccessful()); $this->assertEquals('user', $this->client->getProfile()->getCollector('security')->getUser()); $event = $this->getEventArrayFromResponse($crawler); $this->assertEquals($name, $event['typeId']); $this->assertEquals($name, $event['type']); $this->assertEquals($name, $event['description']); $this->assertEquals('admin', $event['impersonatingUser']); $this->assertEquals('user', $event['user']); $this->assertEquals('127.0.0.1', $event['ip']); }
public function testShouldResolveWithCustomFiltersFromCache() { /** @var Signer $signer */ $signer = self::$kernel->getContainer()->get('liip_imagine.cache.signer'); $params = array( 'filters' => array( 'thumbnail' => array('size' => array(50, 50)), ), ); $path = 'images/cats.jpeg'; $hash = $signer->sign($path, $params['filters']); $expectedCachePath = 'thumbnail_web_path/rc/'.$hash.'/'.$path; $url = 'http://localhost/media/cache/resolve/'.$expectedCachePath.'?'.http_build_query($params); $this->filesystem->dumpFile( $this->cacheRoot.'/'.$expectedCachePath, 'anImageContent' ); $this->client->request('GET', $url); $response = $this->client->getResponse(); $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response); $this->assertEquals(301, $response->getStatusCode()); $this->assertEquals('http://localhost/media/cache'.'/'.$expectedCachePath, $response->getTargetUrl()); $this->assertFileExists($this->cacheRoot.'/'.$expectedCachePath); }
/** * @param array|string $gridParameters * @param array $filter * @return Response */ public function requestGrid($gridParameters, $filter = array()) { if (is_string($gridParameters)) { $gridParameters = array('gridName' => $gridParameters); } //transform parameters to nested array $parameters = array(); foreach ($filter as $param => $value) { $param .= '=' . $value; parse_str($param, $output); $parameters = array_merge_recursive($parameters, $output); } $gridParameters = array_merge_recursive($gridParameters, $parameters); $this->client->request('GET', $this->getUrl('oro_datagrid_index', $gridParameters)); return $this->client->getResponse(); }
public function testGetQueries() { $this->createConfig(); $testing = $this->container->getParameter('testing'); $this->createCredentials($testing['db']['mysql']); $this->createQuery('test', ['name' => 'testQuery', 'query' => 'SELECT * FROM test', 'outputTable' => 'in.c-main.test', 'incremental' => 0, 'primaryKey' => 'id']); self::$client->request('GET', $this->componentName . '/configs/test/queries'); /* @var Response $responseJson */ $responseJson = self::$client->getResponse()->getContent(); $response = json_decode($responseJson, true); $this->assertEquals(200, self::$client->getResponse()->getStatusCode()); $this->assertNotEmpty($response); $query = $response[0]; $this->assertArrayHasKey('id', $query); $this->assertArrayHasKey('name', $query); $this->assertArrayHasKey('query', $query); $this->assertArrayHasKey('outputTable', $query); $this->assertArrayHasKey('incremental', $query); $this->assertArrayHasKey('primaryKey', $query); $this->assertEquals('SELECT * FROM test', $query['query']); $this->assertEquals('in.c-main.test', $query['outputTable']); $this->assertEquals(0, $query['incremental']); $this->assertEquals('id', $query['primaryKey']); $this->assertEquals('testQuery', $query['name']); $this->assertEquals(true, $query['enabled']); }
/** * @group putLeagueplayers */ public function testPutLeaguePlayerAction() { $em = self::$kernel->getContainer()->get('doctrine')->getManager(); $teams = $em->getRepository('DraftBundle:Team')->findAll(); $leaguePlayer = array('team' => $teams[0]->getId()); $postData = json_encode($leaguePlayer); $this->client->request('PUT', '/api/leagueplayers/' . 29327, array(), array(), array("CONTENT_TYPE" => "application/json"), $postData); $response = $this->client->getResponse(); $this->assertTrue($response->isSuccessful()); $this->assertEquals(204, $response->getStatusCode()); $leaguePlayer = $em->getRepository('DraftBundle:League_Player')->find(29327); $this->assertEquals($teams[0]->getId(), $leaguePlayer->getTeam()->getId()); $leaguePlayer->setTeam(null); $em->persist($leaguePlayer); $em->flush(); }