From 590223878ebf4a81583428ac61fb6fc9fe3d54b3 Mon Sep 17 00:00:00 2001 From: alban Date: Thu, 27 Mar 2014 16:03:34 +0100 Subject: [PATCH] [fix] #1545 htaccess files --- bureau/admin/hta_del.php | 9 +++--- phpunit/tests/bureau/class/m_htaTest.php | 35 ++++++++++++++++++++---- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/bureau/admin/hta_del.php b/bureau/admin/hta_del.php index 52ffe975..48a7e9ea 100644 --- a/bureau/admin/hta_del.php +++ b/bureau/admin/hta_del.php @@ -35,11 +35,12 @@ reset($_POST); while (list($key,$val)=each($_POST)) { if (substr($key,0,4)=="del_") { // Effacement du dossier $val - $r=$hta->DelDir($val); - if (!$r) { - $error.=$err->errstr()."
"; +// $r=$hta->DelDir($val); + $return = $hta->DelDir($val); + if (!$return) { + $error.= $err->errstr()."
"; } else { - $error.=sprintf(_("The protected folder %s has been successfully unprotected"),$val)."
"; + $error.= sprintf(_("The protected folder %s has been successfully unprotected"),$val)."
"; } } } diff --git a/phpunit/tests/bureau/class/m_htaTest.php b/phpunit/tests/bureau/class/m_htaTest.php index fe2a6a68..25ecbda6 100644 --- a/phpunit/tests/bureau/class/m_htaTest.php +++ b/phpunit/tests/bureau/class/m_htaTest.php @@ -9,6 +9,9 @@ class m_htaTest extends PHPUnit_Framework_TestCase */ protected $object; + const PATH_HTACCESS = "/tmp/.htaccess"; + const PATH_HTPASSWD = "/tmp/.htpasswd"; + /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. @@ -16,6 +19,10 @@ class m_htaTest extends PHPUnit_Framework_TestCase protected function setUp() { parent::setUp(); + touch(self::PATH_HTACCESS); + touch(self::PATH_HTPASSWD); + $file_content = "AuthUserFile \"/tmp/.htpasswd\"\nAuthName \"Restricted area\"\nAuthType Basic\nrequire valid-user\n"; + file_put_contents(self::PATH_HTACCESS,$file_content); $this->object = new m_hta; } @@ -26,6 +33,12 @@ class m_htaTest extends PHPUnit_Framework_TestCase protected function tearDown() { parent::tearDown(); + if(file_exists(self::PATH_HTACCESS)){ + unlink (self::PATH_HTACCESS); + } + if(file_exists(self::PATH_HTPASSWD)){ + unlink (self::PATH_HTPASSWD); + } } /** @@ -114,14 +127,26 @@ class m_htaTest extends PHPUnit_Framework_TestCase /** * @covers m_hta::DelDir - * @todo Implement testDelDir(). */ public function testDelDir() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $result = $this->object->DelDir("/tmp",TRUE); + $this->assertTrue($result); + $this->assertFileNotExists(self::PATH_HTACCESS); + $this->assertFileNotExists(self::PATH_HTPASSWD); + } + + /** + * @covers m_hta::DelDir + */ + public function testDelDirNotEmpty() + { + file_put_contents(self::PATH_HTACCESS, "\nphpunit", FILE_APPEND); + $result = $this->object->DelDir("/tmp",TRUE); + $this->assertTrue($result); + $this->assertFileExists(self::PATH_HTACCESS); + $this->assertFileNotExists(self::PATH_HTPASSWD); + $this->assertTrue("phpunit" == trim(file_get_contents(self::PATH_HTACCESS))); } /**