Alternc  latest
Alternc logiel libre pour l'hébergement
m_actionTest.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-03-13 at 15:55:58.
5  */
6 class m_actionTest extends AlterncTest {
7 
8  /**
9  * @var m_action
10  */
11  protected $object;
12 
13  const TEST_FILE = "/tmp/phpunit-actionTest-file";
14  const TEST_DIR = "/tmp/phpunit-actionTest-dir";
15  const TEST_UID = 999;
16 
17  /**
18  * @return PHPUnit_Extensions_Database_DataSet_IDataSet
19  */
20  public function getDataSet() {
21 
22  $list = array(
23  "testPurge" => "actions-purgeable.yml",
24  "testGet_action" => "actions-purgeable.yml",
25  "testGet_old" => "actions-purgeable.yml",
26  "testFinish" => "actions-purgeable.yml",
27  "testReset_job" => "actions-began.yml",
28  "testGet_job" => "actions-ready.yml",
29  "testCancel" => "actions-purgeable.yml",
30  "default" => "actions-purgeable.yml"
31  );
32  if (isset($list[$this->getName()])) {
33  $dataset_file = $list[$this->getName()];
34  } else {
35  $dataset_file = "actions-empty.yml";
36  }
37  return parent::loadDataSet($dataset_file);
38  }
39 
40  /**
41  * Sets up the fixture, for example, opens a network connection.
42  * This method is called before a test is executed.
43  */
44  protected function setUp() {
45  parent::setUp();
46  $this->object = new m_action;
47  }
48 
49  /**
50  * Tears down the fixture, for example, closes a network connection.
51  * This method is called after a test is executed.
52  */
53  protected function tearDown() {
54  global $L_INOTIFY_DO_ACTION;
55  parent::tearDown();
56  // Removes flag file eventually created
57  if (is_file($L_INOTIFY_DO_ACTION)) {
58  unlink($L_INOTIFY_DO_ACTION);
59  }
60  }
61 
62  /**
63  * @covers m_action::do_action
64  */
65  public function testDo_action() {
66  global $L_INOTIFY_DO_ACTION;
67  file_put_contents("/tmp/log_fser", "hello world from fser");
68  $result = $this->object->do_action();
69  $this->assertTrue($result);
70  $this->assertFileExists($L_INOTIFY_DO_ACTION);
71  }
72 
73  /**
74  * @covers m_action::chmod
75  */
76  public function testChmod() {
77  $result = $this->object->chmod(self::TEST_FILE, 0777,"phpunit");
78  $this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
79 
80  }
81 
82  /**
83  * @covers m_action::create_file
84  */
85  public function testCreate_file() {
86  $result = $this->object->create_file(self::TEST_FILE, "phpunit");
87  $this->assertTrue($result);
88  $this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
89  }
90 
91  /**
92  * @covers m_action::create_dir
93  */
94  public function testCreate_dir() {
95  $result = $this->object->create_dir(self::TEST_FILE);
96  $this->assertTrue($result);
97  $this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
98  }
99 
100  /**
101  * @covers m_action::fix_user
102  */
103  public function testFix_user() {
104  $result = $this->object->fix_user(self::TEST_UID);
105  $this->assertTrue($result);
106  $this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
107  }
108 
109  /**
110  * @covers m_action::fix_dir
111  */
112  public function testFix_dir() {
113  $result = $this->object->fix_dir(self::TEST_DIR);
114  $this->assertTrue($result);
115  $this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
116  }
117 
118  /**
119  * @covers m_action::fix_file
120  */
121  public function testFix_file() {
122  $result = $this->object->fix_file(self::TEST_FILE);
123  $this->assertTrue($result);
124  $this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
125  }
126 
127  /**
128  * @covers m_action::del
129  */
130  public function testDel() {
131  $result = $this->object->del(self::TEST_DIR);
132  $this->assertTrue($result);
133  $this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
134  }
135 
136  /**
137  * @covers m_action::move
138  */
139  public function testMove() {
140  $result = $this->object->move(self::TEST_FILE, self::TEST_DIR);
141  $this->assertTrue($result);
142  $this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
143  }
144 
145  /**
146  * @covers m_action::archive
147  */
148  public function testArchive() {
149  $result = $this->object->archive(self::TEST_DIR);
150  $this->assertTrue($result);
151  $this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
152  }
153 
154  /**
155  * @covers m_action::set
156  */
157  public function testSet() {
158  // We test only failure, other methods cover success
159  $result = $this->object->set(null, null, null);
160  $this->assertFalse($result);
161  $this->assertEquals(0, $this->getConnection()->getRowCount('actions'));
162  }
163 
164  /**
165  * @covers m_action::get_old
166  */
167  public function testGet_old() {
168  $result = $this->object->get_old();
169  $this->assertEquals(1, $result);
170  }
171 
172  /**
173  * @covers m_action::purge
174  */
175  public function testPurge() {
176  $result = $this->object->purge();
177  $this->assertEquals(1, $result);
178  $expectedTable = $this->loadDataSet("actions-empty.yml")->getTable("actions");
179  $currentTable = $this->getConnection()->createQueryTable('actions', 'SELECT * FROM actions');
180  $this->assertTablesEqual($expectedTable, $currentTable);
181  }
182 
183  /**
184  * @covers m_action::get_action
185  */
186  public function testGet_action() {
187  $result = $this->object->get_action();
188  $this->assertTrue(is_array($result));
189  $this->assertCount(1, $result);
190  return current($result);
191  }
192 
193  /**
194  * @covers m_action::begin
195  * @depends testGet_action
196  */
197  public function testBegin($action) {
198  $result = $this->object->begin($action["id"]);
199  $this->assertTrue($result);
200  }
201 
202  /**
203  * @covers m_action::finish
204  * @depends testGet_action
205  */
206  public function testFinish($action) {
207  $result = $this->object->finish($action["id"]);
208  $this->assertTrue($result);
209  $queryTable = $this->getConnection()->createQueryTable(
210  'actions', 'SELECT * FROM actions WHERE DAY(end) = DAY(NOW())'
211  );
212  $row_count = $queryTable->getRowCount();
213  $this->assertEquals(1, $row_count);
214  }
215 
216  /**
217  * @covers m_action::reset_job
218  * @depends testGet_action
219  */
220  public function testReset_job($action) {
221  $result = $this->object->reset_job($action["id"]);
222  $this->assertTrue($result);
223  $queryTable = $this->getConnection()->createQueryTable(
224  'actions', 'SELECT * FROM actions WHERE end = 0 AND begin = 0 AND status = 0'
225  );
226  $this->assertEquals(1, $queryTable->getRowCount());
227  }
228 
229  /**
230  *
231  *
232  * @covers m_action::get_job
233  */
234  public function testGet_job() {
235  $result = $this->object->get_job();
236  $this->assertTrue(is_array($result));
237  $this->assertCount(1, $result);
238  }
239 
240  /**
241  * @covers m_action::cancel
242  * @depends testGet_action
243  */
244  public function testCancel($variable) {
245  $result = $this->object->cancel($variable["id"]);
246  $this->assertTrue($result);
247  $queryTable = $this->getConnection()->createQueryTable(
248  'actions', 'SELECT * FROM actions WHERE DAY(end) = DAY(NOW())'
249  );
250  $row_count = $queryTable->getRowCount();
251  $this->assertEquals(1, $row_count);
252  }
253 
254 }
loadDataSet($fileList)
Definition: AlterncTest.php:31
This class manage actions to be performed on the file system on behalf of alternc Classes It primary ...
Definition: m_action.php:28
Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-03-13 at 15:55:58.
Definition: m_actionTest.php:6
testFix_dir()
@covers m_action::fix_dir
testDo_action()
@covers m_action::do_action
testChmod()
@covers m_action::chmod
testGet_action()
@covers m_action::get_action
testCreate_file()
@covers m_action::create_file
testDel()
@covers m_action::del
testSet()
@covers m_action::set
testGet_job()
@covers m_action::get_job
testCancel($variable)
@covers m_action::cancel @depends testGet_action
tearDown()
Tears down the fixture, for example, closes a network connection.
testPurge()
@covers m_action::purge
testCreate_dir()
@covers m_action::create_dir
testFix_user()
@covers m_action::fix_user
testFix_file()
@covers m_action::fix_file
testGet_old()
@covers m_action::get_old
testMove()
@covers m_action::move
testArchive()
@covers m_action::archive
setUp()
Sets up the fixture, for example, opens a network connection.
testFinish($action)
@covers m_action::finish @depends testGet_action
testBegin($action)
@covers m_action::begin @depends testGet_action
testReset_job($action)
@covers m_action::reset_job @depends testGet_action
$list
Show a list of all found log files for an account and allow to see / tail / download them.
Definition: logs_list.php:30