class AuthcacheP13nTestDefaultRequestHandler in Authenticated User Page Caching (Authcache) 7.2
Test cases for default request handler.
Hierarchy
- class \DrupalTestCase
- class \DrupalUnitTestCase
Expanded class hierarchy of AuthcacheP13nTestDefaultRequestHandler
File
- modules/
authcache_p13n/ tests/ authcache_p13n.request-handler.test, line 14 - Define unit tests for request handler.
View source
class AuthcacheP13nTestDefaultRequestHandler extends DrupalUnitTestCase {
protected $stubObserver;
protected $coreService;
protected $requestValidator;
protected $contentBuilder;
protected $contentEncoder;
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => "Default Request Handler",
'description' => 'Unit tests for default request handler.',
'group' => 'Authcache Personalization',
);
}
/**
* {@inheritdoc}
*/
public function setUp() {
require_once __DIR__ . '/../includes/AuthcacheP13nDefaultRequestHandler.inc';
$this->stubObserver = new AuthcacheP13nTestStubObserver();
$this->coreService = new AuthcacheP13nTestCoreServiceStub($this->stubObserver);
$this->requestValidator = new AuthcacheP13nTestRequestValidatorStub($this->stubObserver);
$this->contentBuilder = new AuthcacheP13nTestContentBuilderStub($this->stubObserver);
$this->contentEncoder = new AuthcacheP13nTestContentEncoderStub($this->stubObserver);
parent::setUp();
}
/**
* Test default configuration.
*/
public function testDefaultRequestHandler() {
$filters = array();
$context_providers = array();
$params = array(
'some' => 'args',
);
// Setup expectations.
$validate = $this->stubObserver
->method($this->requestValidator, 'validate', $params + array(
'valid' => TRUE,
))
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args(array(
$params,
)));
$build = $this->stubObserver
->method($this->contentBuilder, 'build', 'output built successfully')
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args(array(
$params + array(
'valid' => TRUE,
),
array(),
)));
$content_type = $this->stubObserver
->method($this->contentEncoder, 'contentType', 'application/test')
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args());
$encode = $this->stubObserver
->method($this->contentEncoder, 'encode', 'encoded successfully')
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args(array(
'output built successfully',
)));
$add_header = $this->stubObserver
->method($this->coreService, 'drupalAddHttpHeader')
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args(array(
'Content-Type',
'application/test',
)));
// Run handler, test full sequence without filters / context providers /
$handler = new AuthcacheP13nDefaultRequestHandler($this->coreService, $this->requestValidator, $this->contentBuilder, $this->contentEncoder, $filters, $context_providers);
ob_start();
$handler
->handle($params);
$result = ob_get_clean();
$this
->assertEqual('encoded successfully', $result);
// Verify stubs.
$this
->assert($add_header
->verify($message), $message);
$this
->assert($validate
->verify($message), $message);
$this
->assert($build
->verify($message), $message);
$this
->assert($content_type
->verify($message), $message);
$this
->assert($encode
->verify($message), $message);
}
/**
* Test handler with request filter.
*/
public function testDefaultRequestHandlerWithRequestFilter() {
$filters = array(
'request' => array(
new AuthcacheP13nTestFilterStub($this->stubObserver),
new AuthcacheP13nTestFilterStub($this->stubObserver),
),
);
$context_providers = array();
$params = array(
'some' => 'args',
);
// Setup expectations.
$first_filter = $this->stubObserver
->method($filters['request'][0], 'filter', array(
'some' => 'filtered args',
))
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args(array(
'request',
$params,
)));
$second_filter = $this->stubObserver
->method($filters['request'][1], 'filter', array(
'some' => 'args after second filter',
))
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args(array(
'request',
array(
'some' => 'filtered args',
),
)));
$validate = $this->stubObserver
->method($this->requestValidator, 'validate')
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args(array(
array(
'some' => 'args after second filter',
),
)));
// Run handler.
$handler = new AuthcacheP13nDefaultRequestHandler($this->coreService, $this->requestValidator, $this->contentBuilder, $this->contentEncoder, $filters, $context_providers);
ob_start();
$handler
->handle($params);
ob_end_clean();
// Verify stubs.
$this
->assert($first_filter
->verify($message), $message);
$this
->assert($second_filter
->verify($message), $message);
$this
->assert($validate
->verify($message), $message);
}
/**
* Test handler with response filter.
*/
public function testDefaultRequestHandlerWithResponseFilter() {
$filters = array(
'response' => array(
new AuthcacheP13nTestFilterStub($this->stubObserver),
new AuthcacheP13nTestFilterStub($this->stubObserver),
),
);
$context_providers = array();
$params = array(
'some' => 'args',
);
// Setup expectations.
$encode = $this->stubObserver
->method($this->contentEncoder, 'encode', 'encoded output')
->expect(AuthcacheP13nTestStubVerifyer::once());
$first_filter = $this->stubObserver
->method($filters['response'][0], 'filter', 'output after first filter')
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args(array(
'response',
'encoded output',
)));
$second_filter = $this->stubObserver
->method($filters['response'][1], 'filter', 'output after second filter')
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args(array(
'response',
'output after first filter',
)));
// Run handler.
$handler = new AuthcacheP13nDefaultRequestHandler($this->coreService, $this->requestValidator, $this->contentBuilder, $this->contentEncoder, $filters, $context_providers);
ob_start();
$handler
->handle($params);
$result = ob_get_clean();
$this
->assertEqual('output after second filter', $result);
// Verify stubs.
$this
->assert($encode
->verify($message), $message);
$this
->assert($first_filter
->verify($message), $message);
$this
->assert($second_filter
->verify($message), $message);
}
/**
* Test handler with context provider.
*/
public function testDefaultRequestHandlerWithContextProvider() {
$filters = array();
$context_providers = array(
'my context' => new AuthcacheP13nTestContextProviderStub($this->stubObserver),
'other context' => new AuthcacheP13nTestContextProviderStub($this->stubObserver),
);
$params = array(
'some' => 'args',
);
$validate = $this->stubObserver
->method($this->requestValidator, 'validate', $params + array(
'valid' => TRUE,
))
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args(array(
$params,
)));
// Setup expectations.
$cp_1 = $this->stubObserver
->method($context_providers['my context'], 'get', 'some value')
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args(array(
$params + array(
'valid' => TRUE,
),
)));
$cp_2 = $this->stubObserver
->method($context_providers['other context'], 'get', array(
'other stuff',
))
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args(array(
$params + array(
'valid' => TRUE,
),
)));
$build = $this->stubObserver
->method($this->contentBuilder, 'build')
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args(array(
$params + array(
'valid' => TRUE,
),
array(
'my context' => 'some value',
'other context' => array(
'other stuff',
),
),
)));
// Run handler.
$handler = new AuthcacheP13nDefaultRequestHandler($this->coreService, $this->requestValidator, $this->contentBuilder, $this->contentEncoder, $filters, $context_providers);
ob_start();
$handler
->handle($params);
ob_end_clean();
// Verify stubs.
$this
->assert($validate
->verify($message), $message);
$this
->assert($cp_1
->verify($message), $message);
$this
->assert($cp_2
->verify($message), $message);
$this
->assert($build
->verify($message), $message);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AuthcacheP13nTestDefaultRequestHandler:: |
protected | property | ||
AuthcacheP13nTestDefaultRequestHandler:: |
protected | property | ||
AuthcacheP13nTestDefaultRequestHandler:: |
protected | property | ||
AuthcacheP13nTestDefaultRequestHandler:: |
protected | property | ||
AuthcacheP13nTestDefaultRequestHandler:: |
protected | property | ||
AuthcacheP13nTestDefaultRequestHandler:: |
public static | function | ||
AuthcacheP13nTestDefaultRequestHandler:: |
public | function |
Sets up unit test environment. Overrides DrupalUnitTestCase:: |
|
AuthcacheP13nTestDefaultRequestHandler:: |
public | function | Test default configuration. | |
AuthcacheP13nTestDefaultRequestHandler:: |
public | function | Test handler with context provider. | |
AuthcacheP13nTestDefaultRequestHandler:: |
public | function | Test handler with request filter. | |
AuthcacheP13nTestDefaultRequestHandler:: |
public | function | Test handler with response filter. | |
DrupalTestCase:: |
protected | property | Assertions thrown in that test case. | |
DrupalTestCase:: |
protected | property | The database prefix of this test run. | |
DrupalTestCase:: |
protected | property | The original file directory, before it was changed for testing purposes. | |
DrupalTestCase:: |
public | property | Current results of this test case. | |
DrupalTestCase:: |
protected | property | Flag to indicate whether the test has been set up. | |
DrupalTestCase:: |
protected | property | ||
DrupalTestCase:: |
protected | property | ||
DrupalTestCase:: |
protected | property | This class is skipped when looking for the source of an assertion. | |
DrupalTestCase:: |
protected | property | The test run ID. | |
DrupalTestCase:: |
protected | property | Time limit for the test. | |
DrupalTestCase:: |
public | property | Whether to cache the installation part of the setUp() method. | |
DrupalTestCase:: |
public | property | Whether to cache the modules installation part of the setUp() method. | |
DrupalTestCase:: |
protected | property | URL to the verbose output file directory. | |
DrupalTestCase:: |
protected | function | Internal helper: stores the assert. | |
DrupalTestCase:: |
protected | function | Check to see if two values are equal. | |
DrupalTestCase:: |
protected | function | Check to see if a value is false (an empty string, 0, NULL, or FALSE). | |
DrupalTestCase:: |
protected | function | Check to see if two values are identical. | |
DrupalTestCase:: |
protected | function | Check to see if two values are not equal. | |
DrupalTestCase:: |
protected | function | Check to see if two values are not identical. | |
DrupalTestCase:: |
protected | function | Check to see if a value is not NULL. | |
DrupalTestCase:: |
protected | function | Check to see if a value is NULL. | |
DrupalTestCase:: |
protected | function | Check to see if a value is not false (not an empty string, 0, NULL, or FALSE). | |
DrupalTestCase:: |
public static | function | Delete an assertion record by message ID. | |
DrupalTestCase:: |
protected | function | Fire an error assertion. | 1 |
DrupalTestCase:: |
public | function | Handle errors during test runs. | 1 |
DrupalTestCase:: |
protected | function | Handle exceptions. | |
DrupalTestCase:: |
protected | function | Fire an assertion that is always negative. | |
DrupalTestCase:: |
public static | function | Converts a list of possible parameters into a stack of permutations. | |
DrupalTestCase:: |
protected | function | Cycles through backtrace until the first non-assertion method is found. | |
DrupalTestCase:: |
public static | function | Returns the database connection to the site running Simpletest. | |
DrupalTestCase:: |
public static | function | Store an assertion from outside the testing context. | |
DrupalTestCase:: |
protected | function | Fire an assertion that is always positive. | |
DrupalTestCase:: |
public static | function | Generates a random string containing letters and numbers. | |
DrupalTestCase:: |
public static | function | Generates a random string of ASCII characters of codes 32 to 126. | |
DrupalTestCase:: |
public | function | Run all tests in this class. | |
DrupalTestCase:: |
protected | function | Logs a verbose message in a text file. | |
DrupalUnitTestCase:: |
protected | function | 1 | |
DrupalUnitTestCase:: |
function |
Constructor for DrupalUnitTestCase. Overrides DrupalTestCase:: |