summaryrefslogtreecommitdiff
path: root/tests/UnitTests/TemplateSource/NullCoalescingTest.php
blob: 2432527a7d86a2472e796a5eb3d42ee5e40c1eed (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
<?php

class NullCoalescingTest extends PHPUnit_Smarty {

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

	public function testUndefined() {
		$tpl = $this->smarty->createTemplate('string:{$myvar ?? "undefined"}');
		$this->assertEquals('undefined', $this->smarty->fetch($tpl));
	}

	/**
	 * @dataProvider dataForOther
	 */
	public function testOther($value, $expected) {
		$tpl = $this->smarty->createTemplate('string:{$myvar ?? "undefined"}');
		$tpl->assign('myvar', $value);
		$this->assertEquals($expected, $this->smarty->fetch($tpl));
	}

	public function dataForOther() {
		return [
			[null, 'undefined'],
			['blah', 'blah'],
			['', ''],
			[false, false],
		];
	}

}