3 namespace Drupal\Tests\redirect_404\Unit;
5 use Drupal\Core\Database\Connection;
6 use Drupal\Core\Language\LanguageInterface;
7 use Drupal\redirect_404\SqlRedirectNotFoundStorage;
8 use Drupal\Tests\UnitTestCase;
11 * Tests that overly long paths aren't logged.
15 class SqlRedirectNotFoundStorageTest extends UnitTestCase {
18 * Mock database connection.
20 * @var \Drupal\Core\Database\Connection|\PHPUnit_Framework_MockObject_MockObject
25 * Mock config factory.
27 * @var \Drupal\Core\Config\ConfigFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
29 protected $configFactory;
34 protected function setUp() {
36 $this->database = $this->getMockBuilder(Connection::class)
37 ->disableOriginalConstructor()
42 * Tests that long paths aren't stored in the database.
44 public function testLongPath() {
45 $this->database->expects($this->never())
47 $storage = new SqlRedirectNotFoundStorage($this->database, $this->getConfigFactoryStub());
48 $storage->logRequest($this->randomMachineName(SqlRedirectNotFoundStorage::MAX_PATH_LENGTH + 1), LanguageInterface::LANGCODE_DEFAULT);
52 * Tests that invalid UTF-8 paths are not stored in the database.
54 public function testInvalidUtf8Path() {
55 $this->database->expects($this->never())
57 $storage = new SqlRedirectNotFoundStorage($this->database, $this->getConfigFactoryStub());
58 $storage->logRequest("Caf\xc3", LanguageInterface::LANGCODE_DEFAULT);
62 * Tests that all logs are kept if row limit config is "All".
64 public function testPurgeOldRequests() {
65 $this->configFactory = $this->getConfigFactoryStub(
67 'redirect_404.settings' => [
72 $storage = new SqlRedirectNotFoundStorage($this->database, $this->configFactory);
73 $storage->purgeOldRequests();
74 $this->database->expects($this->never())