class SystemPageRedirectTest in Rules 8.3
@coversDefaultClass \Drupal\rules\Plugin\RulesAction\SystemPageRedirect @group RulesAction
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\rules\Unit\Integration\RulesIntegrationTestBase
- class \Drupal\Tests\rules\Unit\Integration\RulesAction\SystemPageRedirectTest
- class \Drupal\Tests\rules\Unit\Integration\RulesIntegrationTestBase
Expanded class hierarchy of SystemPageRedirectTest
File
- tests/
src/ Unit/ Integration/ RulesAction/ SystemPageRedirectTest.php, line 17
Namespace
Drupal\Tests\rules\Unit\Integration\RulesActionView source
class SystemPageRedirectTest extends RulesIntegrationTestBase {
/**
* A mocked Rules logger.channel.rules_debug service.
*
* @var \Drupal\Core\Logger\LoggerChannelInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected $logger;
/**
* The mocked request stack service.
*
* @var \Symfony\Component\HttpFoundation\RequestStack|\Prophecy\Prophecy\ProphecyInterface
*/
protected $requestStack;
/**
* The mocked current path stack service.
*
* @var \Drupal\Core\Path\CurrentPathStack|\Prophecy\Prophecy\ProphecyInterface
*/
protected $currentPathStack;
/**
* A mocked request.
*
* @var \Symfony\Component\HttpFoundation\Request|\Prophecy\Prophecy\ProphecyInterface
*/
protected $currentRequest;
/**
* A mocked parameter bag.
*
* @var \Symfony\Component\HttpFoundation\ParameterBag|\Prophecy\Prophecy\ProphecyInterface
*/
protected $parameterBag;
/**
* The action to be tested.
*
* @var \Drupal\rules\Plugin\RulesAction\SystemPageRedirect
*/
protected $action;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Mock the Rules debug logger service, make it return our mocked logger,
// and register it in the container.
$this->logger = $this
->prophesize(LoggerChannelInterface::class);
$this->container
->set('logger.channel.rules_debug', $this->logger
->reveal());
// Mock a parameter bag.
$this->parameterBag = $this
->prophesize(ParameterBag::class);
// Mock a request, and set our mocked parameter bag as it attributes
// property.
$this->currentRequest = $this
->prophesize(Request::class);
$this->currentRequest->attributes = $this->parameterBag
->reveal();
// Mock the request stack, make it return our mocked request when the
// current request is requested, and register it in the container.
$this->requestStack = $this
->prophesize(RequestStack::class);
$this->requestStack
->getCurrentRequest()
->willReturn($this->currentRequest);
$this->container
->set('request_stack', $this->requestStack
->reveal());
// Mock the current path stack.
$this->currentPathStack = $this
->prophesize(CurrentPathStack::class);
$this->container
->set('path.current', $this->currentPathStack
->reveal());
// Instantiate the redirect action.
$this->action = $this->actionManager
->createInstance('rules_page_redirect');
}
/**
* Tests redirection.
*
* @covers ::execute
*/
public function testRedirect() {
$this->currentPathStack
->getPath()
->willReturn('some/random/test/path');
$this->action
->setContextValue('url', '/test/url');
$this->action
->execute();
$this->parameterBag
->set('_rules_redirect_action_url', '/test/url')
->shouldHaveBeenCalled();
}
/**
* Tests unsuccessful redirection due to ongoing batch process.
*
* @covers ::execute
*/
public function testRedirectBatch() {
$this->currentPathStack
->getPath()
->willReturn('some/random/test/path');
batch_set('Test batch!');
$this->action
->setContextValue('url', '/test/url');
$this->action
->execute();
$this->logger
->warning('Skipped page redirect during batch processing.')
->shouldHaveBeenCalled();
}
/**
* Tests unsuccessful redirection due to rules admin page location.
*
* @covers ::execute
*/
public function testRedirectRulesAdminPage() {
$this->currentPathStack
->getPath()
->willReturn('admin/config/workflow/rules');
$this->action
->setContextValue('url', '/test/url');
$this->action
->execute();
$this->logger
->warning('Skipped page redirect on a rules admin page.')
->shouldHaveBeenCalled();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
RulesIntegrationTestBase:: |
protected | property | ||
RulesIntegrationTestBase:: |
protected | property | ||
RulesIntegrationTestBase:: |
protected | property | The class resolver mock for the typed data manager. | |
RulesIntegrationTestBase:: |
protected | property | ||
RulesIntegrationTestBase:: |
protected | property | The Drupal service container. | |
RulesIntegrationTestBase:: |
protected | property | The data fetcher service. | |
RulesIntegrationTestBase:: |
protected | property | The data filter manager. | |
RulesIntegrationTestBase:: |
protected | property | Array object keyed with module names and TRUE as value. | |
RulesIntegrationTestBase:: |
protected | property | ||
RulesIntegrationTestBase:: |
protected | property | ||
RulesIntegrationTestBase:: |
protected | property | ||
RulesIntegrationTestBase:: |
protected | property | The messenger service. | |
RulesIntegrationTestBase:: |
protected | property | ||
RulesIntegrationTestBase:: |
protected | property | All setup'ed namespaces. | |
RulesIntegrationTestBase:: |
protected | property | The placeholder resolver service. | |
RulesIntegrationTestBase:: |
protected | property | ||
RulesIntegrationTestBase:: |
protected | property | ||
RulesIntegrationTestBase:: |
protected | property | ||
RulesIntegrationTestBase:: |
protected | function | Determines the path to a module's class files. | |
RulesIntegrationTestBase:: |
protected | function | Fakes the enabling of a module and adds its namespace for plugin loading. | |
RulesIntegrationTestBase:: |
protected | function | Returns a typed data object. | |
RulesIntegrationTestBase:: |
protected | function | Helper method to mock irrelevant cache methods on entities. | |
SystemPageRedirectTest:: |
protected | property | The action to be tested. | |
SystemPageRedirectTest:: |
protected | property | The mocked current path stack service. | |
SystemPageRedirectTest:: |
protected | property | A mocked request. | |
SystemPageRedirectTest:: |
protected | property |
A mocked Rules logger.channel.rules_debug service. Overrides RulesIntegrationTestBase:: |
|
SystemPageRedirectTest:: |
protected | property | A mocked parameter bag. | |
SystemPageRedirectTest:: |
protected | property | The mocked request stack service. | |
SystemPageRedirectTest:: |
protected | function |
Overrides RulesIntegrationTestBase:: |
|
SystemPageRedirectTest:: |
public | function | Tests redirection. | |
SystemPageRedirectTest:: |
public | function | Tests unsuccessful redirection due to ongoing batch process. | |
SystemPageRedirectTest:: |
public | function | Tests unsuccessful redirection due to rules admin page location. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |