Fixes for tests

This commit is contained in:
David Bomba 2024-10-28 08:01:21 +11:00
parent ed69e36521
commit 3cb71f7ef9
5 changed files with 269 additions and 241 deletions

View File

@ -1222,4 +1222,21 @@ class BaseController extends Controller
{
return response()->json(['message' => 'Upgrade to a paid plan for this feature.'], 403);
}
/**
* GetEncodedFilename
*
* @param string $filename
* @return string
*/
public function getEncodedFilename(string $filename): string
{
$ascii_filename = str_replace(['%', '/', '\\'], '', $filename);
$ascii_filename = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $ascii_filename);
$encoded_filename = rawurlencode($filename);
return "filename=\"$ascii_filename\"; filename*=UTF-8''$encoded_filename";
}
}

View File

@ -815,6 +815,7 @@ class InvoiceController extends BaseController
*/
public function downloadPdf($invitation_key)
{
$invitation = $this->invoice_repo->getInvitationByKey($invitation_key);
if (! $invitation) {
@ -834,10 +835,11 @@ class InvoiceController extends BaseController
if (request()->input('inline') == 'true') {
$headers = array_merge($headers, ['Content-Disposition' => 'inline']);
}
return response()->streamDownload(function () use ($file) {
echo $file;
}, $file_name, $headers);
}
/**

View File

@ -261,49 +261,49 @@ class BaseModel extends Model
return ctrans("texts.e_invoice"). "_" . $this->numberFormatter().'.'.$extension;
}
public function numberFormatter()
{
$number = strlen($this->number) >= 1 ? $this->translate_entity() . "_" . $this->number : class_basename($this) . "_" . Str::random(5);
// Remove control characters
$formatted_number = preg_replace('/[\x00-\x1F\x7F]/u', '', $number);
// Replace slash, backslash, and null byte with underscore
$formatted_number = str_replace(['/', '\\', "\0"], '_', $formatted_number);
// Remove any other characters that are invalid in most filesystems
$formatted_number = str_replace(['<', '>', ':', '"', '|', '?', '*'], '', $formatted_number);
// Replace multiple spaces or underscores with a single underscore
$formatted_number = preg_replace('/[\s_]+/', '_', $formatted_number);
// Trim underscores from start and end
$formatted_number = trim($formatted_number, '_');
// Ensure the filename is not empty
if (empty($formatted_number)) {
$formatted_number = 'file_' . Str::random(5);
}
// Limit the length of the filename (adjust as needed)
$formatted_number = mb_substr($formatted_number, 0, 255);
return $formatted_number;
}
// public function numberFormatter()
// {
// $number = strlen($this->number) >= 1 ? $this->translate_entity() . "_" . $this->number : class_basename($this) . "_" . Str::random(5);
// $formatted_number = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $number);
// // Remove control characters
// $formatted_number = preg_replace('/[\x00-\x1F\x7F]/u', '', $number);
// $formatted_number = mb_ereg_replace("([\.]{2,})", '', $formatted_number);
// // Replace slash, backslash, and null byte with underscore
// $formatted_number = str_replace(['/', '\\', "\0"], '_', $formatted_number);
// $formatted_number = preg_replace('/\s+/', '_', $formatted_number);
// // Remove any other characters that are invalid in most filesystems
// $formatted_number = str_replace(['<', '>', ':', '"', '|', '?', '*'], '', $formatted_number);
// return \Illuminate\Support\Str::ascii($formatted_number);
// // Replace multiple spaces or underscores with a single underscore
// $formatted_number = preg_replace('/[\s_]+/', '_', $formatted_number);
// // Trim underscores from start and end
// $formatted_number = trim($formatted_number, '_');
// // Ensure the filename is not empty
// if (empty($formatted_number)) {
// $formatted_number = 'file_' . Str::random(5);
// }
// // Limit the length of the filename (adjust as needed)
// $formatted_number = mb_substr($formatted_number, 0, 255);
// return $formatted_number;
// }
public function numberFormatter()
{
$number = strlen($this->number) >= 1 ? $this->translate_entity() . "_" . $this->number : class_basename($this) . "_" . Str::random(5);
$formatted_number = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $number);
$formatted_number = mb_ereg_replace("([\.]{2,})", '', $formatted_number);
$formatted_number = preg_replace('/\s+/', '_', $formatted_number);
return \Illuminate\Support\Str::ascii($formatted_number);
}
public function translate_entity()
{
return ctrans('texts.item');

View File

@ -57,7 +57,7 @@ class Klarna implements LivewireMethodInterface
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, $request->all());
$this->stripe->payment_hash->save();
if (in_array($request->redirect_status, ['succeeded','pending'])) {
if (in_array($request->redirect_status, ['succeeded', 'pending'])) {
return $this->processSuccessfulPayment($request->payment_intent);
}

419
composer.lock generated

File diff suppressed because it is too large Load Diff