You are here

public function LoggerChannelTest::providerTestLog in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php \Drupal\Tests\Core\Logger\LoggerChannelTest::providerTestLog()

Data provider for self::testLog().

File

core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php, line 103
Contains \Drupal\Tests\Core\Logger\LoggerChannelTest.

Class

LoggerChannelTest
@coversDefaultClass \Drupal\Core\Logger\LoggerChannel @group Logger

Namespace

Drupal\Tests\Core\Logger

Code

public function providerTestLog() {
  $account_mock = $this
    ->createMock('Drupal\\Core\\Session\\AccountInterface');
  $account_mock
    ->expects($this
    ->any())
    ->method('id')
    ->will($this
    ->returnValue(1));
  $request_mock = $this
    ->getMockBuilder('Symfony\\Component\\HttpFoundation\\Request')
    ->setMethods([
    'getClientIp',
  ])
    ->getMock();
  $request_mock
    ->expects($this
    ->any())
    ->method('getClientIp')
    ->will($this
    ->returnValue('127.0.0.1'));
  $request_mock->headers = $this
    ->createMock('Symfony\\Component\\HttpFoundation\\ParameterBag');

  // No request or account.
  $cases[] = [
    function ($context) {
      return $context['channel'] == 'test' && empty($context['uid']) && empty($context['ip']);
    },
  ];

  // With account but not request. Since the request is not available the
  // current user should not be used.
  $cases[] = [
    function ($context) {
      return $context['uid'] === 0 && empty($context['ip']);
    },
    NULL,
    $account_mock,
  ];

  // With request but not account.
  $cases[] = [
    function ($context) {
      return $context['ip'] === '127.0.0.1' && empty($context['uid']);
    },
    $request_mock,
  ];

  // Both request and account.
  $cases[] = [
    function ($context) {
      return $context['ip'] === '127.0.0.1' && $context['uid'] === 1;
    },
    $request_mock,
    $account_mock,
  ];
  return $cases;
}