Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions system/HTTP/CLIRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace CodeIgniter\HTTP;

use Config\App;
use Locale;
use RuntimeException;

/**
Expand Down Expand Up @@ -214,4 +215,12 @@ public function isCLI(): bool
{
return true;
}

/**
* Gets the current locale.
*/
public function getLocale(): string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to put this on Request (or RequestTrait) so any request has it? IncomingRequest can still use it's negotiable version as an extension.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IncommingRequest has locale, but I don't think CLIRequest should have locale.

Okay, I was wrong. This method should not be added.

{
return Locale::getDefault();
}
}
17 changes: 12 additions & 5 deletions tests/system/CommonFunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ final class CommonFunctionsTest extends CIUnitTestCase
protected function setUp(): void
{
unset($_ENV['foo'], $_SERVER['foo']);
Services::reset();
$this->resetServices();

parent::setUp();
}
Expand Down Expand Up @@ -593,8 +593,6 @@ public function testTraceWithCSP()

public function testCspStyleNonce()
{
$this->resetServices();

$config = config('App');
$config->CSPEnabled = true;

Expand All @@ -603,11 +601,20 @@ public function testCspStyleNonce()

public function testCspScriptNonce()
{
$this->resetServices();

$config = config('App');
$config->CSPEnabled = true;

$this->assertStringStartsWith('nonce="', csp_script_nonce());
}

public function testLangOnCLI()
{
Services::createRequest(new App(), true);

$message = lang('CLI.generator.fileCreate', ['TestController.php']);

$this->assertSame('File created: TestController.php', $message);

$this->resetServices();
}
}