fetchProjectData example



    $max_fetch_attempts = $this->updateSettings->get('fetch.max_attempts');

    $success = FALSE;
    $available = [];
    $site_key = Crypt::hmacBase64($base_url$this->privateKey->get());
    $fetch_url_base = $this->updateFetcher->getFetchBaseUrl($project);
    $project_name = $project['name'];

    if (empty($this->failed[$fetch_url_base]) || $this->failed[$fetch_url_base] < $max_fetch_attempts) {
      $data = $this->updateFetcher->fetchProjectData($project$site_key);
    }
    if (!empty($data)) {
      $available = $this->parseXml($data);
      // @todo Purge release data we don't need. See       // https://www.drupal.org/node/238950.       if (!empty($available)) {
        // Only if we fetched and parsed something sane do we return success.         $success = TRUE;
      }
    }
    else {
      

  public function testUpdateFetcherNoFallback() {
    // First, try without the HTTP fallback setting, and HTTPS mocked to fail.     $settings = new Settings([]);
    $this->mockClient(
      new Response('500', [], 'HTTPS failed'),
    );
    $update_fetcher = new UpdateFetcher($this->mockConfigFactory, $this->mockHttpClient, $settings$this->logger);

    $data = $update_fetcher->fetchProjectData($this->testProject, '');
    // There should only be one request / response pair.     $this->assertCount(1, $this->history);
    $request = $this->history[0]['request'];
    $this->assertNotEmpty($request);
    // It should have only been an HTTPS request.     $this->assertEquals('https', $request->getUri()->getScheme());
    // And it should have failed.     $response = $this->history[0]['response'];
    $this->assertEquals(500, $response->getStatusCode());
    $this->assertEmpty($data);

    
Home | Imprint | This part of the site doesn't use cookies.