mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Part 2 of expanded common function testing
This commit is contained in:
parent
fa64b01f56
commit
94bce7c873
@ -440,8 +440,10 @@ if ( ! function_exists('log_message'))
|
||||
return $logger->log($level, $message, $context);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
return Services::logger(true)
|
||||
->log($level, $message, $context);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
}
|
||||
@ -668,6 +670,9 @@ if ( ! function_exists('force_https'))
|
||||
* Defaults to 1 year.
|
||||
* @param RequestInterface $request
|
||||
* @param ResponseInterface $response
|
||||
*
|
||||
* Not testable, as it will exit!
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
function force_https(int $duration = 31536000, RequestInterface $request = null, ResponseInterface $response = null)
|
||||
{
|
||||
@ -837,6 +842,8 @@ if ( ! function_exists('is_really_writable'))
|
||||
* @param string $file
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @codeCoverageIgnore Not practical to test, as travis runs on linux
|
||||
*/
|
||||
function is_really_writable($file)
|
||||
{
|
||||
@ -931,6 +938,8 @@ if ( ! function_exists('function_usable'))
|
||||
* @param string $function_name Function to check for
|
||||
* @return bool TRUE if the function exists and is safe to call,
|
||||
* FALSE otherwise.
|
||||
*
|
||||
* @codeCoverageIgnore This is too exotic
|
||||
*/
|
||||
function function_usable($function_name)
|
||||
{
|
||||
@ -959,6 +968,8 @@ if (! function_exists('dd'))
|
||||
* Prints a Kint debug report and exits.
|
||||
*
|
||||
* @param array ...$vars
|
||||
*
|
||||
* @codeCoverageIgnore Can't be tested ... exits
|
||||
*/
|
||||
function dd(...$vars)
|
||||
{
|
||||
|
@ -1,7 +1,15 @@
|
||||
<?php
|
||||
|
||||
use Tests\Support\Autoloader\MockFileLocator;
|
||||
use Config\App;
|
||||
use Config\Autoload;
|
||||
use CodeIgniter\Config\Services;
|
||||
use CodeIgniter\Router\RouteCollection;
|
||||
use CodeIgniter\HTTP\RequestResponse;
|
||||
use CodeIgniter\HTTP\RedirectResponse;
|
||||
use CodeIgniter\HTTP\URI;
|
||||
use CodeIgniter\HTTP\UserAgent;
|
||||
use Tests\Support\Autoloader\MockFileLocator;
|
||||
use Tests\Support\HTTP\MockIncomingRequest;
|
||||
|
||||
/**
|
||||
* @backupGlobals enabled
|
||||
@ -102,6 +110,11 @@ class CommomFunctionsTest extends \CIUnitTestCase
|
||||
$this->assertInstanceOf(\CodeIgniter\HTTP\RedirectResponse::class, redirect('base'));
|
||||
}
|
||||
|
||||
public function testRedirectDefault()
|
||||
{
|
||||
$this->assertInstanceOf(\CodeIgniter\HTTP\RedirectResponse::class, redirect());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public function testView()
|
||||
@ -216,4 +229,50 @@ class CommomFunctionsTest extends \CIUnitTestCase
|
||||
$this->assertContains('<input type="hidden" ', csrf_field());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public function testOldInput()
|
||||
{
|
||||
// setup from RedirectResponseTest...
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
|
||||
$this->config = new App();
|
||||
$this->config->baseURL = 'http://example.com';
|
||||
|
||||
$this->routes = new RouteCollection(new MockFileLocator(new Autoload()));
|
||||
Services::injectMock('routes', $this->routes);
|
||||
|
||||
$this->request = new MockIncomingRequest($this->config, new URI('http://example.com'), null, new UserAgent());
|
||||
Services::injectMock('request', $this->request);
|
||||
|
||||
// setup & ask for a redirect...
|
||||
$_SESSION = [];
|
||||
$_GET = ['foo' => 'bar'];
|
||||
$_POST = ['bar' => 'baz', 'zibble' => serialize('fritz')];
|
||||
|
||||
$response = new RedirectResponse(new App());
|
||||
$returned = $response->withInput();
|
||||
|
||||
$this->assertEquals('bar', old('foo')); // regular parameter
|
||||
$this->assertEquals('doo', old('yabba dabba', 'doo')); // non-existing parameter
|
||||
$this->assertEquals('fritz', old('zibble')); // serialized parameter
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public function testReallyWritable()
|
||||
{
|
||||
// cannot test fully on *nix
|
||||
$this->assertTrue(is_really_writable(WRITEPATH));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public function testSlashItem()
|
||||
{
|
||||
$this->assertEquals('/', slash_item('cookiePath')); // slash already there
|
||||
$this->assertEquals('', slash_item('cookieDomain')); // empty, so untouched
|
||||
$this->assertEquals('en/', slash_item('defaultLocale')); // slash appended
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user