Commit | Line | Data |
---|---|---|
b812aefb TO |
1 | <?php |
2 | ||
b812aefb TO |
3 | /** |
4 | * Class CRM_Utils_AutoCleanTest | |
acb109b7 | 5 | * @group headless |
b812aefb TO |
6 | */ |
7 | class CRM_Utils_AutoCleanTest extends CiviUnitTestCase { | |
8 | ||
9 | public $foo; | |
10 | ||
0b49aa04 | 11 | protected function setUp(): void { |
b812aefb TO |
12 | $this->useTransaction(); |
13 | parent::setUp(); | |
14 | } | |
15 | ||
16 | public function testAutoclean() { | |
17 | $this->foo = 'orig'; | |
18 | $this->assertEquals('orig', $this->foo); | |
19 | $this->nestedWithArrayCb(); | |
20 | $this->assertEquals('orig', $this->foo); | |
21 | $this->nestedWithFuncCb(); | |
22 | $this->assertEquals('orig', $this->foo); | |
23 | $this->nestedSwap(); | |
24 | $this->assertEquals('orig', $this->foo); | |
25 | } | |
26 | ||
27 | public function nestedWithArrayCb() { | |
28 | $this->foo = 'arraycb'; | |
9099cab3 | 29 | $ac = CRM_Utils_AutoClean::with([$this, 'setFoo'], 'orig'); |
b812aefb TO |
30 | $this->assertEquals('arraycb', $this->foo); |
31 | } | |
32 | ||
33 | public function nestedWithFuncCb() { | |
34 | $this->foo = 'funccb'; | |
35 | ||
36 | $self = $this; /* php 5.3 */ | |
37 | $ac = CRM_Utils_AutoClean::with(function () use ($self /* php 5.3 */) { | |
38 | $self->foo = 'orig'; | |
39 | }); | |
40 | ||
41 | $this->assertEquals('funccb', $this->foo); | |
42 | } | |
43 | ||
44 | public function nestedSwap() { | |
9099cab3 | 45 | $ac = CRM_Utils_AutoClean::swap([$this, 'getFoo'], [$this, 'setFoo'], 'tmp'); |
b812aefb TO |
46 | $this->assertEquals('tmp', $this->foo); |
47 | } | |
48 | ||
49 | public function getFoo() { | |
50 | return $this->foo; | |
51 | } | |
52 | ||
53 | public function setFoo($value) { | |
54 | $this->foo = $value; | |
55 | } | |
56 | ||
57 | } |