function RestfulHookMenuTestCase::testVersionNegotiation in RESTful 7
Same name and namespace in other branches
- 7.2 tests/RestfulHookMenuTestCase.test \RestfulHookMenuTestCase::testVersionNegotiation()
Test the version negotiation.
File
- tests/
RestfulHookMenuTestCase.test, line 126 - Contains RestfulHookMenuTestCase
Class
- RestfulHookMenuTestCase
- @file Contains RestfulHookMenuTestCase
Code
function testVersionNegotiation() {
// Fake the HTTP header.
$original_header = \RestfulManager::getRequestHttpHeader('X-API-Version');
// 1. my-api/v1.1/articles yields version 1.1
$handler = restful_get_restful_handler_for_path('api/v1.1/articles');
$this
->assertEqual($handler
->getVersion(), array(
'major' => 1,
'minor' => 1,
), 'api/v1.1/articles resolves 1.1');
// 2. my-api/v1/articles yields version 1.7 (update to last 1.x version)
drupal_static_reset('RestfulBase::getVersionFromRequest');
$handler = restful_get_restful_handler_for_path('api/v1/articles');
$this
->assertEqual($handler
->getVersion(), array(
'major' => 1,
'minor' => 7,
), 'api/v1.7/articles resolves 1.7');
// 3. my-api/articles with header X-API-Version: v1.1 yields 1.1
// Fake the HTTP header.
$_SERVER['HTTP_X_API_VERSION'] = 'v1.1';
drupal_static_reset('RestfulBase::getVersionFromRequest');
$handler = restful_get_restful_handler_for_path('api/articles');
$this
->assertEqual($handler
->getVersion(), array(
'major' => 1,
'minor' => 1,
), 'api/articles resolves 1.1');
// 4. my-api/articles with header X-API-Version: v1 yields 1.7
// Fake the HTTP header.
$_SERVER['HTTP_X_API_VERSION'] = 'v1';
drupal_static_reset('RestfulBase::getVersionFromRequest');
drupal_static_reset('restful_get_restful_handler_for_path');
$handler = restful_get_restful_handler_for_path('api/articles');
$this
->assertEqual($handler
->getVersion(), array(
'major' => 1,
'minor' => 7,
), 'api/articles resolves 1.7');
// 5. my-api/articles without header X-API-Version yields 2.0
drupal_static_reset('RestfulBase::getVersionFromRequest');
drupal_static_reset('restful_get_restful_handler_for_path');
unset($_SERVER['HTTP_X_API_VERSION']);
$handler = restful_get_restful_handler_for_path('api/articles');
$this
->assertEqual($handler
->getVersion(), array(
'major' => 2,
'minor' => 0,
), 'api/articles resolves 2.0');
// Restore the original header.
$_SERVER['HTTP_X_API_VERSION'] = $original_header;
}