From ae490904ea670bac9b1673436502515ad15006bf Mon Sep 17 00:00:00 2001 From: alban Date: Sun, 23 Mar 2014 15:13:12 +0100 Subject: [PATCH] =?UTF-8?q?[enh]=C2=A0Adds=20bureau/m=5Faction=20testing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpunit/tests/_datasets/actions-began.yml | 10 + phpunit/tests/_datasets/actions-empty.yml | 1 + phpunit/tests/_datasets/actions-purgeable.yml | 10 + phpunit/tests/_datasets/actions-ready.yml | 10 + phpunit/tests/bureau/class/m_actionTest.php | 256 +++++++++--------- 5 files changed, 158 insertions(+), 129 deletions(-) create mode 100644 phpunit/tests/_datasets/actions-began.yml create mode 100644 phpunit/tests/_datasets/actions-empty.yml create mode 100644 phpunit/tests/_datasets/actions-purgeable.yml create mode 100644 phpunit/tests/_datasets/actions-ready.yml diff --git a/phpunit/tests/_datasets/actions-began.yml b/phpunit/tests/_datasets/actions-began.yml new file mode 100644 index 00000000..8a3f5310 --- /dev/null +++ b/phpunit/tests/_datasets/actions-began.yml @@ -0,0 +1,10 @@ +actions: + - + id: 999 + type: "file" + parameters: "phpunit" + creation: "2000-01-01 00:00:00" + begin: "2020-12-31 23:59:58" + end: "2020-12-31 23:59:59" + user: "phpunit" + status: 0 \ No newline at end of file diff --git a/phpunit/tests/_datasets/actions-empty.yml b/phpunit/tests/_datasets/actions-empty.yml new file mode 100644 index 00000000..2c752aa4 --- /dev/null +++ b/phpunit/tests/_datasets/actions-empty.yml @@ -0,0 +1 @@ +actions: \ No newline at end of file diff --git a/phpunit/tests/_datasets/actions-purgeable.yml b/phpunit/tests/_datasets/actions-purgeable.yml new file mode 100644 index 00000000..b0f79635 --- /dev/null +++ b/phpunit/tests/_datasets/actions-purgeable.yml @@ -0,0 +1,10 @@ +actions: + - + id: 999 + type: "file" + parameters: "phpunit" + creation: "2000-01-01 00:00:00" + begin: "0000-00-00 00:00:00" + end: "0000-00-00 00:00:00" + user: "phpunit" + status: 0 \ No newline at end of file diff --git a/phpunit/tests/_datasets/actions-ready.yml b/phpunit/tests/_datasets/actions-ready.yml new file mode 100644 index 00000000..d7d8ac34 --- /dev/null +++ b/phpunit/tests/_datasets/actions-ready.yml @@ -0,0 +1,10 @@ +actions: + - + id: 999 + type: "file" + parameters: "phpunit" + creation: "2000-01-01 00:00:00" + begin: "2020-12-31 23:59:58" + end: "0000-00-00 00:00:00" + user: "phpunit" + status: 0 \ No newline at end of file diff --git a/phpunit/tests/bureau/class/m_actionTest.php b/phpunit/tests/bureau/class/m_actionTest.php index 578bbdbc..1de07cdf 100644 --- a/phpunit/tests/bureau/class/m_actionTest.php +++ b/phpunit/tests/bureau/class/m_actionTest.php @@ -1,20 +1,47 @@ "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. */ - protected function setUp() - { + protected function setUp() { parent::setUp(); $this->object = new m_action; } @@ -23,224 +50,195 @@ class m_actionTest extends PHPUnit_Framework_TestCase * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() - { + protected function tearDown() { + global $L_INOTIFY_DO_ACTION; parent::tearDown(); + // Removes flag file eventually created + if (is_file($L_INOTIFY_DO_ACTION)) { + unlink($L_INOTIFY_DO_ACTION); + } } /** * @covers m_action::do_action - * @todo Implement testDo_action(). */ - public function testDo_action() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + public function testDo_action() { + global $L_INOTIFY_DO_ACTION; + $result = $this->object->do_action(); + $this->assertTrue($result); + $this->assertFileExists($L_INOTIFY_DO_ACTION); } /** * @covers m_action::create_file - * @todo Implement testCreate_file(). */ - public function testCreate_file() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + 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 - * @todo Implement testCreate_dir(). */ - public function testCreate_dir() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + 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 - * @todo Implement testFix_user(). */ - public function testFix_user() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + 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 - * @todo Implement testFix_dir(). */ - public function testFix_dir() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + 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 - * @todo Implement testFix_file(). */ - public function testFix_file() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + 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 - * @todo Implement testDel(). */ - public function testDel() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + public function testDel() { + $result = $this->object->del(self::TEST_DIR); + $this->assertTrue($result); + $this->assertEquals(1, $this->getConnection()->getRowCount('actions')); } /** * @covers m_action::move - * @todo Implement testMove(). */ - public function testMove() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + 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 - * @todo Implement testArchive(). */ - public function testArchive() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + public function testArchive() { + $result = $this->object->archive(self::TEST_DIR); + $this->assertTrue($result); + $this->assertEquals(1, $this->getConnection()->getRowCount('actions')); } /** * @covers m_action::set - * @todo Implement testSet(). */ - public function testSet() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + 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 - * @todo Implement testGet_old(). */ - public function testGet_old() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + public function testGet_old() { + $result = $this->object->get_old(); + $this->assertEquals(1, $result); } /** * @covers m_action::purge - * @todo Implement testPurge(). */ - public function testPurge() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + public function testPurge() { + $result = $this->object->purge(); + $this->assertEquals(0, $result); + $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 - * @todo Implement testGet_action(). */ - public function testGet_action() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + 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 - * @todo Implement testBegin(). + * @depends testGet_action */ - public function testBegin() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + public function testBegin($action) { + $result = $this->object->begin($action["id"]); + $this->assertTrue($result); } /** * @covers m_action::finish - * @todo Implement testFinish(). + * @depends testGet_action */ - public function testFinish() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' + 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())' ); + $row_count = $queryTable->getRowCount(); + $this->assertEquals(1, $row_count); } /** * @covers m_action::reset_job - * @todo Implement testReset_job(). + * @depends testGet_action */ - public function testReset_job() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' + 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' ); + $this->assertEquals(1, $queryTable->getRowCount()); } /** + * + * * @covers m_action::get_job - * @todo Implement testGet_job(). */ - public function testGet_job() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + public function testGet_job() { + $result = $this->object->get_job(); + $this->assertTrue(is_array($result)); + $this->assertCount(1, $result); } /** * @covers m_action::cancel - * @todo Implement testCancel(). + * @depends testGet_action */ - public function testCancel() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' + 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())' ); + $row_count = $queryTable->getRowCount(); + $this->assertEquals(1, $row_count); } + }