diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php index dfae39fe7cf1..37c5ffdb263e 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php @@ -37,6 +37,13 @@ class StatisticsAdminTest extends WebTestBase { */ protected $test_node; + /** + * The Guzzle HTTP client. + * + * @var \Guzzle\Http\ClientInterface; + */ + protected $client; + public static function getInfo() { return array( 'name' => 'Test statistics admin.', @@ -55,6 +62,8 @@ class StatisticsAdminTest extends WebTestBase { $this->privileged_user = $this->drupalCreateUser(array('administer statistics', 'view post access counter', 'create page content')); $this->drupalLogin($this->privileged_user); $this->test_node = $this->drupalCreateNode(array('type' => 'page', 'uid' => $this->privileged_user->uid)); + $this->client = \Drupal::httpClient(); + $this->client->setConfig(array('curl.options' => array(CURLOPT_TIMEOUT => 10))); } /** @@ -78,16 +87,16 @@ class StatisticsAdminTest extends WebTestBase { $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); global $base_url; $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics'). '/statistics.php'; - drupal_http_request($stats_path, array('method' => 'POST', 'data' => $post, 'headers' => $headers, 'timeout' => 10000)); + $this->client->post($stats_path, $headers, $post)->send(); // Hit the node again (the counter is incremented after the hit, so // "1 view" will actually be shown when the node is hit the second time). $this->drupalGet('node/' . $this->test_node->nid); - drupal_http_request($stats_path, array('method' => 'POST', 'data' => $post, 'headers' => $headers, 'timeout' => 10000)); + $this->client->post($stats_path, $headers, $post)->send(); $this->assertText('1 view', 'Node is viewed once.'); $this->drupalGet('node/' . $this->test_node->nid); - drupal_http_request($stats_path, array('method' => 'POST', 'data' => $post, 'headers' => $headers, 'timeout' => 10000)); + $this->client->post($stats_path, $headers, $post)->send(); $this->assertText('2 views', 'Node is viewed 2 times.'); } @@ -104,7 +113,7 @@ class StatisticsAdminTest extends WebTestBase { $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); global $base_url; $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics'). '/statistics.php'; - drupal_http_request($stats_path, array('method' => 'POST', 'data' => $post, 'headers' => $headers, 'timeout' => 10000)); + $this->client->post($stats_path, $headers, $post)->send(); $result = db_select('node_counter', 'n') ->fields('n', array('nid')) @@ -139,9 +148,9 @@ class StatisticsAdminTest extends WebTestBase { $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); global $base_url; $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics'). '/statistics.php'; - drupal_http_request($stats_path, array('method' => 'POST', 'data' => $post, 'headers' => $headers, 'timeout' => 10000)); + $this->client->post($stats_path, $headers, $post)->send(); $this->drupalGet('node/' . $this->test_node->nid); - drupal_http_request($stats_path, array('method' => 'POST', 'data' => $post, 'headers' => $headers, 'timeout' => 10000)); + $this->client->post($stats_path, $headers, $post)->send(); $this->assertText('1 view', 'Node is viewed once.'); // statistics_cron() will subtract diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsLoggingTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsLoggingTest.php index 286ad7139303..86c7b42fe351 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsLoggingTest.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsLoggingTest.php @@ -25,6 +25,13 @@ class StatisticsLoggingTest extends WebTestBase { */ public static $modules = array('statistics', 'block'); + /** + * The Guzzle HTTP client. + * + * @var \Guzzle\Http\ClientInterface; + */ + protected $client; + public static function getInfo() { return array( 'name' => 'Statistics logging tests', @@ -59,6 +66,9 @@ class StatisticsLoggingTest extends WebTestBase { // Clear the logs. db_truncate('node_counter'); + + $this->client = \Drupal::httpClient(); + $this->client->setConfig(array('curl.options' => array(CURLOPT_TIMEOUT => 10))); } /** @@ -79,7 +89,7 @@ class StatisticsLoggingTest extends WebTestBase { $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); global $base_url; $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics'). '/statistics.php'; - drupal_http_request($stats_path, array('method' => 'POST', 'data' => $post, 'headers' => $headers, 'timeout' => 10000)); + $this->client->post($stats_path, $headers, $post)->send(); $this->assertIdentical($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Testing an uncached page.'); $node_counter = statistics_get($this->node->nid); $this->assertIdentical($node_counter['totalcount'], '1'); @@ -87,7 +97,7 @@ class StatisticsLoggingTest extends WebTestBase { // Verify logging of a cached page. $this->drupalGet($path); // Manually calling statistics.php, simulating ajax behavior. - drupal_http_request($stats_path, array('method' => 'POST', 'data' => $post, 'headers' => $headers, 'timeout' => 10000)); + $this->client->post($stats_path, $headers, $post)->send(); $this->assertIdentical($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Testing a cached page.'); $node_counter = statistics_get($this->node->nid); $this->assertIdentical($node_counter['totalcount'], '2'); @@ -96,7 +106,7 @@ class StatisticsLoggingTest extends WebTestBase { $this->drupalLogin($this->auth_user); $this->drupalGet($path); // Manually calling statistics.php, simulating ajax behavior. - drupal_http_request($stats_path, array('method' => 'POST', 'data' => $post, 'headers' => $headers, 'timeout' => 10000)); + $this->client->post($stats_path, $headers, $post)->send(); $node_counter = statistics_get($this->node->nid); $this->assertIdentical($node_counter['totalcount'], '3'); diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsReportsTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsReportsTest.php index 50cc99b3948d..ed14bb0c8a5c 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsReportsTest.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsReportsTest.php @@ -36,7 +36,9 @@ class StatisticsReportsTest extends StatisticsTestBase { $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); global $base_url; $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics'). '/statistics.php'; - drupal_http_request($stats_path, array('method' => 'POST', 'data' => $post, 'headers' => $headers, 'timeout' => 10000)); + $client = \Drupal::httpClient(); + $client->setConfig(array('curl.options' => array(CURLOPT_TIMEOUT => 10))); + $client->post($stats_path, $headers, $post)->send(); // Configure and save the block. $this->drupalPlaceBlock('statistics_popular_block', array('label' => 'Popular content'), array( diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTokenReplaceTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTokenReplaceTest.php index 0b5909d4136e..fad28078df7d 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTokenReplaceTest.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTokenReplaceTest.php @@ -38,7 +38,9 @@ class StatisticsTokenReplaceTest extends StatisticsTestBase { $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); global $base_url; $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics'). '/statistics.php'; - drupal_http_request($stats_path, array('method' => 'POST', 'data' => $post, 'headers' => $headers, 'timeout' => 10000)); + $client = \Drupal::httpClient(); + $client->setConfig(array('curl.options' => array(CURLOPT_TIMEOUT => 10))); + $client->post($stats_path, $headers, $post)->send(); $statistics = statistics_get($node->nid); // Generate and test tokens.