AlternC/phpunit/tests/bureau/class/m_actionTest.php

255 lines
7.4 KiB
PHP
Raw Normal View History

<?php
2014-03-23 14:13:12 +00:00
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-03-13 at 15:55:58.
*/
2014-03-23 14:13:12 +00:00
class m_actionTest extends AlterncTest {
/**
* @var m_action
*/
protected $object;
2014-03-23 14:13:12 +00:00
const TEST_FILE = "/tmp/phpunit-actionTest-file";
const TEST_DIR = "/tmp/phpunit-actionTest-dir";
const TEST_UID = 999;
/**
* @return PHPUnit_Extensions_Database_DataSet_IDataSet
*/
public function getDataSet() {
$list = array(
"testPurge" => "actions-purgeable.yml",
"testGet_action" => "actions-purgeable.yml",
"testGet_old" => "actions-purgeable.yml",
"testFinish" => "actions-purgeable.yml",
"testReset_job" => "actions-began.yml",
"testGet_job" => "actions-ready.yml",
"testCancel" => "actions-purgeable.yml",
"default" => "actions-purgeable.yml"
);
if (isset($list[$this->getName()])) {
$dataset_file = $list[$this->getName()];
} else {
$dataset_file = "actions-empty.yml";
}
return parent::loadDataSet($dataset_file);
}
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
2014-03-23 14:13:12 +00:00
protected function setUp() {
parent::setUp();
$this->object = new m_action;
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
2014-03-23 14:13:12 +00:00
protected function tearDown() {
global $L_INOTIFY_DO_ACTION;
parent::tearDown();
2014-03-23 14:13:12 +00:00
// Removes flag file eventually created
if (is_file($L_INOTIFY_DO_ACTION)) {
unlink($L_INOTIFY_DO_ACTION);
}
}
/**
* @covers m_action::do_action
*/
2014-03-23 14:13:12 +00:00
public function testDo_action() {
global $L_INOTIFY_DO_ACTION;
2014-07-05 21:07:30 +00:00
file_put_contents("/tmp/log_fser", "hello world from fser");
2014-03-23 14:13:12 +00:00
$result = $this->object->do_action();
$this->assertTrue($result);
$this->assertFileExists($L_INOTIFY_DO_ACTION);
}
2014-09-09 12:52:56 +00:00
/**
* @covers m_action::chmod
*/
public function testChmod() {
$result = $this->object->chmod(self::TEST_FILE, 0777,"phpunit");
$this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
}
/**
* @covers m_action::create_file
*/
2014-03-23 14:13:12 +00:00
public function testCreate_file() {
$result = $this->object->create_file(self::TEST_FILE, "phpunit");
$this->assertTrue($result);
$this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
}
/**
* @covers m_action::create_dir
*/
2014-03-23 14:13:12 +00:00
public function testCreate_dir() {
$result = $this->object->create_dir(self::TEST_FILE);
$this->assertTrue($result);
$this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
}
/**
* @covers m_action::fix_user
*/
2014-03-23 14:13:12 +00:00
public function testFix_user() {
$result = $this->object->fix_user(self::TEST_UID);
$this->assertTrue($result);
$this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
}
/**
* @covers m_action::fix_dir
*/
2014-03-23 14:13:12 +00:00
public function testFix_dir() {
$result = $this->object->fix_dir(self::TEST_DIR);
$this->assertTrue($result);
$this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
}
/**
* @covers m_action::fix_file
*/
2014-03-23 14:13:12 +00:00
public function testFix_file() {
$result = $this->object->fix_file(self::TEST_FILE);
$this->assertTrue($result);
$this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
}
/**
* @covers m_action::del
*/
2014-03-23 14:13:12 +00:00
public function testDel() {
$result = $this->object->del(self::TEST_DIR);
$this->assertTrue($result);
$this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
}
/**
* @covers m_action::move
*/
2014-03-23 14:13:12 +00:00
public function testMove() {
$result = $this->object->move(self::TEST_FILE, self::TEST_DIR);
$this->assertTrue($result);
$this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
}
/**
* @covers m_action::archive
*/
2014-03-23 14:13:12 +00:00
public function testArchive() {
$result = $this->object->archive(self::TEST_DIR);
$this->assertTrue($result);
$this->assertEquals(1, $this->getConnection()->getRowCount('actions'));
}
/**
* @covers m_action::set
*/
2014-03-23 14:13:12 +00:00
public function testSet() {
// We test only failure, other methods cover success
$result = $this->object->set(null, null, null);
$this->assertFalse($result);
$this->assertEquals(0, $this->getConnection()->getRowCount('actions'));
}
/**
* @covers m_action::get_old
*/
2014-03-23 14:13:12 +00:00
public function testGet_old() {
$result = $this->object->get_old();
$this->assertEquals(1, $result);
}
/**
* @covers m_action::purge
*/
2014-03-23 14:13:12 +00:00
public function testPurge() {
$result = $this->object->purge();
$this->assertEquals(1, $result);
2014-03-23 14:13:12 +00:00
$expectedTable = $this->loadDataSet("actions-empty.yml")->getTable("actions");
$currentTable = $this->getConnection()->createQueryTable('actions', 'SELECT * FROM actions');
$this->assertTablesEqual($expectedTable, $currentTable);
}
/**
* @covers m_action::get_action
*/
2014-03-23 14:13:12 +00:00
public function testGet_action() {
$result = $this->object->get_action();
$this->assertTrue(is_array($result));
$this->assertCount(1, $result);
return current($result);
}
/**
* @covers m_action::begin
2014-03-23 14:13:12 +00:00
* @depends testGet_action
*/
2014-03-23 14:13:12 +00:00
public function testBegin($action) {
$result = $this->object->begin($action["id"]);
$this->assertTrue($result);
}
/**
* @covers m_action::finish
2014-03-23 14:13:12 +00:00
* @depends testGet_action
*/
2014-03-23 14:13:12 +00:00
public function testFinish($action) {
$result = $this->object->finish($action["id"]);
$this->assertTrue($result);
$queryTable = $this->getConnection()->createQueryTable(
'actions', 'SELECT * FROM actions WHERE DAY(end) = DAY(NOW())'
);
2014-03-23 14:13:12 +00:00
$row_count = $queryTable->getRowCount();
$this->assertEquals(1, $row_count);
}
/**
* @covers m_action::reset_job
2014-03-23 14:13:12 +00:00
* @depends testGet_action
*/
2014-03-23 14:13:12 +00:00
public function testReset_job($action) {
$result = $this->object->reset_job($action["id"]);
$this->assertTrue($result);
$queryTable = $this->getConnection()->createQueryTable(
'actions', 'SELECT * FROM actions WHERE end = 0 AND begin = 0 AND status = 0'
);
2014-03-23 14:13:12 +00:00
$this->assertEquals(1, $queryTable->getRowCount());
}
/**
2014-03-23 14:13:12 +00:00
*
*
* @covers m_action::get_job
*/
2014-03-23 14:13:12 +00:00
public function testGet_job() {
$result = $this->object->get_job();
$this->assertTrue(is_array($result));
$this->assertCount(1, $result);
}
/**
* @covers m_action::cancel
2014-03-23 14:13:12 +00:00
* @depends testGet_action
*/
2014-03-23 14:13:12 +00:00
public function testCancel($variable) {
$result = $this->object->cancel($variable["id"]);
$this->assertTrue($result);
$queryTable = $this->getConnection()->createQueryTable(
'actions', 'SELECT * FROM actions WHERE DAY(end) = DAY(NOW())'
);
2014-03-23 14:13:12 +00:00
$row_count = $queryTable->getRowCount();
$this->assertEquals(1, $row_count);
}
2014-03-23 14:13:12 +00:00
}