/**
  * @param integer $userId
  * @param integer $limit
  * @param integer $offset
  * @return array
  * @throws \TYPO3\Flow\Http\Client\InfiniteRedirectionException
  */
 protected function getProjectsData($userId = null, $limit = null, $offset = null)
 {
     $query = http_build_query(['users' => $userId, 'limit' => $limit, 'offset' => $offset, 'format' => 'json']);
     $response = $this->browser->request(sprintf('http://readthedocs.org/api/v1/project/?%s', $query));
     $projectsData = json_decode($response, true);
     return $projectsData;
 }
 /**
  * Go to the previous form page
  *
  * @param \Symfony\Component\DomCrawler\Form $form
  * @return \TYPO3\Flow\Http\Response
  */
 protected function gotoPreviousFormPage(\Symfony\Component\DomCrawler\Form $form)
 {
     $previousButton = $this->browser->getCrawler()->filterXPath('//nav[@class="form-navigation"]/*/*[contains(@class, "previous")]/button');
     $previousButton->rewind();
     $form->set(new InputFormField($previousButton->current()));
     return $this->browser->submit($form);
 }
 /**
  * @param string $email
  * @param string $firstName
  * @param string $lastName
  * @return bool
  * @throws \TYPO3\Flow\Http\Client\InfiniteRedirectionException
  */
 protected function sendApiRequest($email, $firstName, $lastName)
 {
     $browser = new Browser();
     $engine = new CurlEngine();
     $browser->setRequestEngine($engine);
     $jsonString = 'email=' . urlencode($email) . '&first_name=' . urlencode($firstName) . '&last_name=' . urlencode($lastName) . '&token=' . $this->settings['Slack']['token'] . '&set_active=true';
     return $browser->request($this->settings['Slack']['TeamUrl'] . '/api/users.admin.invite?t=' . time(), 'POST', [], [], [], $jsonString);
 }
 /**
  * @param string $method
  * @param \Flowpack\ElasticSearch\Domain\Model\Client $client
  * @param string $path
  * @param array $arguments
  * @param string|array $content
  *
  * @return \Flowpack\ElasticSearch\Transfer\Response
  */
 public function request($method, \Flowpack\ElasticSearch\Domain\Model\Client $client, $path = null, $arguments = array(), $content = null)
 {
     $clientConfigurations = $client->getClientConfigurations();
     $clientConfiguration = $clientConfigurations[0];
     $uri = clone $clientConfiguration->getUri();
     if ($path !== null) {
         $uri->setPath($uri->getPath() . $path);
     }
     $response = $this->browser->request($uri, $method, $arguments, array(), array(), is_array($content) ? json_encode($content) : $content);
     return new Response($response, $this->browser->getLastRequest());
 }
 /**
  * @return \Guzzle\Http\EntityBodyInterface|string
  */
 public function literatureAction()
 {
     $literatureUrl = $this->settings['data']['literature'];
     $this->initializeAction();
     try {
         $literature = $this->browser->request($literatureUrl)->getContent();
         return $literature;
     } catch (\Exception $e) {
         $this->systemLogger->logException($e);
         return '';
     }
 }
 /**
  * @param Node $node
  * @param Application $application
  * @param Deployment $deployment
  * @param array $options
  * @throws \TYPO3\Flow\Http\Client\InfiniteRedirectionException
  */
 protected function executeOrSimulate(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     if (empty($options['clearPhpCacheUris'])) {
         return;
     }
     $uris = is_array($options['clearPhpCacheUris']) ? $options['clearPhpCacheUris'] : array($options['clearPhpCacheUris']);
     foreach ($uris as $uri) {
         $deployment->getLogger()->log('... (localhost): curl "' . $uri . '"', LOG_DEBUG);
         if ($deployment->isDryRun() === FALSE) {
             $this->browser->request($uri);
         }
     }
 }
 /**
  * @param string $command
  * @param string $method
  * @param array $parameters
  * @param array $content
  * @return mixed $data
  * @throws Exception
  * @throws \TYPO3\Flow\Http\Exception
  */
 public function call($command, $method = 'GET', array $parameters = array(), array $content = array())
 {
     $url = $this->apiUrl . $command . '?' . http_build_query($parameters);
     $this->emitBeforeApiCall($url, $method);
     // maybe we will throw own exception to give less information (token is outputed)
     $response = $this->browser->request($url, $method, array(), array(), $this->server, json_encode($content));
     $this->emitApiCall($url, $method, $response);
     $statusCode = $response->getStatusCode();
     if ($statusCode < 200 || $statusCode >= 400) {
         throw new Exception('ApiRequest was not successful for command  ' . $command . ' Response was: ' . $response->getStatus(), 1423473312);
     }
     $content = json_decode($response->getContent(), TRUE);
     if ($content === NULL) {
         throw new Exception('Response from ApiRequest is not a valid json', 1423473312);
     }
     return $content;
 }
 /**
  * @param integer $categoryId
  * @return array
  */
 protected function getCategoryData($categoryId)
 {
     $response = $this->browser->request(sprintf('%s/c/%u/show.json', $this['baseUri'], $categoryId));
     $category = json_decode($response, true)['category'];
     $category['parentCategories'] = [];
     $category['idPath'] = $category['id'];
     $category['slugPath'] = $category['slug'];
     $parentCategoryId = array_key_exists('parent_category_id', $category) ? $category['parent_category_id'] : null;
     while ($parentCategoryId !== null) {
         $response = $this->browser->request(sprintf('%s/c/%u/show.json', $this['baseUri'], $parentCategoryId));
         $parentCategory = json_decode($response, true)['category'];
         array_unshift($category['parentCategories'], $parentCategory);
         $category['idPath'] = $parentCategory['id'] . '/' . $category['idPath'];
         $category['slugPath'] = $parentCategory['slug'] . '/' . $category['slugPath'];
         $parentCategoryId = array_key_exists('parent_category_id', $parentCategory) ? $parentCategory['parent_category_id'] : null;
     }
     return $category;
 }
 /**
  * Sets up a virtual browser and web environment for seamless HTTP and MVC
  * related tests.
  *
  * @return void
  */
 protected function setupHttp()
 {
     $this->browser = new \TYPO3\Flow\Http\Client\Browser();
     $this->browser->setRequestEngine(new \TYPO3\Flow\Http\Client\InternalRequestEngine());
     $this->router = $this->browser->getRequestEngine()->getRouter();
     $requestHandler = self::$bootstrap->getActiveRequestHandler();
     $requestHandler->setHttpRequest(Request::create(new \TYPO3\Flow\Http\Uri('http://localhost/typo3/flow/test')));
     $requestHandler->setHttpResponse(new \TYPO3\Flow\Http\Response());
 }
Example #10
0
 /**
  * @param string $command
  * @param string $method
  * @param array $content
  * @return string
  * @throws Exception
  * @throws \TYPO3\Flow\Http\Client\InfiniteRedirectionException
  */
 protected function getApiResponse($command, $method = 'GET', array $content)
 {
     $url = self::URL . trim($command, '/') . '?' . http_build_query(array('auth_token' => $this->settings['authToken']));
     $response = $this->browser->request($url, $method, array(), array(), $this->server, json_encode($content));
     $statusCode = $response->getStatusCode();
     if ($statusCode < 200 || $statusCode >= 400) {
         throw new Exception('HipChat request was not successful. Response was: ' . $response->getStatus() . '. Content: ' . $response->getContent(), 1408549039);
     }
     return $response->getContent();
 }
 /**
  * @test
  * @expectedException \TYPO3\Flow\Http\Client\InfiniteRedirectionException
  */
 public function browserHaltsOnExceedingMaximumRedirections()
 {
     $requestEngine = $this->getMock(\TYPO3\Flow\Http\Client\RequestEngineInterface::class);
     for ($i = 0; $i <= 10; $i++) {
         $response = new Response();
         $response->setHeader('Location', 'http://localhost/this/willLead/you/knowhere/' . $i);
         $response->setStatus(301);
         $requestEngine->expects($this->at($i))->method('sendRequest')->will($this->returnValue($response));
     }
     $this->browser->setRequestEngine($requestEngine);
     $this->browser->request('http://localhost/some/initialRequest');
 }
 /**
  * Sets up a virtual browser and web environment for seamless HTTP and MVC
  * related tests.
  *
  * @return void
  */
 protected function setupHttp()
 {
     $_GET = array();
     $_POST = array();
     $_COOKIE = array();
     $_FILES = array();
     $_SERVER = array('REDIRECT_FLOW_CONTEXT' => 'Development', 'REDIRECT_FLOW_REWRITEURLS' => '1', 'REDIRECT_STATUS' => '200', 'FLOW_CONTEXT' => 'Testing', 'FLOW_REWRITEURLS' => '1', 'HTTP_HOST' => 'localhost', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.52.7 (KHTML, like Gecko) Version/5.1.2 Safari/534.52.7', 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_LANGUAGE' => 'en-us', 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate', 'HTTP_CONNECTION' => 'keep-alive', 'PATH' => '/usr/bin:/bin:/usr/sbin:/sbin', 'SERVER_SIGNATURE' => '', 'SERVER_SOFTWARE' => 'Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/1.0.0e DAV/2 PHP/5.3.8', 'SERVER_NAME' => 'localhost', 'SERVER_ADDR' => '127.0.0.1', 'SERVER_PORT' => '80', 'REMOTE_ADDR' => '127.0.0.1', 'DOCUMENT_ROOT' => '/opt/local/apache2/htdocs/', 'SERVER_ADMIN' => 'george@localhost', 'SCRIPT_FILENAME' => '/opt/local/apache2/htdocs/Web/index.php', 'REMOTE_PORT' => '51439', 'REDIRECT_QUERY_STRING' => '', 'REDIRECT_URL' => '', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_METHOD' => 'GET', 'QUERY_STRING' => '', 'REQUEST_URI' => '', 'SCRIPT_NAME' => '/index.php', 'PHP_SELF' => '/index.php', 'REQUEST_TIME' => 1326472534);
     $this->browser = new \TYPO3\Flow\Http\Client\Browser();
     $this->browser->setRequestEngine(new \TYPO3\Flow\Http\Client\InternalRequestEngine());
     $this->router = $this->browser->getRequestEngine()->getRouter();
     $requestHandler = self::$bootstrap->getActiveRequestHandler();
     $requestHandler->setHttpRequest(\TYPO3\Flow\Http\Request::create(new \TYPO3\Flow\Http\Uri('http://localhost/typo3/flow/test')));
     $requestHandler->setHttpResponse(new \TYPO3\Flow\Http\Response());
 }
Example #13
0
 /**
  * Call the Piwik Reporting API for node specific statistics
  * @todo make this protected for security !!!
  * @param $node NodeInterface
  * @param $controllerContext ControllerContext
  * @param $arguments array
  * @return DataResult
  */
 public function getNodeStatistics($node = NULL, $controllerContext = NULL, $arguments = array())
 {
     if (!empty($this->settings['host']) && !empty($this->settings['token_auth'] && !empty($this->settings['token_auth']))) {
         $params = '';
         foreach ($arguments as $key => $value) {
             if (!empty($value) && $key != 'view' && $key != 'device' && $key != 'type') {
                 $params .= '&' . $key . '=' . rawurlencode($value);
             }
         }
         try {
             $pageUrl = urlencode($this->getLiveNodeUri($node, $controllerContext)->__toString());
         } catch (StatisticsNotAvailableException $err) {
             return;
         }
         $apiCallUrl = $this->settings['protocol'] . '://' . $this->settings['host'] . '/index.php?module=API&format=json' . $params;
         $apiCallUrl .= '&pageUrl=' . $pageUrl;
         $apiCallUrl .= '&idSite=' . $this->settings['idSite'] . '&token_auth=' . $this->settings['token_auth'];
         $this->browser->setRequestEngine($this->browserRequestEngine);
         if ($arguments['view'] == 'TimeSeriesView') {
             $response = $this->browser->request($apiCallUrl);
             return new TimeSeriesDataResult($response);
         }
         if ($arguments['view'] == 'ColumnView') {
             $response = $this->browser->request($apiCallUrl);
             return new ColumnDataResult($response);
         }
         if ($arguments['type'] == 'device') {
             $apiCallUrl .= '&segment=pageUrl==' . $pageUrl;
             $response = $this->browser->request($apiCallUrl);
             return new DeviceDataResult($response);
         }
         if ($arguments['type'] == 'osFamilies') {
             $apiCallUrl .= '&segment=pageUrl==' . $pageUrl;
             $response = $this->browser->request($apiCallUrl);
             return new OperatingSystemDataResult($response);
         }
         if ($arguments['type'] == 'browsers') {
             $apiCallUrl .= '&segment=pageUrl==' . $pageUrl;
             $response = $this->browser->request($apiCallUrl);
             return new BrowserDataResult($response);
         }
         if ($arguments['type'] == 'outlinks') {
             $apiCallUrl .= '&segment=pageUrl==' . $pageUrl;
             $response = $this->browser->request($apiCallUrl);
             return new OutlinkDataResult($response);
         }
     }
 }
 /**
  * @test
  */
 public function valueForDisabledCheckboxIsNotLost()
 {
     $postIdentifier = $this->setupDummyPost();
     $post = $this->persistenceManager->getObjectByIdentifier($postIdentifier, \TYPO3\Fluid\Tests\Functional\Form\Fixtures\Domain\Model\Post::class);
     $this->assertEquals(true, $post->getPrivate());
     $this->browser->request('http://localhost/test/fluid/formobjects/edit?fooPost=' . $postIdentifier);
     $checkboxDisabled = $this->browser->getCrawler()->filterXPath('//*[@id="private"]')->attr('disabled');
     $this->assertNotEmpty($checkboxDisabled);
     $this->assertEquals($checkboxDisabled, $this->browser->getCrawler()->filterXPath('//input[@type="hidden" and contains(@name,"private")]')->attr('disabled'), 'The hidden checkbox field is not disabled like the connected checkbox.');
     $form = $this->browser->getForm();
     $this->browser->submit($form);
     $this->persistenceManager->clearState();
     $post = $this->persistenceManager->getObjectByIdentifier($postIdentifier, \TYPO3\Fluid\Tests\Functional\Form\Fixtures\Domain\Model\Post::class);
     // This will currently never fail, because DomCrawler\Form does not handle hidden checkbox fields correctly!
     // Hence this test currently only relies on the correctly set "disabled" attribute on the hidden field.
     $this->assertEquals(true, $post->getPrivate(), 'The value for the checkbox field "private" was lost on form submit!');
 }
 /**
  * @test
  */
 public function formIsRedisplayedIfValidationErrorsOccur()
 {
     $this->browser->request('http://localhost/test/fluid/formobjects');
     $form = $this->browser->getForm();
     $form['post']['name']->setValue('Egon Olsen');
     $form['post']['email']->setValue('test_noValidEmail');
     $this->browser->submit($form);
     $form = $this->browser->getForm();
     $this->assertSame('Egon Olsen', $form['post']['name']->getValue());
     $this->assertSame('test_noValidEmail', $form['post']['email']->getValue());
     $this->assertSame('f3-form-error', $this->browser->getCrawler()->filterXPath('//*[@id="email"]')->attr('class'));
     $form['post']['email']->setValue('*****@*****.**');
     $response = $this->browser->submit($form);
     $this->assertSame('Egon Olsen|another@email.org', $response->getContent());
 }
 /**
  * @test
  */
 public function radioButtonsAreCheckedCorrectlyOnValidationErrors()
 {
     $this->browser->request('http://localhost/test/fluid/formobjects');
     $form = $this->browser->getForm();
     $form['post']['author']['emailAddress']->setValue('test_noValidEmail');
     $form['post']['category']->setValue('bar');
     $form['post']['subCategory']->setValue('bar');
     $this->browser->submit($form);
     $this->assertEquals('', $this->browser->getCrawler()->filterXPath('//input[@id="category_foo"]')->attr('checked'));
     $this->assertEquals('checked', $this->browser->getCrawler()->filterXPath('//input[@id="category_bar"]')->attr('checked'));
     $this->assertEquals('', $this->browser->getCrawler()->filterXPath('//input[@id="subCategory_foo"]')->attr('checked'));
     $this->assertEquals('checked', $this->browser->getCrawler()->filterXPath('//input[@id="subCategory_bar"]')->attr('checked'));
     $form['post']['category']->setValue('foo');
     $form['post']['subCategory']->setValue('foo');
     $this->browser->submit($form);
     $this->assertEquals('checked', $this->browser->getCrawler()->filterXPath('//input[@id="category_foo"]')->attr('checked'));
     $this->assertEquals('', $this->browser->getCrawler()->filterXPath('//input[@id="category_bar"]')->attr('checked'));
     $this->assertEquals('checked', $this->browser->getCrawler()->filterXPath('//input[@id="subCategory_foo"]')->attr('checked'));
     $this->assertEquals('', $this->browser->getCrawler()->filterXPath('//input[@id="subCategory_bar"]')->attr('checked'));
 }
 /**
  * @param string $changeId
  * @param string $topic
  */
 private function setTopic($changeId, $topic)
 {
     $user = $this->settings['Gerrit']['username'];
     $pass = $this->settings['Gerrit']['password'];
     $browser = new Client\Browser();
     $engine = new Client\CurlEngine();
     $browser->setRequestEngine($engine);
     $browser->request('https://' . $user . ':' . $pass . '@review.typo3.org/a/changes/' . $changeId . '/topic', 'PUT', array(), array(), array('PHP_AUTH_USER' => $user, 'PHP_AUTH_PW' => $pass, 'HTTP_CONTENT_TYPE' => 'application/json'), json_encode(array('topic' => $topic)));
     $this->counter['canSet']++;
 }
Example #18
0
 /**
  * Returns a browser instance with curlengine and authentication parameters set
  *
  * @return Browser
  */
 protected function getBrowser()
 {
     $browser = new Browser();
     $browser->setRequestEngine(new CurlEngine());
     if (array_key_exists('username', $this->apiSettings) && !empty($this->apiSettings['username']) && array_key_exists('password', $this->apiSettings) && !empty($this->apiSettings['password'])) {
         $browser->addAutomaticRequestHeader('Authorization', 'Basic ' . base64_encode($this->apiSettings['username'] . ':' . $this->apiSettings['password']));
     }
     return $browser;
 }
 /**
  * Update the page https://forge.typo3.org/projects/typo3cms-core/wiki/Forgertest
  * @deprecated Not usable because our redmine is too old
  * @param string $content
  * @param string $project
  * @param string $page
  */
 protected function updateWikiPage($content, $project = 'typo3cms-core', $page = 'Mergedorphans')
 {
     //content[text]
     //content[comments]
     $user = $this->settings['Gerrit']['username'];
     $pass = $this->settings['Gerrit']['password'];
     $browser = new Client\Browser();
     $engine = new Client\CurlEngine();
     $browser->setRequestEngine($engine);
     $res = $browser->request('https://' . $user . ':' . $pass . '@forge.typo3.org/projects/' . $project . '/wiki/' . $page . '/', 'PUT', array(), array(), array('PHP_AUTH_USER' => $user, 'PHP_AUTH_PW' => $pass), 'content[text]=' . rawurlencode($content) . '&commit=Save');
     \TYPO3\Flow\var_dump($res);
 }
 /**
  * @param string $projectSlug
  * @return array
  * @throws \TYPO3\Flow\Http\Client\InfiniteRedirectionException
  */
 protected function getProjectData($projectSlug)
 {
     $response = $this->browser->request(sprintf('http://readthedocs.org/api/v1/project/%s', $projectSlug));
     $projectData = json_decode($response, true);
     return $projectData;
 }
 /**
  * @param string $uri
  * @return \TYPO3\Flow\Http\Response
  */
 public function processUriPOST($uri)
 {
     return $this->browser->request($uri, $method = 'POST');
 }