General: Return "O B" when passing 0 to size_format().

Props swissspidy.
Fixes #36635.

git-svn-id: https://develop.svn.wordpress.org/trunk@37962 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling
2016-07-05 10:35:24 +00:00
parent ce7b53fb3f
commit c259f4c35d
3 changed files with 56 additions and 22 deletions

View File

@@ -51,28 +51,6 @@ class Tests_Functions extends WP_UnitTestCase {
$this->assertInternalType( 'string', $args['bar'] );
}
function test_size_format() {
$b = 1;
$kb = 1024;
$mb = $kb*1024;
$gb = $mb*1024;
$tb = $gb*1024;
// test if boundaries are correct
$this->assertEquals('1 GB', size_format($gb, 0));
$this->assertEquals('1 MB', size_format($mb, 0));
$this->assertEquals('1 KB', size_format($kb, 0));
$this->assertEquals('1 B', size_format($b, 0));
// now some values around
// add some bytes to make sure the result isn't 1.4999999
$this->assertEquals('1.5 TB', size_format($tb + $tb/2 + $mb, 1));
$this->assertEquals('1,023.999 GB', size_format($tb-$mb-$kb, 3));
// edge
$this->assertFalse(size_format(-1));
$this->assertFalse(size_format(0));
$this->assertFalse(size_format('baba'));
$this->assertFalse(size_format(array()));
}
/**
* @ticket 35972
*/