gitignore, product photos fixture, copy/delete in base controller test setUp/tearDown
CI / testsuite (mysql, 8.1, ) (push) Failing after 6m9s Details
CI / testsuite (mysql, 8.4, ) (push) Failing after 5m39s Details
CI / testsuite (sqlite, 8.1, prefer-lowest) (push) Failing after 6m8s Details
CI / Coding Standard & Static Analysis (push) Failing after 5m57s Details

This commit is contained in:
Brandon Shipley 2025-08-19 01:13:13 -07:00
parent 493068cc1c
commit 8bdb329828
Signed by: bmfs
GPG Key ID: 14E38571D8BB0DE4
6 changed files with 43 additions and 11 deletions

2
.gitignore vendored
View File

@ -7,4 +7,4 @@
/vendor/
/.idea/
tmp
tests/test_app/webroot/images/products
tests/test_app/webroot/images/products/

View File

@ -101,10 +101,11 @@ class ProductPhotosController extends AppController
$this->Flash->error(__('The product photo could not be saved. Please, try again.'));
}
$products = $productPhotosTable->Products->find('list', limit: 200)->all();
$this->set(compact('productPhoto', 'products'));
}
d /**
/**
* Edit method
*
* @param string|null $id Product Photo id.

View File

@ -23,7 +23,7 @@ class ProductPhotosFixture extends TestFixture
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'product_sku_id' => null,
'photo_dir' => '/products/cfc98a9a-29b2-44c8-b587-8156adc05317/',
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f58.jpg',
'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f58.png',
'primary_photo' => 1,
'photo_position' => 100,
'enabled' => 1,

View File

@ -2,8 +2,12 @@
namespace CakeProducts\Test\TestCase\Controller;
use Cake\Core\Configure;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use FilesystemIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
class BaseControllerTest extends TestCase
{
@ -22,4 +26,38 @@ class BaseControllerTest extends TestCase
{
$this->assertEquals(1, 1);
}
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$toCopy = PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS . 'images' . DS . '2c386086-f4c5-4093-bea5-ee9c29479f58.png';
$productsFolder = PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS .
'images' . DS . 'products' . DS . 'cfc98a9a-29b2-44c8-b587-8156adc05317';
$newName = $productsFolder . DS . '2c386086-f4c5-4093-bea5-ee9c29479f58.png';
if (file_exists($toCopy)) {
if (!file_exists($productsFolder)) {
mkdir($productsFolder);
}
copy($toCopy, $newName);
}
}
protected function tearDown(): void
{
parent::tearDown(); // TODO: Change the autogenerated stub
$path = Configure::readOrFail('CakeProducts.photos.directory');
if (file_exists($path)) {
$di = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS);
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
foreach ( $ri as $file ) {
$file->isDir() ? rmdir($file->getRealPath()) : unlink($file->getRealPath());
}
}
}
}

View File

@ -58,14 +58,7 @@ class ProductPhotosControllerTest extends BaseControllerTest
protected function tearDown(): void
{
unset($this->ProductPhotos);
$path = Configure::readOrFail('CakeProducts.photos.directory');
if (file_exists($path)) {
$di = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS);
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
foreach ( $ri as $file ) {
$file->isDir() ? rmdir($file->getRealPath()) : unlink($file->getRealPath());
}
}
parent::tearDown();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 943 B