class AuthcacheP13nTestFragmentBuilder in Authenticated User Page Caching (Authcache) 7.2
Tests fragment builder.
Hierarchy
- class \DrupalTestCase
- class \DrupalUnitTestCase
Expanded class hierarchy of AuthcacheP13nTestFragmentBuilder
File
- modules/
authcache_p13n/ tests/ authcache_p13n.request-handler.test, line 263 - Define unit tests for request handler.
View source
class AuthcacheP13nTestFragmentBuilder extends DrupalUnitTestCase {
protected $stubObserver;
protected $fragmentValidator;
protected $fragementLoader;
protected $fragmentAccess;
protected $fragmentRenderer;
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Fragment Builder',
'description' => 'Unit tests for fragment builder.',
'group' => 'Authcache Personalization',
);
}
/**
* {@inheritdoc}
*/
public function setUp() {
require_once __DIR__ . '/../includes/AuthcacheP13nFragmentBuilder.inc';
$this->stubObserver = new AuthcacheP13nTestStubObserver();
$this->fragmentValidator = new AuthcacheP13nTestFragmentValidatorStub($this->stubObserver);
$this->fragmentLoader = new AuthcacheP13nTestFragmentLoaderStub($this->stubObserver);
$this->fragmentAccess = new AuthcacheP13nTestFragmentAccessStub($this->stubObserver);
$this->fragmentRenderer = new AuthcacheP13nTestFragmentStub($this->stubObserver);
parent::setUp();
}
/**
* Tests fragment request.
*/
public function testFragmentBuilder() {
$input = array(
'a' => array(
'some_key' => 'some_subject',
),
);
$context = array(
'bla',
);
$builder = new AuthcacheP13nFragmentBuilder($this->fragmentRenderer, NULL, NULL, NULL);
// Setup expectations.
$render = $this->stubObserver
->method($this->fragmentRenderer, 'render', 'rendered')
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args(array(
'some_key',
'some_subject',
$context,
)));
// Run builder.
$output = $builder
->build($input, $context);
$this
->assertEqual('rendered', $output);
// Verify stub.
$this
->assert($render
->verify($message), $message);
}
/**
* Test request with validator.
*/
public function testFragmentBuilderValidation() {
$builder = new AuthcacheP13nFragmentBuilder($this->fragmentRenderer, $this->fragmentValidator, NULL, NULL);
// Setup expectations.
$validator = $this->stubObserver
->method($this->fragmentValidator, 'validate', array(
'some_key' => 'valid value',
))
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args(array(
array(
'some_key' => 'some_key',
),
)));
// Run validator.
$result = $builder
->validate(array(
'a' => 'some_key',
));
// Verify stub.
$this
->assertEqual(array(
'a' => array(
'some_key' => 'valid value',
),
), $result);
$this
->assert($validator
->verify($message), $message);
// Setup expectations.
$validator = $this->stubObserver
->method($this->fragmentValidator, 'validate', new AuthcacheP13nRequestInvalidInput())
->expect(AuthcacheP13nTestStubVerifyer::once());
// Run validator.
$input = array(
'a' => 'invalid',
);
try {
$builder
->validate($input);
$this
->fail('AuthcacheP13nFragmentBuilder should throw an AuthcacheP13nRequestInvalidInput when validation fails');
} catch (AuthcacheP13nRequestInvalidInput $e) {
unset($e);
$this
->pass('AuthcacheP13nFragmentBuilder should throw an AuthcacheP13nRequestInvalidInput when validation fails');
}
// Verify stub.
$this
->assert($validator
->verify($message), $message);
}
/**
* Test request with loader.
*/
public function testFragmentBuilderLoader() {
$context = array(
'some' => 'context',
);
$builder = new AuthcacheP13nFragmentBuilder($this->fragmentRenderer, NULL, $this->fragmentLoader, NULL);
// Setup expectations.
$load = $this->stubObserver
->method($this->fragmentLoader, 'load', array(
'some_key' => 'loaded subject',
))
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args(array(
array(
'some_key' => 'some_subject',
),
$context,
)));
$render = $this->stubObserver
->method($this->fragmentRenderer, 'render', 'rendered')
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args(array(
'some_key',
'loaded subject',
$context,
)));
// Run builder.
$input = array(
'a' => array(
'some_key' => 'some_subject',
),
);
$output = $builder
->build($input, $context);
$this
->assertEqual('rendered', $output);
// Verify stub.
$this
->assert($load
->verify($message), $message);
$this
->assert($render
->verify($message), $message);
// Setup expectations.
$load = $this->stubObserver
->method($this->fragmentLoader, 'load', new AuthcacheP13nRequestNotFound())
->expect(AuthcacheP13nTestStubVerifyer::once());
$render = $this->stubObserver
->method($this->fragmentRenderer, 'render')
->expect(AuthcacheP13nTestStubVerifyer::never());
// Run builder.
$input = array(
'a' => array(
'some_key' => 'missing',
),
);
try {
$builder
->build($input, array());
$this
->fail('AuthcacheP13nFragmentBuilder should throw an AuthcacheP13nRequestNotFound when loading fails');
} catch (AuthcacheP13nRequestNotFound $e) {
unset($e);
$this
->pass('AuthcacheP13nFragmentBuilder should throw an AuthcacheP13nRequestNotFound when loading fails');
}
// Verify stub.
$this
->assert($load
->verify($message), $message);
$this
->assert($render
->verify($message), $message);
}
/**
* Test request with access checker.
*/
public function testFragmentBuilderAccessChecker() {
global $user;
$orig_user = $user;
$fake_user = (object) array(
'uid' => 42,
'mail' => 'fake@example.com',
'name' => 'fake',
);
$context = array(
'some' => 'context',
);
// Setup expectations.
$check = $this->stubObserver
->method($this->fragmentAccess, 'check', TRUE)
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args(array(
$fake_user,
'some_key',
'some_subject',
$context,
)));
$render = $this->stubObserver
->method($this->fragmentRenderer, 'render', 'rendered')
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args(array(
'some_key',
'some_subject',
$context,
)));
// Run builder.
$user = $fake_user;
$input = array(
'a' => array(
'some_key' => 'some_subject',
),
);
$builder = new AuthcacheP13nFragmentBuilder($this->fragmentRenderer, NULL, NULL, $this->fragmentAccess);
$result = $builder
->build($input, $context);
$user = $orig_user;
// Verify stub.
$this
->assertEqual('rendered', $result);
$this
->assert($check
->verify($message), $message);
$this
->assert($render
->verify($message), $message);
// Setup expectations.
$check = $this->stubObserver
->method($this->fragmentAccess, 'check', FALSE)
->expect(AuthcacheP13nTestStubVerifyer::once())
->expect(AuthcacheP13nTestStubVerifyer::args(array(
$fake_user,
'some_key',
'some_subject',
$context,
)));
$render = $this->stubObserver
->method($this->fragmentRenderer, 'render')
->expect(AuthcacheP13nTestStubVerifyer::never());
// Run builder.
$user = $fake_user;
$input = array(
'a' => array(
'some_key' => 'some_subject',
),
);
$builder = new AuthcacheP13nFragmentBuilder($this->fragmentRenderer, NULL, NULL, $this->fragmentAccess);
try {
$builder
->build($input, $context);
$this
->fail('AuthcacheP13nFragmentBuilder should throw an AuthcacheP13nRequestAccessDenied when access check fails');
} catch (AuthcacheP13nRequestAccessDenied $e) {
unset($e);
$this
->pass('AuthcacheP13nFragmentBuilder should throw an AuthcacheP13nRequestAccessDenied when access check fails');
}
$user = $orig_user;
// Verify stub.
$this
->assert($check
->verify($message), $message);
$this
->assert($render
->verify($message), $message);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AuthcacheP13nTestFragmentBuilder:: |
protected | property | ||
AuthcacheP13nTestFragmentBuilder:: |
protected | property | ||
AuthcacheP13nTestFragmentBuilder:: |
protected | property | ||
AuthcacheP13nTestFragmentBuilder:: |
protected | property | ||
AuthcacheP13nTestFragmentBuilder:: |
protected | property | ||
AuthcacheP13nTestFragmentBuilder:: |
public static | function | ||
AuthcacheP13nTestFragmentBuilder:: |
public | function |
Sets up unit test environment. Overrides DrupalUnitTestCase:: |
|
AuthcacheP13nTestFragmentBuilder:: |
public | function | Tests fragment request. | |
AuthcacheP13nTestFragmentBuilder:: |
public | function | Test request with access checker. | |
AuthcacheP13nTestFragmentBuilder:: |
public | function | Test request with loader. | |
AuthcacheP13nTestFragmentBuilder:: |
public | function | Test request with validator. | |
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:: |