You are here

public function LoggerChannelTest::providerTestLog in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 86
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
    ->getMock('Drupal\\Core\\Session\\AccountInterface');
  $account_mock
    ->expects($this
    ->exactly(2))
    ->method('id')
    ->will($this
    ->returnValue(1));
  $request_mock = $this
    ->getMock('Symfony\\Component\\HttpFoundation\\Request');
  $request_mock
    ->expects($this
    ->exactly(2))
    ->method('getClientIp')
    ->will($this
    ->returnValue('127.0.0.1'));
  $request_mock->headers = $this
    ->getMock('Symfony\\Component\\HttpFoundation\\ParameterBag');

  // No request or account.
  $cases[] = array(
    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[] = array(
    function ($context) {
      return $context['uid'] === 0 && empty($context['ip']);
    },
    NULL,
    $account_mock,
  );

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

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