Alternc  3.2
Alternc logiel libre pour l'hébergement
 All Data Structures Namespaces Files Functions Variables Pages
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;
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  $result = $this->object->do_action();
68  $this->assertTrue($result);
69  $this->assertFileExists($L_INOTIFY_DO_ACTION);
70  }
71 
72  /**
73  * @covers m_action::create_file
74  */
75  public function testCreate_file() {
76  $result = $this->object->create_file(self::TEST_FILE, "phpunit");
77  $this->assertTrue($result);
78  $this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
79  }
80 
81  /**
82  * @covers m_action::create_dir
83  */
84  public function testCreate_dir() {
85  $result = $this->object->create_dir(self::TEST_FILE);
86  $this->assertTrue($result);
87  $this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
88  }
89 
90  /**
91  * @covers m_action::fix_user
92  */
93  public function testFix_user() {
94  $result = $this->object->fix_user(self::TEST_UID);
95  $this->assertTrue($result);
96  $this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
97  }
98 
99  /**
100  * @covers m_action::fix_dir
101  */
102  public function testFix_dir() {
103  $result = $this->object->fix_dir(self::TEST_DIR);
104  $this->assertTrue($result);
105  $this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
106  }
107 
108  /**
109  * @covers m_action::fix_file
110  */
111  public function testFix_file() {
112  $result = $this->object->fix_file(self::TEST_FILE);
113  $this->assertTrue($result);
114  $this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
115  }
116 
117  /**
118  * @covers m_action::del
119  */
120  public function testDel() {
121  $result = $this->object->del(self::TEST_DIR);
122  $this->assertTrue($result);
123  $this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
124  }
125 
126  /**
127  * @covers m_action::move
128  */
129  public function testMove() {
130  $result = $this->object->move(self::TEST_FILE, self::TEST_DIR);
131  $this->assertTrue($result);
132  $this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
133  }
134 
135  /**
136  * @covers m_action::archive
137  */
138  public function testArchive() {
139  $result = $this->object->archive(self::TEST_DIR);
140  $this->assertTrue($result);
141  $this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
142  }
143 
144  /**
145  * @covers m_action::set
146  */
147  public function testSet() {
148  // We test only failure, other methods cover success
149  $result = $this->object->set(null, null, null);
150  $this->assertFalse($result);
151  $this->assertEquals(0, $this->getConnection()->getRowCount('actions'));
152  }
153 
154  /**
155  * @covers m_action::get_old
156  */
157  public function testGet_old() {
158  $result = $this->object->get_old();
159  $this->assertEquals(1, $result);
160  }
161 
162  /**
163  * @covers m_action::purge
164  */
165  public function testPurge() {
166  $result = $this->object->purge();
167  $this->assertEquals(0, $result);
168  $expectedTable = $this->loadDataSet("actions-empty.yml")->getTable("actions");
169  $currentTable = $this->getConnection()->createQueryTable('actions', 'SELECT * FROM actions');
170  $this->assertTablesEqual($expectedTable, $currentTable);
171  }
172 
173  /**
174  * @covers m_action::get_action
175  */
176  public function testGet_action() {
177  $result = $this->object->get_action();
178  $this->assertTrue(is_array($result));
179  $this->assertCount(1, $result);
180  return current($result);
181  }
182 
183  /**
184  * @covers m_action::begin
185  * @depends testGet_action
186  */
187  public function testBegin($action) {
188  $result = $this->object->begin($action["id"]);
189  $this->assertTrue($result);
190  }
191 
192  /**
193  * @covers m_action::finish
194  * @depends testGet_action
195  */
196  public function testFinish($action) {
197  $result = $this->object->finish($action["id"]);
198  $this->assertTrue($result);
199  $queryTable = $this->getConnection()->createQueryTable(
200  'actions', 'SELECT * FROM actions WHERE DAY(end) = DAY(NOW())'
201  );
202  $row_count = $queryTable->getRowCount();
203  $this->assertEquals(1, $row_count);
204  }
205 
206  /**
207  * @covers m_action::reset_job
208  * @depends testGet_action
209  */
210  public function testReset_job($action) {
211  $result = $this->object->reset_job($action["id"]);
212  $this->assertTrue($result);
213  $queryTable = $this->getConnection()->createQueryTable(
214  'actions', 'SELECT * FROM actions WHERE end = 0 AND begin = 0 AND status = 0'
215  );
216  $this->assertEquals(1, $queryTable->getRowCount());
217  }
218 
219  /**
220  *
221  *
222  * @covers m_action::get_job
223  */
224  public function testGet_job() {
225  $result = $this->object->get_job();
226  $this->assertTrue(is_array($result));
227  $this->assertCount(1, $result);
228  }
229 
230  /**
231  * @covers m_action::cancel
232  * @depends testGet_action
233  */
234  public function testCancel($variable) {
235  $result = $this->object->cancel($variable["id"]);
236  $this->assertTrue($result);
237  $queryTable = $this->getConnection()->createQueryTable(
238  'actions', 'SELECT * FROM actions WHERE DAY(end) = DAY(NOW())'
239  );
240  $row_count = $queryTable->getRowCount();
241  $this->assertEquals(1, $row_count);
242  }
243 
244 }