Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tbs_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@ function meth_Locator_FindTbs(&$Txt,$Name,$Pos,$ChrSub) {
$this->meth_Misc_Alert('','can\'t found the end of the tag \''.substr($Txt,$Pos,$PosX-$Pos+10).'...\'.');
$Pos++;
} else {
self::meth_Misc_ApplyPrmCombo($Loc->PrmLst, $Loc);
self::meth_Misc_ApplyPrmCombo($Loc->PrmLst, $Loc, $this);
}
}

Expand Down Expand Up @@ -4169,7 +4169,7 @@ function meth_Misc_DateFormat(&$Value, $Frm) {
* @param array $PrmLst The existing list of combo
* @param object|false $Loc The current locator, of false if called from an combo definition
*/
static function meth_Misc_ApplyPrmCombo(&$PrmLst, $Loc) {
static function meth_Misc_ApplyPrmCombo(&$PrmLst, $Loc, $TBS = null) {

if (isset($PrmLst['combo'])) {

Expand Down Expand Up @@ -4199,7 +4199,7 @@ static function meth_Misc_ApplyPrmCombo(&$PrmLst, $Loc) {
}
$PrmLst = array_merge($ap, $PrmLst);
} else {
$this->meth_Misc_Alert("with parameter 'combo'", "Combo '". $name. "' is not yet set.");
if ($TBS !== null) $TBS->meth_Misc_Alert("with parameter 'combo'", "Combo '". $name. "' is not yet set.");
}
}

Expand Down
2 changes: 2 additions & 0 deletions testunit/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
include($dir_testu.'/testcase/BlockTestCase.php');
include($dir_testu.'/testcase/BlockGrpTestCase.php');
include($dir_testu.'/testcase/MiscTestCase.php');
include($dir_testu.'/testcase/PrmComboTestCase.php');
include($dir_testu.'/testcase/SubTplTestCase.php');
include($dir_testu.'/testcase/SubnameTestCase.php');
include($dir_testu.'/testcase/PluginsTestCase.php');
Expand All @@ -54,6 +55,7 @@
$test->addTestCase(new OpeTestCase());
$test->addTestCase(new StrconvTestCase());
$test->addTestCase(new MiscTestCase());
$test->addTestCase(new PrmComboTestCase());
$test->addTestCase(new SubTplTestCase());
$test->addTestCase(new SubnameTestCase());
$test->addTestCase(new PluginsTestCase());
Expand Down
43 changes: 43 additions & 0 deletions testunit/testcase/PrmComboTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

class PrmComboTestCase extends TBSUnitTestCase {

function __construct() {
$this->UnitTestCase('Parameter combo Unit Tests');
}

function setUp() {
// Reset global combo list before each test to avoid pollution
$GLOBALS['_TBS_PrmCombo'] = array();
}

function tearDown() {
$GLOBALS['_TBS_PrmCombo'] = array();
}

function testKnownCombo() {
// A registered combo's parameters are applied to the field.
// Here 'safe' adds noerr so a missing variable produces no error.
$this->newInstance = false;
$this->tbs = new clsTinyButStrong;
$this->tbs->SetOption('prm_combo', array('safe' => array('noerr' => '')));

$this->assertEqualMergeFieldStrings('[onshow.nonexistent;combo=safe]', array(), '', 'known combo #1 - output is empty');
$this->assertNoTbsError('known combo #1 - no TBS error');
}

function testUnknownComboRaisesTbsError() {
// Referencing an undefined combo must raise a TBS error instead of a PHP fatal error.
// Before the fix, this caused: "Fatal error: Using $this when not in object context"
// because meth_Misc_ApplyPrmCombo is static but called $this->meth_Misc_Alert().
$this->tbs = new clsTinyButStrong;
$this->tbs->NoErr = true;
$this->tbs->Source = '[onshow.msg;combo=undefined_combo]';
$this->tbs->VarRef['msg'] = 'hello';
$this->tbs->Show(TBS_NOTHING);

$this->assertTrue($this->tbs->ErrCount > 0, 'unknown combo - TBS error is raised');
$this->assertEqual($this->tbs->Source, 'hello', 'unknown combo - field value still rendered');
}

}