upload test passing + file not getting deleted every time - well it is but we now use a copy lol
CI / testsuite (mysql, 8.1, ) (push) Has been cancelled Details
CI / testsuite (mysql, 8.4, ) (push) Has been cancelled Details
CI / testsuite (pgsql, 8.1, ) (push) Has been cancelled Details
CI / testsuite (pgsql, 8.4, ) (push) Has been cancelled Details
CI / testsuite (sqlite, 8.1, ) (push) Has been cancelled Details
CI / testsuite (sqlite, 8.1, prefer-lowest) (push) Has been cancelled Details
CI / testsuite (sqlite, 8.4, ) (push) Has been cancelled Details
CI / Coding Standard & Static Analysis (push) Has been cancelled Details

This commit is contained in:
Brandon Shipley 2025-08-10 02:50:22 -07:00
parent a1012b4054
commit 3a47f09e8c
Signed by: bmfs
GPG Key ID: 14E38571D8BB0DE4
4 changed files with 19 additions and 2 deletions

View File

@ -56,6 +56,13 @@ class ProductPhotosController extends AppController
$productPhotosTable = $this->getTable();
$productPhoto = $productPhotosTable->newEmptyEntity();
if ($this->request->is('post')) {
if (!$this->request->getData('photo')) {
$this->Flash->error('Photo is required. Nothing was uploaded. Please try again.');
$products = $productPhotosTable->Products->find('list', limit: 200)->all();
$this->set(compact('productPhoto', 'products'));
return;
}
$uuid = Text::uuid();
$postData = $this->request->getData();
$postData['id'] = $uuid;

View File

@ -162,8 +162,16 @@ class ProductPhotosControllerTest extends BaseControllerTest
'controller' => 'ProductPhotos',
'action' => 'add',
];
$file = Configure::readOrFail('App.paths.testWebroot') . 'images' . DS . 'cake_icon.png';
$toUseFile = Configure::readOrFail('App.paths.testWebroot') . 'images' . DS . 'cake_icon_copy.png';
if (!file_exists($file)) {
$this->fail('Test image did not exist');
}
if (!copy($file, $toUseFile)) {
$this->fail('Failed to copy test image');
}
$image = new UploadedFile(
Configure::readOrFail('App.paths.webroot') . 'images' . DS . 'cake_icon.png', // stream or path to file representing the temp file
$toUseFile, // stream or path to file representing the temp file
12345, // the filesize in bytes
UPLOAD_ERR_OK, // the upload/error status
'cake_icon.png', // the filename as sent by the client
@ -209,7 +217,8 @@ class ProductPhotosControllerTest extends BaseControllerTest
'controller' => 'ProductPhotos',
'action' => 'add',
];
$data = [];
$data = [
];
$this->post($url, $data);
$this->assertResponseCode(200);

View File

@ -48,6 +48,7 @@ Configure::write('App', [
'namespace' => 'TestApp',
'encoding' => 'UTF-8',
'paths' => [
'testWebroot' => PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS,
'webroot' => PLUGIN_ROOT . DS . 'webroot' . DS,
'templates' => [
PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'templates' . DS,

View File

Before

Width:  |  Height:  |  Size: 943 B

After

Width:  |  Height:  |  Size: 943 B