tests/phpunit/** - Remove unnecessary "require_once" statements
[civicrm-core.git] / tests / phpunit / CRM / Utils / AutoCleanTest.php
CommitLineData
b812aefb
TO
1<?php
2
b812aefb
TO
3/**
4 * Class CRM_Utils_AutoCleanTest
5 */
6class CRM_Utils_AutoCleanTest extends CiviUnitTestCase {
7
8 public $foo;
9
10 protected function setUp() {
11 $this->useTransaction();
12 parent::setUp();
13 }
14
15 public function testAutoclean() {
16 $this->foo = 'orig';
17 $this->assertEquals('orig', $this->foo);
18 $this->nestedWithArrayCb();
19 $this->assertEquals('orig', $this->foo);
20 $this->nestedWithFuncCb();
21 $this->assertEquals('orig', $this->foo);
22 $this->nestedSwap();
23 $this->assertEquals('orig', $this->foo);
24 }
25
26 public function nestedWithArrayCb() {
27 $this->foo = 'arraycb';
28 $ac = CRM_Utils_AutoClean::with(array($this, 'setFoo'), 'orig');
29 $this->assertEquals('arraycb', $this->foo);
30 }
31
32 public function nestedWithFuncCb() {
33 $this->foo = 'funccb';
34
35 $self = $this; /* php 5.3 */
36 $ac = CRM_Utils_AutoClean::with(function () use ($self /* php 5.3 */) {
37 $self->foo = 'orig';
38 });
39
40 $this->assertEquals('funccb', $this->foo);
41 }
42
43 public function nestedSwap() {
44 $ac = CRM_Utils_AutoClean::swap(array($this, 'getFoo'), array($this, 'setFoo'), 'tmp');
45 $this->assertEquals('tmp', $this->foo);
46 }
47
48 public function getFoo() {
49 return $this->foo;
50 }
51
52 public function setFoo($value) {
53 $this->foo = $value;
54 }
55
56}