Bug 21233: Unit tests
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 16 Aug 2018 09:54:53 +0000 (06:54 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 14 Sep 2018 17:54:13 +0000 (17:54 +0000)
This patch adds tests for the required password-related exceptions. The
tests verify the stringified version of the exceptions.

To test:
- Apply this patch
- Run:
  $ kshell
 k$ prove t/Koha/Exceptions.t
=> FAIL: Exceptions not implemented, tests fail!

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

t/Koha/Exceptions.t

index c306d31..7ecc115 100644 (file)
@@ -17,7 +17,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 1;
+use Test::More tests => 2;
 use Test::Exception;
 
 subtest 'Koha::Exceptions::Object::FKConstraint tests' => sub {
@@ -41,3 +41,23 @@ subtest 'Koha::Exceptions::Object::FKConstraint tests' => sub {
     is( "$@", 'Manual message exception', 'Exception not stringified if manually passed' );
 };
 
+subtest 'Koha::Exceptions::Password tests' => sub {
+
+    plan tests => 5;
+
+    use_ok('Koha::Exceptions::Password');
+
+    throws_ok
+        { Koha::Exceptions::Password::TooShort->throw( length => 4, min_length => 5 ); }
+        'Koha::Exceptions::Password::TooShort',
+        'Exception is thrown :-D';
+
+    # stringify the exception
+    is( "$@", 'Password length (4) is shorter than required (5)', 'Exception stringified correctly' );
+
+    throws_ok
+        { Koha::Exceptions::Password::TooShort->throw( "Manual message exception" ) }
+        'Koha::Exceptions::Password::TooShort',
+        'Exception is thrown :-D';
+    is( "$@", 'Manual message exception', 'Exception not stringified if manually passed' );
+};