You are here

class SqlRedirectNotFoundStorageTest in Redirect 8

Tests that overly long paths aren't logged.

@group redirect_404

Hierarchy

Expanded class hierarchy of SqlRedirectNotFoundStorageTest

File

modules/redirect_404/tests/src/Unit/SqlRedirectNotFoundStorageTest.php, line 15

Namespace

Drupal\Tests\redirect_404\Unit
View 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

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
SqlRedirectNotFoundStorageTest::$configFactory protected property Mock config factory.
SqlRedirectNotFoundStorageTest::$database protected property Mock database connection.
SqlRedirectNotFoundStorageTest::setUp protected function Overrides UnitTestCase::setUp
SqlRedirectNotFoundStorageTest::testInvalidUtf8Path public function Tests that invalid UTF-8 paths are not stored in the database.
SqlRedirectNotFoundStorageTest::testLongPath public function Tests that long paths aren't stored in the database.
SqlRedirectNotFoundStorageTest::testPurgeOldRequests public function Tests that all logs are kept if row limit config is "All".
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.