diff --git a/.gitignore b/.gitignore index a3fd6ab..2ba15f3 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,9 @@ vendor/ /phpstan.neon # PHPStan cache directory /.phpstan.cache/ + +# Added by horde-components QC --fix-qc-issues +# Horde installer plugin runtime data +/var/ +# Horde installer plugin web-accessible directory +/web/ diff --git a/lib/Horde/Mime/Part.php b/lib/Horde/Mime/Part.php index df81456..661dc1e 100644 --- a/lib/Horde/Mime/Part.php +++ b/lib/Horde/Mime/Part.php @@ -1318,7 +1318,7 @@ public function getSize($approx = false) return 0; } - $localeinfo = Horde_Nls::getLocaleInfo(); + $localeinfo = (new Horde\Nls\Nls())->getLocaleInfo(); // TODO: Workaround broken number_format() prior to PHP 5.4.0. return str_replace( diff --git a/test/unit/PartGetSizeTest.php b/test/unit/PartGetSizeTest.php new file mode 100644 index 0000000..90407e2 --- /dev/null +++ b/test/unit/PartGetSizeTest.php @@ -0,0 +1,60 @@ +setBytes(10240); + + $result = $part->getSize(); + + $this->assertIsString($result); + $this->assertStringContainsString('10', $result); + } + + public function testGetSizeReturnsZeroForEmptyPart(): void + { + $part = new Horde_Mime_Part(); + + $result = $part->getSize(); + + $this->assertEquals(0, $result); + } + + public function testGetSizeWithLargeValue(): void + { + $part = new Horde_Mime_Part(); + $part->setBytes(1048576); + + $result = $part->getSize(); + + $this->assertIsString($result); + $this->assertStringContainsString('1', $result); + } + + public function testGetSizeWithApprox(): void + { + $part = new Horde_Mime_Part(); + $part->setBytes(5120); + + $result = $part->getSize(true); + + $this->assertIsString($result); + $this->assertStringContainsString('5', $result); + } +}