gitignore, product photos fixture, copy/delete in base controller test setUp/tearDown
This commit is contained in:
parent
493068cc1c
commit
8bdb329828
|
@ -7,4 +7,4 @@
|
||||||
/vendor/
|
/vendor/
|
||||||
/.idea/
|
/.idea/
|
||||||
tmp
|
tmp
|
||||||
tests/test_app/webroot/images/products
|
tests/test_app/webroot/images/products/
|
||||||
|
|
|
@ -101,10 +101,11 @@ class ProductPhotosController extends AppController
|
||||||
$this->Flash->error(__('The product photo could not be saved. Please, try again.'));
|
$this->Flash->error(__('The product photo could not be saved. Please, try again.'));
|
||||||
}
|
}
|
||||||
$products = $productPhotosTable->Products->find('list', limit: 200)->all();
|
$products = $productPhotosTable->Products->find('list', limit: 200)->all();
|
||||||
|
|
||||||
$this->set(compact('productPhoto', 'products'));
|
$this->set(compact('productPhoto', 'products'));
|
||||||
}
|
}
|
||||||
|
|
||||||
d /**
|
/**
|
||||||
* Edit method
|
* Edit method
|
||||||
*
|
*
|
||||||
* @param string|null $id Product Photo id.
|
* @param string|null $id Product Photo id.
|
||||||
|
|
|
@ -23,7 +23,7 @@ class ProductPhotosFixture extends TestFixture
|
||||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||||
'product_sku_id' => null,
|
'product_sku_id' => null,
|
||||||
'photo_dir' => '/products/cfc98a9a-29b2-44c8-b587-8156adc05317/',
|
'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,
|
'primary_photo' => 1,
|
||||||
'photo_position' => 100,
|
'photo_position' => 100,
|
||||||
'enabled' => 1,
|
'enabled' => 1,
|
||||||
|
|
|
@ -2,8 +2,12 @@
|
||||||
|
|
||||||
namespace CakeProducts\Test\TestCase\Controller;
|
namespace CakeProducts\Test\TestCase\Controller;
|
||||||
|
|
||||||
|
use Cake\Core\Configure;
|
||||||
use Cake\TestSuite\IntegrationTestTrait;
|
use Cake\TestSuite\IntegrationTestTrait;
|
||||||
use Cake\TestSuite\TestCase;
|
use Cake\TestSuite\TestCase;
|
||||||
|
use FilesystemIterator;
|
||||||
|
use RecursiveDirectoryIterator;
|
||||||
|
use RecursiveIteratorIterator;
|
||||||
|
|
||||||
class BaseControllerTest extends TestCase
|
class BaseControllerTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -22,4 +26,38 @@ class BaseControllerTest extends TestCase
|
||||||
{
|
{
|
||||||
$this->assertEquals(1, 1);
|
$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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,14 +58,7 @@ class ProductPhotosControllerTest extends BaseControllerTest
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
unset($this->ProductPhotos);
|
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();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 943 B |
Loading…
Reference in New Issue