myBlade=new myBlade();
$this->myBlade->setMode(BladeOne::MODE_DEBUG);
}
public function testBox(): void
{
$this->myBlade->addJs('
';
$this->assertEqualsNR( $html,$this->myBlade->runString($template));
}
public function testarguments(): void
{
$r = 'a1=1 a2="hello world" a2b="hello=world" a3=\'hello world\' a4=$a5 ';
self::assertEquals(
['a1' => 1, 'a2' => '"hello world"', 'a2b' => '"hello=world"', 'a3' => '\'hello world\'', 'a4' => '$a5']
, $this->myBlade->getArgsProxy($r));
$r = '1 "hello world" "hello=world" \'hello world\' $a5';
self::assertEquals(
['1' => null, '"hello world"' => null, '"hello=world"' => null, '\'hello world\'' => null, '$a5' => null]
, $this->myBlade->getArgsProxy($r));
}
public function testBasic1(): void
{
self::assertEquals('abc:'
,$this->myBlade->runString('@input(type="text" idname="hi" pre="abc:")'));
self::assertEquals(''
,$this->myBlade->runString('@input(type="text")'));
self::assertEquals(''
,$this->myBlade->runString('@input(type="text" abc="123" cde=\'123\' efg hij="")'));
}
public function testCheckbox(): void
{
$template='@checkbox(id="idsimple" value="1" checked="1" post="it is a selection")';
$html='it is a selection';
self::assertEquals($html,$this->myBlade->runString($template));
$template='@checkboxes(id="checkbox1" value=$selection alias=$country)
@item(id="aa1" value=\'aaa\' text=\'hello world\' post="
")
@item(id="aa2" value=\'aaa\' text=\'hello world2\' post="
")
@items(values=$countries value=\'id\' text=\'name\' post="
")
@endcheckboxes';
$html='
hello world
hello world2
';
self::assertEquals($html,$this->myBlade->runString($template));
}
public function testRadio(): void
{
$template='@radio(id="idsimple" value="1" checked="1" post="it is a selection")';
$html='it is a selection';
self::assertEquals($html,$this->myBlade->runString($template));
$template='@radios(id="radios1" name="aaa" value=$selection alias=$country)
@item(value=\'aaa\' text=\'hello world\' post="
")
@item(value=\'aaa\' text=\'hello world2\' post="
")
@items(values=$countries value=\'id\' text=\'name\' post="
")
@endradios';
$html='
hello world
hello world2
';
self::assertEquals($html,$this->myBlade->runString($template));
}
public function testMisc(): void
{
$template='@ul(id="aaa" value=$selection values=$countries alias=$country)
@item(value=\'aaa\' text=\'hello world\')
@items(value=$country->id text=$country->name)
@endul
@image(src="https://via.placeholder.com/350x150")
@label(for="id1" text="hello world:")
@hidden(name="id1" value="hello world$somevar" )
@alert(text="hi there" class="alert-danger" customtag="it is a custom tag")
';
$html='
hi there
';
self::assertEquals($html,$this->myBlade->runString($template));
}
public function testTextArea(): void
{
$template='@textarea(id="aaa" value="3333 3333 aaa3333")';
$html='';
self::assertEquals($html,$this->myBlade->runString($template));
}
public function testTable(): void
{
$template='@table(class="table" values=$countries alias=$country border="1")
@tablehead
@cell(text="id")
@cell(text="cod")
@cell(text="name")
@endtablehead
@tablebody(id=\'hello world\' )
@tablerows(style="background-color:azure")
@cell(text=$country->id style="background-color:orange")
@cell(text=$country->cod )
@cell(text=$country->name)
@endtablerows
@endtablebody
@tablefooter
@cell(text="id" colspan="3")
@endtablefooter
@endtable';
$html='';
self::assertEquals($html,$this->myBlade->runString($template));
}
public function testButton(): void
{
$template='
@form()
@input(type="text" name="myform" value=$myvalue)
@button(type="submit" text="Send")
@link(href="https://www.google.cl" text="context")
@endform()
';
$html='
';
self::assertEquals($html,$this->myBlade->runString($template));
}
public function testNewVarSelect(): void
{
self::assertEquals('
',$this->myBlade->runString('@select(id="aaa" value=$selection values=$countries alias=$country)
@item(value=\'aaa\' text=\'hello world\')
@item(value=\'aaa\' text=\'hello world\')
@item(value=\'aaa\' text=\'hello world\')
@items( id="chkx" value=$country->id text=$country->name)
@endselect
'));
}
public function testNewVarSelect2(): void
{
self::assertEquals('
',$this->myBlade->runString('@select(name="frm_Cham__idSensor$x" label="Sensor$x" id="frm_Cham__idSensor$x"
value=$selection values=$countries alias=$country)
@item(value=\'aaa\' text=\'hello world\')
@item(value=\'aaa\' text=\'hello world\')
@item(value=\'aaa\' text=\'hello world\')
@items( id="chkx" value=$country->id text=$country->name)
@endselect
',['x'=>'xyz']));
}
public function testNewVar3(): void
{
$this->myBlade->useBootstrap3();
$this->myBlade->useBootstrap3(true);
self::assertEquals(''
,$this->myBlade->runString('@input(type="text")'));
self::assertEquals(''
,$this->myBlade->runString('@input(type="text" abc="123" cde=\'123\' efg hij="")'));
}
public function testNewVar4(): void
{
$this->myBlade->useBootstrap4();
$this->myBlade->useBootstrap4(true);
self::assertEquals(''
,$this->myBlade->runString('@input(type="text")'));
self::assertEquals(''
,$this->myBlade->runString('@input(type="text" abc="123" cde=\'123\' efg hij="")'));
}
public function testtc(): void
{
$pagarray=array('pagination'=>array( 'first' => 'First',
'prev' => 'Previous',
'next' => 'Next',
'last' => 'Last'));
self::assertEquals($pagarray,$this->myBlade->getTranslationControl());
$this->myBlade->setTranslationControl($pagarray);
self::assertEquals($pagarray,$this->myBlade->getTranslationControl());
}
public function testmsg(): void
{
$mc=new MessageContainer();
$mc->addItem('msg1','there is an error');
$this->myBlade->message($mc);
self::assertEquals("there is an error",$this->myBlade->runString("@message(id='msg1' level='error' default='')"));
}
}