Skip to content

Commit

Permalink
Merge pull request #1813 from jim-parry/testing24
Browse files Browse the repository at this point in the history
Fix: Model::save needs to call insert properly
  • Loading branch information
jim-parry authored Mar 11, 2019
2 parents e4482b7 + d233bc6 commit bab5281
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 36 deletions.
2 changes: 1 addition & 1 deletion system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ protected function forceSecureAccess($duration = 31536000)
*
* @throws \Exception
*
* @return bool|\CodeIgniter\HTTP\ResponseInterface
* @return boolean|\CodeIgniter\HTTP\ResponseInterface
*/
public function displayCache($config)
{
Expand Down
5 changes: 3 additions & 2 deletions system/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* @since Version 3.0.0
* @filesource
*/

use CodeIgniter\Config\Services;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
Expand Down Expand Up @@ -179,8 +180,8 @@ protected function loadHelpers()
* A shortcut to performing validation on input data. If validation
* is not successful, a $errors property will be set on this class.
*
* @param array|string $rules
* @param array $messages An array of custom error messages
* @param array|string $rules
* @param array $messages An array of custom error messages
*
* @return boolean
*/
Expand Down
2 changes: 1 addition & 1 deletion system/Debug/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ protected function render(\Throwable $exception, int $statusCode)
if (empty($path))
{
$paths = new Paths();
$path = $paths->viewDirectory . '/errors/';
$path = $paths->viewDirectory . '/errors/';
}

$path = is_cli()
Expand Down
9 changes: 9 additions & 0 deletions system/Filters/CSRF.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
* @link https://codeigniter.com
* @since Version 3.0.0
* @filesource
*
* This filter is not intended to be used from the command line.
*
* @codeCoverageIgnore
*/

use CodeIgniter\Filters\FilterInterface;
Expand All @@ -42,6 +46,11 @@
use CodeIgniter\Security\Exceptions\SecurityException;
use Config\Services;

/**
* This filter is not intended to be used from the command line.
*
* @codeCoverageIgnore
*/
class CSRF implements FilterInterface
{
/**
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/Files/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public function getErrorString()
UPLOAD_ERR_NO_FILE => lang('HTTP.uploadErrNoFile'),
UPLOAD_ERR_CANT_WRITE => lang('HTTP.uploadErrCantWrite'),
UPLOAD_ERR_NO_TMP_DIR => lang('HTTP.uploadErrNoTmpDir'),
UPLOAD_ERR_EXTENSION => lang('HTTP.uploadErrExtension')
UPLOAD_ERR_EXTENSION => lang('HTTP.uploadErrExtension'),
];

$error = is_null($this->error) ? UPLOAD_ERR_OK : $this->error;
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ public function fetchGlobal($method, $index = null, $filter = null, $flags = nul
}
}

if (!isset($value))
if (! isset($value))
{
$value = $this->globals[$method][$index] ?? null;
}
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/form_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function form_open(string $action = '', $attributes = [], array $hidden = []): s
$action = site_url($action);
}

if(is_array($attributes) && array_key_exists('csrf_id', $attributes))
if (is_array($attributes) && array_key_exists('csrf_id', $attributes))
{
$csrfId = $attributes['csrf_id'];
unset($attributes['csrf_id']);
Expand Down
4 changes: 2 additions & 2 deletions system/Helpers/text_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ function convert_accented_characters(string $str): string
* Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor
* will URLs.
*
* @param string $str the text string
* @param string $str the text string
* @param integer $charlim = 76 the number of characters to wrap at
*
* @return string
Expand Down Expand Up @@ -604,7 +604,7 @@ function ellipsize(string $str, int $max_length, $position = 1, string $ellipsis
*
* Removes slashes contained in a string or in an array
*
* @param mixed $str string or array
* @param mixed $str string or array
*
* @return mixed string or array
*/
Expand Down
20 changes: 10 additions & 10 deletions system/Language/en/HTTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@
'alreadyMoved' => 'The uploaded file has already been moved.',
'invalidFile' => 'The original file is not a valid file.',
'moveFailed' => 'Could not move file {0} to {1} ({2})',
'uploadErrOk' => 'The file uploaded with success.',
'uploadErrIniSize' => 'The file "%s" exceeds your upload_max_filesize ini directive.',
'uploadErrFormSize' => 'The file "%s" exceeds the upload limit defined in your form.',
'uploadErrPartial' => 'The file "%s" was only partially uploaded.',
'uploadErrNoFile' => 'No file was uploaded.',
'uploadErrCantWrite' => 'The file "%s" could not be written on disk.',
'uploadErrNoTmpDir' => 'File could not be uploaded: missing temporary directory.',
'uploadErrExtension' => 'File upload was stopped by a PHP extension.',
'uploadErrUnknown' => 'The file "%s" was not uploaded due to an unknown error.'

'uploadErrOk' => 'The file uploaded with success.',
'uploadErrIniSize' => 'The file "%s" exceeds your upload_max_filesize ini directive.',
'uploadErrFormSize' => 'The file "%s" exceeds the upload limit defined in your form.',
'uploadErrPartial' => 'The file "%s" was only partially uploaded.',
'uploadErrNoFile' => 'No file was uploaded.',
'uploadErrCantWrite' => 'The file "%s" could not be written on disk.',
'uploadErrNoTmpDir' => 'File could not be uploaded: missing temporary directory.',
'uploadErrExtension' => 'File upload was stopped by a PHP extension.',
'uploadErrUnknown' => 'The file "%s" was not uploaded due to an unknown error.',
];
5 changes: 5 additions & 0 deletions system/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,11 @@ public function save($data): bool
else
{
$response = $this->insert($data, false);
// call insert directly if you want the ID or the record object
if ($response !== false)
{
$response = true;
}
}

return $response;
Expand Down
2 changes: 1 addition & 1 deletion system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class RouteCollection implements RouteCollectionInterface
/**
* Constructor
*
* @param FileLocator $locator
* @param FileLocator $locator
* @param \Config\Modules $moduleConfig
*/
public function __construct(FileLocator $locator, $moduleConfig)
Expand Down
4 changes: 2 additions & 2 deletions system/Session/Handlers/MemcachedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public function __construct(BaseConfig $config, string $ipAddress)
{
$this->keyPrefix .= $this->ipAddress . ':';
}
if(!empty($this->keyPrefix))

if (! empty($this->keyPrefix))
{
ini_set('memcached.sess_prefix', $this->keyPrefix);
}
Expand Down
4 changes: 2 additions & 2 deletions system/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ protected function configure()
{
ini_set('session.gc_maxlifetime', (int) $this->sessionExpiration);
}
if(!empty($this->sessionSavePath))

if (! empty($this->sessionSavePath))
{
ini_set('session.save_path', $this->sessionSavePath);
}
Expand Down
17 changes: 5 additions & 12 deletions tests/system/Helpers/FormHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -811,56 +811,49 @@ public function testSetRadioDefault()
$this->assertEquals(' checked="checked"', set_radio('code', 'alpha', true));
$this->assertEquals('', set_radio('code', 'beta', false));
}



// ------------------------------------------------------------------------
public function testFormParseFormAttributesTrue()
{
$expected = 'readonly ';
$this->assertEquals($expected, parse_form_attributes(['readonly' => true], []));
}



// ------------------------------------------------------------------------
public function testFormParseFormAttributesFalse()
{
$expected = 'disabled ';
$this->assertEquals($expected, parse_form_attributes(['disabled' => false], []));
}


// ------------------------------------------------------------------------
public function testFormParseFormAttributesNull()
{
$expected = 'bar="" ';
$this->assertEquals($expected, parse_form_attributes(['bar' => null], []));
}



// ------------------------------------------------------------------------
public function testFormParseFormAttributesStringEmpty()
{
$expected = 'bar="" ';
$this->assertEquals($expected, parse_form_attributes(['bar' => ''], []));
}



// ------------------------------------------------------------------------
public function testFormParseFormAttributesStringFoo()
{
$expected = 'bar="foo" ';
$this->assertEquals($expected, parse_form_attributes(['bar' => 'foo'], []));
}


// ------------------------------------------------------------------------
public function testFormParseFormAttributesInt0()
{
$expected = 'ok="0" ';
$this->assertEquals($expected, parse_form_attributes(['ok' => 0], []));
}



// ------------------------------------------------------------------------
public function testFormParseFormAttributesInt1()
{
Expand Down

0 comments on commit bab5281

Please sign in to comment.