Fix: Correctly close active output buffer. (#28723)

# Fix: Correctly close active output buffer.

Use ob_get_clean(), not ob_get_contents() and ob_clean().

Tests were failing with:
FunctionsLibTest::testVerifCond with data set "Test that verifConf("0") returns false" ('0', false)
Test code or tested code did not (only) close its own output buffers

OK, but incomplete, skipped, or risky tests\!

Also refactored a test case to use a data provider which helped identify that it was related
to dol_eval.
This commit is contained in:
MDW
2024-03-09 01:27:01 +01:00
committed by GitHub
parent 6d857757e9
commit 746ca01423
2 changed files with 33 additions and 25 deletions

View File

@@ -1227,33 +1227,43 @@ class FunctionsLibTest extends CommonClassTest
$this->assertEquals(getServerTimeZoneInt('now') * 3600, ($nowtzserver - $now));
}
/**
* Data provider for testVerifCond
*
* @return array<string,array{0:string,1:bool}>
*/
public function verifCondDataProvider(): array
{
return [
'Test a true comparison' => ['1==1', true,],
'Test a false comparison' => ['1==2', false,],
'Test that the conf property of a module reports true when enabled' => ['isModEnabled("facture")', true,],
'Test that the conf property of a module reports false when disabled' => ['isModEnabled("moduledummy")', false,],
'Test that verifConf(0) returns false' => [0, false,],
'Test that verifConf("0") returns false' => ["0", false,],
'Test that verifConf("") returns false (special case)' => ['', true,],
];
}
/**
* testVerifCond
*
* @dataProvider verifCondDataProvider
*
* @param string $cond Condition to test using verifCond
* @param string $expected Expected outcome of verifCond
*
* @return void
*/
public function testVerifCond()
public function testVerifCond($cond, $expected)
{
$verifcond = verifCond('1==1');
$this->assertTrue($verifcond, 'Test a true comparison');
$verifcond = verifCond('1==2');
$this->assertFalse($verifcond, 'Test a false comparison');
$verifcond = verifCond('isModEnabled("facture")');
$this->assertTrue($verifcond, 'Test that the conf property of a module reports true when enabled');
$verifcond = verifCond('isModEnabled("moduledummy")');
$this->assertFalse($verifcond, 'Test that the conf property of a module reports false when disabled');
$verifcond = verifCond(0);
$this->assertFalse($verifcond, 'Test that verifConf(0) return False');
$verifcond = verifCond("0");
$this->assertFalse($verifcond, 'Test that verifConf("0") return False');
$verifcond = verifCond('');
$this->assertTrue($verifcond, 'Test that verifConf("") return False (special case)');
if ($expected) {
$this->assertTrue(verifCond($cond));
} else {
$this->assertFalse(verifCond($cond));
}
}
/**