Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion phpBB/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
"symfony/dom-crawler": "^7.4",
"symfony/http-client": "^7.4",
"vimeo/psalm": "^6.13.1",
"psalm/plugin-symfony": "^v5.1.0"
"psalm/plugin-symfony": "^v5.1.0",
"mikey179/vfsstream": "^1.6"
},
"extra": {
"branch-alias": {
Expand Down
54 changes: 53 additions & 1 deletion phpBB/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion phpBB/phpbb/textformatter/s9e/factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,19 @@ public function tidy()
$renderer_data = $this->cache->get($this->cache_key_renderer);
$renderer_file = ($renderer_data) ? $renderer_data['class'] . '.php' : null;

foreach (glob($this->cache_dir . 's9e_*') as $filename)
foreach (scandir($this->cache_dir) ?: array() as $file)
{
if (strpos($file, 's9e_') !== 0)
{
continue;
Comment thread
rubencm marked this conversation as resolved.
}

$filename = $this->cache_dir . $file;
if (!is_file($filename))
{
continue;
}

// Only remove the file if it's not the current renderer
if (!$renderer_file || substr($filename, -strlen($renderer_file)) !== $renderer_file)
{
Expand Down
44 changes: 7 additions & 37 deletions tests/cache/file_driver_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@

require_once __DIR__ . '/common_test_case.php';

use org\bovigo\vfs\vfsStream;

class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case
{
private $cache_dir;

/** @var \phpbb\cache\driver\file */
private $cache_file;
private $cache_file;

public function getDataSet()
{
Expand All @@ -29,30 +31,15 @@ protected function setUp(): void
{
parent::setUp();

$this->cache_dir = __DIR__ . '/../tmp/cache/';

if (file_exists($this->cache_dir))
{
// cache directory possibly left after aborted
// or failed run earlier
$this->remove_cache_dir();
}
$this->create_cache_dir();
vfsStream::setup('phpbb', null, array(
'cache' => array(),
));
$this->cache_dir = vfsStream::url('phpbb/cache') . '/';

$this->cache_file = new \phpbb\cache\driver\file($this->cache_dir);
$this->driver = $this->cache_file;
}

protected function tearDown(): void
{
if (file_exists($this->cache_dir))
{
$this->remove_cache_dir();
}

parent::tearDown();
}

public function test_read_not_readable()
{
if (strtolower(substr(PHP_OS, 0, 3)) === 'win')
Expand Down Expand Up @@ -188,21 +175,4 @@ public function test_read_data_global()
$this->assertEquals($expectedVarExpires, $reflectionCacheVarExpires->getValue($this->cache_file));
}

private function create_cache_dir()
{
$this->get_test_case_helpers()->makedirs($this->cache_dir);
}

private function remove_cache_dir()
{
$iterator = new DirectoryIterator($this->cache_dir);
foreach ($iterator as $file)
{
if ($file != '.' && $file != '..')
{
unlink($this->cache_dir . '/' . $file);
}
}
rmdir($this->cache_dir);
}
}
33 changes: 6 additions & 27 deletions tests/console/cache/purge_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use org\bovigo\vfs\vfsStream;
use phpbb\console\command\cache\purge;

require_once __DIR__ . '/../../../phpBB/includes/functions_admin.php';
Expand All @@ -31,20 +32,16 @@ protected function setUp(): void
{
global $phpbb_root_path, $phpEx;

$this->cache_dir = __DIR__ . '/tmp/cache/';
parent::setUp();

if (file_exists($this->cache_dir))
{
// cache directory possibly left after aborted
// or failed run earlier
$this->remove_cache_dir();
}
$this->create_cache_dir();
vfsStream::setup('phpbb', null, array(
'cache' => array(),
));
$this->cache_dir = vfsStream::url('phpbb/cache') . '/';

$this->cache = new \phpbb\cache\driver\file($this->cache_dir);

$this->db = $this->createMock('\phpbb\db\driver\driver_interface');
$tools_factory = new \phpbb\db\tools\factory();
$this->db_tools = $this->createMock('\phpbb\db\tools\doctrine');

$this->config = new \phpbb\config\config(array('assets_version' => 1));
Expand All @@ -69,24 +66,6 @@ public function test_purge()
$this->assertSame(2, $this->config['assets_version']);
}

private function create_cache_dir()
{
$this->get_test_case_helpers()->makedirs($this->cache_dir);
}

private function remove_cache_dir()
{
$iterator = new DirectoryIterator($this->cache_dir);
foreach ($iterator as $file)
{
if ($file != '.' && $file != '..')
{
unlink($this->cache_dir . '/' . $file);
}
}
rmdir($this->cache_dir);
}

public function get_command_tester()
{
$application = new Application();
Expand Down
75 changes: 33 additions & 42 deletions tests/console/thumbnail_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use phpbb\attachment\attachment_category;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use org\bovigo\vfs\vfsStream;
use phpbb\console\command\thumbnail\generate;
use phpbb\console\command\thumbnail\delete;
use phpbb\console\command\thumbnail\recreate;
Expand All @@ -30,6 +31,8 @@ class phpbb_console_command_thumbnail_test extends phpbb_database_test_case
protected $phpEx;
protected $phpbb_root_path;
protected $application;
protected $storage_path;
protected $temp_path;

public function getDataSet()
{
Expand Down Expand Up @@ -64,81 +67,69 @@ protected function setUp(): void
'txt' => array('display_cat' => attachment_category::NONE),
)));

$png = file_get_contents(__DIR__ . '/fixtures/png.png');
$txt = file_get_contents(__DIR__ . '/fixtures/txt.txt');

$phpbb_filesystem = new \phpbb\filesystem\filesystem();
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
vfsStream::setup('phpbb', null, array(
'files' => array(
'test_png_1' => $png,
'test_png_2' => $png,
'thumb_test_png_2' => $png,
'test_txt' => $txt,
),
'tmp' => array(),
));
$this->storage_path = vfsStream::url('phpbb/files') . '/';
$this->temp_path = vfsStream::url('phpbb/tmp');

$this->storage = $this->createMock('\phpbb\storage\storage');
$this->storage->method('write')->willReturnCallback(function ($path, $data) use ($phpbb_root_path) {
file_put_contents($phpbb_root_path . 'files/' . $path, $data);
$this->storage->method('write')->willReturnCallback(function ($path, $data) {
file_put_contents($this->storage_path . $path, is_resource($data) ? stream_get_contents($data) : $data);
});
$this->storage->method('read')->willReturnCallback(function ($path) use ($phpbb_root_path) {
return fopen($phpbb_root_path . 'files/' . $path, 'rb');
$this->storage->method('read')->willReturnCallback(function ($path) {
return fopen($this->storage_path . $path, 'rb');
});
$this->storage->method('delete')->willReturnCallback(function ($path) use ($phpbb_root_path) {
unlink($phpbb_root_path . 'files/' . $path);
$this->storage->method('delete')->willReturnCallback(function ($path) {
unlink($this->storage_path . $path);
});

$this->temp = $this->createMock('\phpbb\filesystem\temp');
$this->temp->method('get_dir')->willReturnCallback(function () {
return sys_get_temp_dir();
return $this->temp_path;
});

$this->application = new Application();
$this->application->add(new generate($this->user, $this->db, $this->cache, $this->language, $this->storage, $this->temp, $this->phpbb_root_path, $this->phpEx));
$this->application->add(new delete($this->user, $this->db, $this->language, $this->storage));
$this->application->add(new recreate($this->user, $this->language));

copy(__DIR__ . '/fixtures/png.png', $this->phpbb_root_path . 'files/test_png_1');
copy(__DIR__ . '/fixtures/png.png', $this->phpbb_root_path . 'files/test_png_2');
copy(__DIR__ . '/fixtures/png.png', $this->phpbb_root_path . 'files/thumb_test_png_2');
copy(__DIR__ . '/fixtures/txt.txt', $this->phpbb_root_path . 'files/test_txt');
}

protected function tearDown(): void
{
parent::tearDown();

$delete_files = [
$this->phpbb_root_path . 'files/test_png_1',
$this->phpbb_root_path . 'files/test_png_2',
$this->phpbb_root_path . 'files/test_txt',
$this->phpbb_root_path . 'files/thumb_test_png_1',
$this->phpbb_root_path . 'files/thumb_test_png_2'
];

foreach ($delete_files as $file)
{
if (file_exists($file))
{
unlink($file);
}
}
}

public function test_thumbnails()
{
$command_tester = $this->get_command_tester('thumbnail:generate');
$exit_status = $command_tester->execute([]);

self::assertSame(true, file_exists($this->phpbb_root_path . 'files/thumb_test_png_1'));
self::assertSame(true, file_exists($this->phpbb_root_path . 'files/thumb_test_png_2'));
self::assertSame(false, file_exists($this->phpbb_root_path . 'files/thumb_test_txt'));
self::assertSame(true, file_exists($this->storage_path . 'thumb_test_png_1'));
self::assertSame(true, file_exists($this->storage_path . 'thumb_test_png_2'));
self::assertSame(false, file_exists($this->storage_path . 'thumb_test_txt'));
self::assertSame(0, $exit_status);

$command_tester = $this->get_command_tester('thumbnail:delete');
$exit_status = $command_tester->execute([]);

self::assertSame(false, file_exists($this->phpbb_root_path . 'files/thumb_test_png_1'));
self::assertSame(false, file_exists($this->phpbb_root_path . 'files/thumb_test_png_2'));
self::assertSame(false, file_exists($this->phpbb_root_path . 'files/thumb_test_txt'));
self::assertSame(false, file_exists($this->storage_path . 'thumb_test_png_1'));
self::assertSame(false, file_exists($this->storage_path . 'thumb_test_png_2'));
self::assertSame(false, file_exists($this->storage_path . 'thumb_test_txt'));
self::assertSame(0, $exit_status);

$command_tester = $this->get_command_tester('thumbnail:recreate');
$exit_status = $command_tester->execute([]);

self::assertSame(true, file_exists($this->phpbb_root_path . 'files/thumb_test_png_1'));
self::assertSame(true, file_exists($this->phpbb_root_path . 'files/thumb_test_png_2'));
self::assertSame(false, file_exists($this->phpbb_root_path . 'files/thumb_test_txt'));
self::assertSame(true, file_exists($this->storage_path . 'thumb_test_png_1'));
self::assertSame(true, file_exists($this->storage_path . 'thumb_test_png_2'));
self::assertSame(false, file_exists($this->storage_path . 'thumb_test_txt'));
self::assertSame(0, $exit_status);
}

Expand Down
Loading
Loading