gitignore, product photos fixture, copy/delete in base controller test setUp/tearDown

This commit is contained in:
2025-08-19 01:13:13 -07:00
parent 493068cc1c
commit 8bdb329828
6 changed files with 43 additions and 11 deletions

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());
}
}
}
}