Feature: Labelprint für Kistenetiketten hinzugefügt

This commit is contained in:
2025-10-27 12:14:44 +01:00
parent 43bc416554
commit 14bae6c9ef
1068 changed files with 229014 additions and 1807 deletions

View File

@@ -0,0 +1,289 @@
<?php
/**
* ByteTest.php
*
* @since 2015-07-28
* @category Library
* @package File
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2015-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-file
*
* This file is part of tc-lib-file software library.
*/
namespace Test;
use PHPUnit\Framework\Attributes\DataProvider;
/**
* Byte Color class test
*
* @since 2015-07-28
* @category Library
* @package File
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2015-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-file
*/
class ByteTest extends TestUtil
{
protected function getTestObject(): \Com\Tecnick\File\Byte
{
$str = chr(0) . chr(0) . chr(0) . chr(0)
. chr(1) . chr(3) . chr(7) . chr(15)
. chr(31) . chr(63) . chr(127) . chr(255)
. chr(254) . chr(252) . chr(248) . chr(240)
. chr(224) . chr(192) . chr(128) . chr(0)
. chr(255) . chr(255) . chr(255) . chr(255);
return new \Com\Tecnick\File\Byte($str);
}
#[DataProvider('getByteDataProvider')]
public function testGetByte(int $offset, int $expected): void
{
$byte = $this->getTestObject();
$res = $byte->getByte($offset);
$this->assertEquals($expected, $res);
}
/**
* @return array<array{int, int}>
*/
public static function getByteDataProvider(): array
{
return [
[0, 0],
[1, 0],
[2, 0],
[3, 0],
[4, 1],
[5, 3],
[6, 7],
[7, 15],
[8, 31],
[9, 63],
[10, 127],
[11, 255],
[12, 254],
[13, 252],
[14, 248],
[15, 240],
[16, 224],
[17, 192],
[18, 128],
[19, 0],
[20, 255],
[21, 255],
[22, 255],
[23, 255],
];
}
#[DataProvider('getULongDataProvider')]
public function testGetULong(int $offset, int $expected): void
{
$byte = $this->getTestObject();
$res = $byte->getULong($offset);
$this->assertEquals($expected, $res);
}
/**
* @return array<array{int, int}>
*/
public static function getULongDataProvider(): array
{
return [
[0, 0],
[1, 1],
[2, 259],
[3, 66311],
[4, 16_975_631],
[5, 50_794_271],
[6, 118_431_551],
[7, 253_706_111],
[8, 524_255_231],
[9, 1_065_353_214],
[10, 2_147_483_388],
[11, 4_294_900_984],
[12, 4_277_991_664],
[13, 4_244_173_024],
[14, 4_176_535_744],
[15, 4_041_261_184],
[16, 3_770_712_064],
[17, 3_229_614_335],
[18, 2_147_549_183],
[19, 16_777_215],
[20, 4_294_967_295],
];
}
#[DataProvider('getUShortDataProvider')]
public function testGetUShort(int $offset, int $expected): void
{
$byte = $this->getTestObject();
$res = $byte->getUShort($offset);
$this->assertEquals($expected, $res);
}
#[DataProvider('getUShortDataProvider')]
public function testGetUFWord(int $offset, int $expected): void
{
$byte = $this->getTestObject();
$res = $byte->getUFWord($offset);
$this->assertEquals($expected, $res);
}
/**
* @return array<array{int, int}>
*/
public static function getUShortDataProvider(): array
{
return [
[0, 0],
[1, 0],
[2, 0],
[3, 1],
[4, 259],
[5, 775],
[6, 1807],
[7, 3871],
[8, 7999],
[9, 16255],
[10, 32767],
[11, 65534],
[12, 65276],
[13, 64760],
[14, 63728],
[15, 61664],
[16, 57536],
[17, 49280],
[18, 32768],
[19, 255],
[20, 65535],
[21, 65535],
[22, 65535],
];
}
#[DataProvider('getShortDataProvider')]
public function testGetShort(int $offset, int $expected): void
{
$byte = $this->getTestObject();
$res = $byte->getShort($offset);
$this->assertEquals($expected, $res);
}
/**
* @return array<array{int, int}>
*/
public static function getShortDataProvider(): array
{
return [
[0, 0],
[1, 0],
[2, 0],
[3, 256],
[4, 769],
[5, 1795],
[6, 3847],
[7, 7951],
[8, 16159],
[9, 32575],
[10, -129],
[11, -257],
[12, -770],
[13, -1796],
[14, -3848],
[15, -7952],
[16, -16160],
[17, -32576],
[18, 128],
[19, -256],
[20, -1],
[21, -1],
[22, -1],
];
}
#[DataProvider('getFWordDataProvider')]
public function testGetFWord(int $offset, int $expected): void
{
$byte = $this->getTestObject();
$res = $byte->getFWord($offset);
$this->assertEquals($expected, $res);
}
/**
* @return array<array{int, int}>
*/
public static function getFWordDataProvider(): array
{
return [
[0, 0],
[1, 0],
[2, 0],
[3, 1],
[4, 259],
[5, 775],
[6, 1807],
[7, 3871],
[8, 7999],
[9, 16255],
[10, 32767],
[11, -2],
[12, -260],
[13, -776],
[14, -1808],
[15, -3872],
[16, -8000],
[17, -16256],
[18, -32768],
[19, 255],
[20, -1],
[21, -1],
[22, -1],
];
}
#[DataProvider('getFixedDataProvider')]
public function testGetFixed(int $offset, int|float $expected): void
{
$byte = $this->getTestObject();
$res = $byte->getFixed($offset);
$this->assertEquals($expected, $res);
}
/**
* @return array<array{int, float}>
*/
public static function getFixedDataProvider(): array
{
return [
[0, 0],
[1, 0.1],
[2, 0.259],
[3, 1.775],
[4, 259.1807],
[5, 775.3871],
[6, 1807.7999],
[7, 3871.16255],
[8, 7999.32767],
[9, 16255.65534],
[10, 32767.65276],
[11, -2.64760],
[12, -260.63728],
[13, -776.61664],
[14, -1808.57536],
[15, -3872.49280],
[16, -8000.32768],
[17, -16256.255],
[18, -32768.65535],
[19, 255.65535],
[20, -1.65535],
];
}
}

View File

@@ -0,0 +1,102 @@
<?php
/**
* CacheTest.php
*
* @since 2011-05-23
* @category Library
* @package File
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-filecache
*
* This file is part of tc-lib-pdf-filecache software library.
*/
namespace Test;
/**
* Unit Test
*
* @since 2011-05-23
* @category Library
* @package File
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-filecache
*/
class CacheTest extends TestUtil
{
protected function getTestObject(): \Com\Tecnick\File\Cache
{
return new \Com\Tecnick\File\Cache('1_2-a+B/c');
}
public function testAutoPrefix(): void
{
$cache = new \Com\Tecnick\File\Cache();
$this->assertNotEmpty($cache->getFilePrefix());
}
public function testGetCachePath(): void
{
$cache = $this->getTestObject();
$cachePath = $cache->getCachePath();
$this->assertEquals('/', $cachePath[0]);
$this->assertEquals('/', substr($cachePath, -1));
$cache->setCachePath();
$this->assertEquals($cachePath, $cache->getCachePath());
$path = '/tmp';
$cache->setCachePath($path);
$this->assertEquals('/tmp/', $cache->getCachePath());
}
public function testGetFilePrefix(): void
{
$cache = $this->getTestObject();
$filePrefix = $cache->getFilePrefix();
$this->assertEquals('_1_2-a-B_c_', $filePrefix);
}
public function testGetNewFileName(): void
{
$cache = $this->getTestObject();
$val = $cache->getNewFileName('tst', '0123');
$this->assertNotFalse($val);
$this->bcAssertMatchesRegularExpression('/_1_2-a-B_c_tst_0123_/', $val);
}
public function testDelete(): void
{
$cache = $this->getTestObject();
$idk = 0;
for ($idx = 1; $idx <= 2; ++$idx) {
for ($idy = 1; $idy <= 2; ++$idy) {
$file[$idk] = $cache->getNewFileName((string) $idx, (string) $idy);
$this->assertNotFalse($file[$idk]);
file_put_contents($file[$idk], '');
$this->assertTrue(file_exists($file[$idk]));
++$idk;
}
}
$cache->delete('2', '1');
$this->assertNotFalse($file[2]);
$this->assertFalse(file_exists($file[2]));
$cache->delete('1');
$this->assertNotFalse($file[0]);
$this->assertFalse(file_exists($file[0]));
$this->assertNotFalse($file[1]);
$this->assertFalse(file_exists($file[1]));
$this->assertNotFalse($file[3]);
$this->assertTrue(file_exists($file[3]));
$cache->delete();
$this->assertFalse(file_exists($file[3]));
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* DirTest.php
*
* @since 2015-07-28
* @category Library
* @package File
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2015-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-file
*
* This file is part of tc-lib-file software library.
*/
namespace Test;
use PHPUnit\Framework\Attributes\DataProvider;
/**
* File Color class test
*
* @since 2015-07-28
* @category Library
* @package File
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2015-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-file
*/
class DirTest extends TestUtil
{
protected function getTestObject(): \Com\Tecnick\File\Dir
{
return new \Com\Tecnick\File\Dir();
}
#[DataProvider('getAltFilePathsDataProvider')]
public function testGetAltFilePaths(string $name, string $expected): void
{
$testObj = $this->getTestObject();
$dir = $testObj->findParentDir($name);
$this->bcAssertMatchesRegularExpression('#' . $expected . '#', $dir);
}
/**
* @return array<array{string, string}>
*/
public static function getAltFilePathsDataProvider(): array
{
return [['', '/src/'], ['missing', '/'], ['src', '/src/']];
}
}

View File

@@ -0,0 +1,224 @@
<?php
/**
* FileTest.php
*
* @since 2015-07-28
* @category Library
* @package File
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2015-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-file
*
* This file is part of tc-lib-file software library.
*/
namespace Test;
use PHPUnit\Framework\Attributes\DataProvider;
/**
* File Color class test
*
* @since 2015-07-28
* @category Library
* @package File
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2015-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-file
*/
class FileTest extends TestUtil
{
protected function getTestObject(): \Com\Tecnick\File\File
{
return new \Com\Tecnick\File\File();
}
public function testFopenLocal(): void
{
$file = $this->getTestObject();
$handle = $file->fopenLocal(__FILE__, 'r');
$this->bcAssertIsResource($handle);
fclose($handle);
}
public function testFopenLocalNonLocal(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\File\Exception::class);
$file = $this->getTestObject();
$file->fopenLocal('http://www.example.com/test.txt', 'r');
}
public function testFopenLocalMissing(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\File\Exception::class);
$file = $this->getTestObject();
$file->fopenLocal('/missing_error.txt', 'r');
}
public function testFopenLocalDoubleDot(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\File\Exception::class);
$file = $this->getTestObject();
$file->fopenLocal('/tmp/invalid/../test.txt', 'r');
}
public function testfReadInt(): void
{
$file = $this->getTestObject();
$handle = fopen(__FILE__, 'r');
$this->assertNotFalse($handle);
$res = $file->fReadInt($handle);
// '<?ph' = 60 63 112 104 = 00111100 00111111 01110000 01101000 = 1010790504
$this->assertEquals(1_010_790_504, $res);
fclose($handle);
}
public function testRfRead(): void
{
$file = $this->getTestObject();
$handle = fopen(dirname(__DIR__) . '/src/File.php', 'rb');
$this->assertNotFalse($handle);
$res = $file->rfRead($handle, 2);
$this->assertEquals('<?', $res);
$res = $file->rfRead($handle, 3);
$this->assertEquals('php', $res);
fclose($handle);
}
public function testRfReadException(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\File\Exception::class);
$file = $this->getTestObject();
$file->rfRead(null, 2);
}
/**
* @param string $file File path
* @param array{string, array<int, string>} $expected Expected result
*/
#[DataProvider('getAltFilePathsDataProvider')]
public function testGetAltFilePaths(string $file, array $expected): void
{
$testObj = $this->getTestObject();
$_SERVER['DOCUMENT_ROOT'] = '/var/www';
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['HTTPS'] = 'on';
$_SERVER['SCRIPT_URI'] = 'https://localhost/path/example.php';
$alt = $testObj->getAltFilePaths($file);
$this->assertEquals($expected, $alt);
}
/**
* Data provider for testGetAltFilePaths
*
* @return array<array{string, array<int, string>}>
*/
public static function getAltFilePathsDataProvider(): array
{
return [
[
'http://www.example.com/test.txt',
[
0 => 'http://www.example.com/test.txt',
],
],
[
'https://localhost/path/test.txt',
[
0 => 'https://localhost/path/test.txt',
3 => '/var/www/path/test.txt',
],
],
[
'//www.example.com/space test.txt',
[
0 => '//www.example.com/space test.txt',
2 => 'https://www.example.com/space%20test.txt',
],
],
[
'/path/test.txt',
[
0 => '/path/test.txt',
1 => '/var/www/path/test.txt',
4 => 'https://localhost/path/test.txt',
],
],
[
'https://localhost/path/test.php?a=0&b=1&amp;c=2;&amp;d="a+b%20c"',
[
0 => 'https://localhost/path/test.php?a=0&b=1&amp;c=2;&amp;d="a+b%20c"',
2 => 'https://localhost/path/test.php?a=0&b=1&c=2;&d="a+b%20c"',
],
],
[
'path/test.txt',
[
0 => 'path/test.txt',
4 => 'https://localhost/path/test.txt',
],
],
];
}
public function testFileGetContentsMissingException(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\File\Exception::class);
$file = $this->getTestObject();
$file->fileGetContents('missing.txt');
}
public function testFileGetContentsDoubleDotException(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\File\Exception::class);
$file = $this->getTestObject();
$file->fileGetContents('/tmp/something/../test.txt');
}
public function testFileGetContentsForbiddenProtocolException(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\File\Exception::class);
$file = $this->getTestObject();
$file->fileGetContents('phar://test.txt');
}
public function testFileGetContents(): void
{
$file = $this->getTestObject();
$res = $file->fileGetContents(__FILE__);
$this->assertEquals('<?php', substr($res, 0, 5));
}
public function testFileGetContentsCurl(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\File\Exception::class);
$file = $this->getTestObject();
define('FORCE_CURL', true);
$file->fileGetContents('http://www.example.com/test.txt');
}
public function testHasDoubleDots(): void
{
$file = $this->getTestObject();
$res = $file->hasDoubleDots('/tmp/../test.txt');
$this->assertTrue($res);
$res = $file->hasDoubleDots('/tmp/test.txt');
$this->assertFalse($res);
}
public function testHasForbiddenProtocol(): void
{
$file = $this->getTestObject();
$res = $file->hasForbiddenProtocol('phar://test.txt');
$this->assertTrue($res);
$res = $file->hasForbiddenProtocol('http://www.example.com/test.txt');
$this->assertFalse($res);
$res = $file->hasForbiddenProtocol('file://some/file.txt');
$this->assertFalse($res);
$res = $file->hasForbiddenProtocol('./some/file.txt');
$this->assertFalse($res);
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* TestUtil.php
*
* @since 2020-12-19
* @category Library
* @package file
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2015-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-file
*
* This file is part of tc-lib-file software library.
*/
namespace Test;
use PHPUnit\Framework\TestCase;
/**
* Test Util
*
* @since 2020-12-19
* @category Library
* @package file
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2015-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-file
*/
class TestUtil extends TestCase
{
public function bcAssertEqualsWithDelta(
mixed $expected,
mixed $actual,
float $delta = 0.01,
string $message = ''
): void {
parent::assertEqualsWithDelta($expected, $actual, $delta, $message);
}
/**
* @param class-string<\Throwable> $exception
*/
public function bcExpectException($exception): void
{
parent::expectException($exception);
}
public function bcAssertIsResource(mixed $res): void
{
parent::assertIsResource($res);
}
public function bcAssertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void
{
parent::assertMatchesRegularExpression($pattern, $string, $message);
}
}

View File