summaryrefslogtreecommitdiff
path: root/tests/UnitTests/TemplateSource/TernaryTest.php
blob: 312ada96e2f20ce27ab84a6b8b57bee1594f81a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php

class TernaryTest extends PHPUnit_Smarty {

	public function setUp(): void
	{
		$this->setUpSmarty(sys_get_temp_dir());
		$this->cleanDirs();
	}

	public function testTernaryTrue() {
		$tpl = $this->smarty->createTemplate('string:{$a ? $b : $c}');
		$tpl->assign('a', true);
		$tpl->assign('b', 'B');
		$tpl->assign('c', 'C');
		$this->assertEquals('B', $this->smarty->fetch($tpl));
	}

	public function testTernaryFalse() {
		$tpl = $this->smarty->createTemplate('string:{$a ? $b : $c}');
		$tpl->assign('a', false);
		$tpl->assign('b', 'B');
		$tpl->assign('c', 'C');
		$this->assertEquals('C', $this->smarty->fetch($tpl));
	}

	public function testShorthandTernaryTrue() {
		$tpl = $this->smarty->createTemplate('string:{$a ?: $c}');
		$tpl->assign('a', true);
		$tpl->assign('c', 'C');
		$this->assertEquals(true, $this->smarty->fetch($tpl));
	}

	public function testShorthandTernaryFalse() {
		$tpl = $this->smarty->createTemplate('string:{$a ? $b : $c}');
		$tpl->assign('a', false);
		$tpl->assign('c', 'C');
		$this->assertEquals('C', $this->smarty->fetch($tpl));
	}

}