mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-07 16:41:48 +01:00
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:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user