From cb96f899b2e71f5aada69bfb84b2f6f6a80e80e7 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Thu, 25 Apr 2019 13:52:17 +0000 Subject: [PATCH] Add Tests for ratelimitfile and ratelimit git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5232 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- Tests/ratelimitTest.php | 14 ++++++++ Tests/ratelimitfileTest.php | 71 +++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 Tests/ratelimitTest.php create mode 100644 Tests/ratelimitfileTest.php diff --git a/Tests/ratelimitTest.php b/Tests/ratelimitTest.php new file mode 100644 index 0000000..c7a5b72 --- /dev/null +++ b/Tests/ratelimitTest.php @@ -0,0 +1,14 @@ + + */ + +/** Test the ratelimit.php file */ +class test_ratelimit extends PHPUnit_Framework_TestCase +{ + public function test_ratelimit0 () + { + $ratelimit = new ratelimit (); + } +} diff --git a/Tests/ratelimitfileTest.php b/Tests/ratelimitfileTest.php new file mode 100644 index 0000000..0afb2ee --- /dev/null +++ b/Tests/ratelimitfileTest.php @@ -0,0 +1,71 @@ + + */ + +/** Test the ratelimitfile.php file */ +class test_ratelimitfile extends PHPUnit_Framework_TestCase +{ + public function test_ratelimitfile0 () + { + exec ("rm -rf /tmp/testDFWratelimit"); + } + + public function test_ratelimitfile1 () + { + // Create one non ratelimited entry + $ratelimitfile = new ratelimitfile (); + $ratelimitfile->storageDir = "/tmp/testDFWratelimit"; + $res = $ratelimitfile->set ("TOTO"); + $this->assertSame (true, $res); + } + + public function test_ratelimitfile2 () + { + // Too much entries + $ratelimitfile = new ratelimitfile (); + $ratelimitfile->storageDir = "/tmp/testDFWratelimit"; + $ratelimitfile->set ("TOTO"); + $ratelimitfile->set ("TOTO"); + $ratelimitfile->set ("TOTO"); + $ratelimitfile->set ("TOTO"); + $ratelimitfile->set ("TOTO"); + $ratelimitfile->set ("TOTO"); + $ratelimitfile->set ("TOTO"); + $ratelimitfile->set ("TOTO"); + $ratelimitfile->set ("TOTO"); + $res = $ratelimitfile->set ("TOTO"); + $this->assertSame (false, $res); + } + + public function test_ratelimitfile3 () + { + // Del the ratelimited entry + $ratelimitfile = new ratelimitfile (); + $ratelimitfile->storageDir = "/tmp/testDFWratelimit"; + $res = $ratelimitfile->del ("TOTO"); + $this->assertSame (true, $res); + } + + public function test_ratelimitfile4 () + { + // Create one non ratelimited entry + $ratelimitfile = new ratelimitfile (); + $ratelimitfile->storageDir = "/tmp/testDFWratelimit"; + $res = $ratelimitfile->set ("TOTO"); + $this->assertSame (true, $res); + } + + public function test_ratelimitfile5 () + { + // Clean expired entries + sleep (2); + $ratelimitfile = new ratelimitfile (); + $ratelimitfile->unittime = 1; + $ratelimitfile->storageDir = "/tmp/testDFWratelimit"; + $ratelimitfile->clean (); + $res = count (glob ("/tmp/testDFWratelimit/*")); + $this->assertSame (0, $res); + } +}