class SqlRedirectNotFoundStorageTest in Redirect 8
Tests that overly long paths aren't logged.
@group redirect_404
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\redirect_404\Unit\SqlRedirectNotFoundStorageTest
Expanded class hierarchy of SqlRedirectNotFoundStorageTest
File
- modules/
redirect_404/ tests/ src/ Unit/ SqlRedirectNotFoundStorageTest.php, line 15
Namespace
Drupal\Tests\redirect_404\UnitView source
class SqlRedirectNotFoundStorageTest extends UnitTestCase {
/**
* Mock database connection.
*
* @var \Drupal\Core\Database\Connection|\PHPUnit_Framework_MockObject_MockObject
*/
protected $database;
/**
* Mock config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $configFactory;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->database = $this
->getMockBuilder(Connection::class)
->disableOriginalConstructor()
->getMock();
}
/**
* Tests that long paths aren't stored in the database.
*/
public function testLongPath() {
$this->database
->expects($this
->never())
->method('merge');
$storage = new SqlRedirectNotFoundStorage($this->database, $this
->getConfigFactoryStub());
$storage
->logRequest($this
->randomMachineName(SqlRedirectNotFoundStorage::MAX_PATH_LENGTH + 1), LanguageInterface::LANGCODE_DEFAULT);
}
/**
* Tests that invalid UTF-8 paths are not stored in the database.
*/
public function testInvalidUtf8Path() {
$this->database
->expects($this
->never())
->method('merge');
$storage = new SqlRedirectNotFoundStorage($this->database, $this
->getConfigFactoryStub());
$storage
->logRequest("", LanguageInterface::LANGCODE_DEFAULT);
}
/**
* Tests that all logs are kept if row limit config is "All".
*/
public function testPurgeOldRequests() {
$this->configFactory = $this
->getConfigFactoryStub([
'redirect_404.settings' => [
'row_limit' => 0,
],
]);
$storage = new SqlRedirectNotFoundStorage($this->database, $this->configFactory);
$storage
->purgeOldRequests();
$this->database
->expects($this
->never())
->method('select');
}
}
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. | |
SqlRedirectNotFoundStorageTest:: |
protected | property | Mock config factory. | |
SqlRedirectNotFoundStorageTest:: |
protected | property | Mock database connection. | |
SqlRedirectNotFoundStorageTest:: |
protected | function |
Overrides UnitTestCase:: |
|
SqlRedirectNotFoundStorageTest:: |
public | function | Tests that invalid UTF-8 paths are not stored in the database. | |
SqlRedirectNotFoundStorageTest:: |
public | function | Tests that long paths aren't stored in the database. | |
SqlRedirectNotFoundStorageTest:: |
public | function | Tests that all logs are kept if row limit config is "All". | |
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. |