Commit graph

49 commits

Author SHA1 Message Date
721d925c58
Bug 25540: Default for branches.pickup_location must be 0
This is a try to fix failures in both
t/db_dependent/Template/Plugin/Branches.t
t/db_dependent/Koha/Biblio.t

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2020-05-23 08:34:03 +01:00
0c8d8e867b
Bug 23463: AddItem removing
We are done with AddItem, only need to log and index.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2020-03-23 09:26:30 +00:00
2075a22ed3
Bug 23463: Replace AddItem calls with Koha::Item->store
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2020-03-23 09:26:26 +00:00
9b33b8babd
Bug 23463: fix for testbuilder - set default value items.damaged=0
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2020-03-23 09:26:22 +00:00
88d699fece
Bug 24149: Skip Koha::Statistics for TestBuilder tests
As statistics does not have a PK we need to adjust the TestBuilder
tests.
Bug 18441 already exists for adding the PK.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2020-01-24 08:47:43 +00:00
af50ec6e5f
Bug 24150: Add missing koha_object[s]_class methods and skip for deletedborrowers
deletedborrowers does not have a PK, and adding it is out of the scope
of this patchset. Indeed we will have to handle possible duplication of
borrowernumber values, which does not seem trivial.
Having bug 20271 in mind, we will have to deal with this problematic
anyway later.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2020-01-07 13:44:29 +00:00
fda209ca50
Bug 24062: Make sure TestBuilder will stop generate X or other invalid category's types
To make sure this kind of random failures will not appear in a future we
are going to fix it at TestBuilder level.

Test plan:
  prove t/db_dependent/TestBuilder.t
and confirm it returns green

You could also only apply the tests against master, run them several
times and confirm that they fail most of the time.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2019-11-19 15:17:08 +00:00
18f9ed465d
Bug 21985: Fix Circulation tests when ES it set, by using build_sample_item
We should use build_sample item (from bug 21971) to create items,
otherwise we may not have a valid biblioitem and/or MARC record.

Test plan:
Set SearchEngine to ES
prove that the tests in Circulation.t now pass

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2019-10-03 10:26:22 +01:00
ce17dc90a1
Bug 18930: (RM follow-up) Restore primary key find
The find method in RefundLostItemFeeRules had been overloaded to only
support a hash being passed, however find can be called with a bare
array of primary key values (i.e. id in this case).  TestBuilder relies
on this functionality and started to fail; This patch simply restores
the original behaviour for when a single value (or array of values) is
passed.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2019-07-16 13:53:54 +01:00
52325a771a Bug 22930: Make TestBuilder->build_object explodes if parameters are wrong
This patch implements bug 15339 for build_object.
We want it to warn if the call is wrong.

Test plan:
Make sure the tests are still returning green

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

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
2019-05-17 13:26:34 +00:00
c1513a10c3 Bug 22453: Make TestBuilder generates dates taking into account the timezone
I have no idea why this only appears today but TestBuilder generates dates using DateTime->now,
which does not take into account the timezone.

It has been highlights by a failing test today on U18.
Why today whereas this patch was pushed few weeks ago?
Why U18 and not D9?

The output of the test is:
koha_1       |     #   Failed test 'With BorrowerLogs and TrackLastPatronActivity we should not spam the logs'
koha_1       |     #   at t/db_dependent/Koha/Patrons.t line 1421.
koha_1       |     #          got: '2'
koha_1       |     #     expected: '1'
koha_1       |     # Looks like you failed 1 test of 4.
koha_1       |
koha_1       | #   Failed test 'BorrowersLog tests'
koha_1       | #   at t/db_dependent/Koha/Patrons.t line 1422.
koha_1       | # Looks like you failed 1 test of 33.
koha_1       | [19:51:44] t/db_dependent/Koha/Patrons.t

Actually there are 2 logs, one for the cardnumber that is expected, and on for updated_on:
   "updated_on" : {
      "after" : "2019-03-04 21:10:00",
      "before" : "2019-03-04 18:10:00"
   }
Apart from the fact that we may want to remove this updated_on field from MODIFY,
the before/after dates differ from 3 hours.
Here it's currently 18:10 and in UTC-3

To prevent such behaviors in tests (create stuffs in the future...), we should
use our Koha::DateUtils::dt_from_string method that takes care of the timezone
used in other places of Koha.

Test plan:
prove t/db_dependent/Koha/Patrons.t
May fail without this patch.

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

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
This patch is fine in itself, but there may still be an issue around
the failing test for TrackLastPatronActivity. Reopened bug 22741.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
2019-05-07 10:57:28 +00:00
6e3da5397e Bug 21683: Remove accountlines.accountno
Test plan:
1) Play with fines, should work OK
2) Try to print receipts on fines - prinfeercpt.pl, printinvoice.pl
3) git grep getnextacctno -> no occurences
4) git grep accountno should return only:
  installer/data/mysql/atomicupdate/bug_21683_remove_column_accountno.perl
  installer/data/mysql/update22to30.pl
  misc/release_notes/release_notes_3_10_0.txt
  misc/release_notes/release_notes_3_22_0.txt
5) prove
  t/db_dependent/Accounts.t
  t/db_dependent/ILSDI_Services.t
  t/db_dependent/Stats.t
  t/db_dependent/Koha/Account.t

Rescued-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
2019-03-21 18:19:22 +00:00
d885aefcd5 Bug 22392: Reuse existing pattern
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
2019-03-11 12:36:01 +00:00
3189df3ac9 Bug 22392: Allow barcode to be passed to build_sample_item
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
2019-03-11 12:36:01 +00:00
45595334e6 Bug 20912: (QA follow-up) Fix TestBuilder
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
2019-03-07 17:29:58 +00:00
046d5e12e4 Bug 21971: TestBuilder::build_sample_item
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
2019-01-28 21:00:12 +00:00
2b76548770 Bug 21798: replace gimme_a_biblio with build_sample_biblio
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
2019-01-28 18:53:28 +00:00
9ba6125f72 Bug 21798: Unify the creation of bibliographic record in tests
Using the newly created subroutine

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

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
2019-01-28 18:53:27 +00:00
ebce48a752 Bug 21798: We need t::lib::TestBuilder::gimme_a_biblio
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

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

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
2019-01-28 18:53:26 +00:00
5e2b67d8c5 Bug 21717: Fix generation of real's values
With strict SQL modes we now have TestBuilder tests that fail randomly with:
  Out of range value for column 'tax_rate_on_receiving'
  Out of range value for column 'discount'

We are trying to insert a value that is too high for the type defined at DB level.

It happens for discount when a value > 100 is generated. The datatype is float(6,4).
From the MySQL Doc:
"""
MySQL permits a nonstandard syntax: FLOAT(M,D) or REAL(M,D) or DOUBLE PRECISION(M,D).
Here, (M,D) means than values can be stored with up to M digits in total, of which D digits may be after the decimal point.
"""

So float(6,4) does not allow 100.

To recreate easily the issue:
  use t::lib::TestBuilder;
  my $builder = t::lib::TestBuilder->new;
  $builder->build( { source => 'Aqorder', value => { discount => 100 } } )->{discount};

To make sure this patch fixes the issue you can use this script:
  use Modern::Perl;
  use t::lib::TestBuilder;
  my $builder = t::lib::TestBuilder->new;
  my ( $real, $i ) = ( 0, 0 );
  while ( $real < 100 ) {
      $real = $builder->_gen_real( { info => { size => [ 6, 4 ] } } );
      warn $i++;
  }
  warn "$i - $real";

Test plan:
0/ Does not apply this patch
1/ Run the snippet above
2/ Confirm that it fails quite quickly (constantly before 500 for me)
3/ Apply this patch
4/ Run again the script
5/ Confirm that it is stuck in an infinite loop
6/ CTRL-C :D

QA Note:
Other _gen_* subroutine may need a fix, but we will wait for them to fail
TODO:
1. Add JS check to the interface to prevent the use to enter a value > 100
2. Allow '100' as a valid value for discount (?)

Followed test plan, patch worked as described
Signed-off-by: Alex Buckley <alexbuckley@catalyst.net.nz>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
2018-11-01 19:05:46 +00:00
8bb531b530 Bug 20721: (bug 19403 follow-up) Prevent Circulation.t to fail randomly
If items.restricted == 1, CanBookBeIssued will not returned what we are
testing.

The easiest and global fix is to define a default value at TestBuilder
package level

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2018-05-07 13:15:34 -03:00
6f75f7bb9e Bug 20144: [sql_modes] Set default value for Itemtype fees in TestBuilder
Fix for:
Out of range value for column 'amount'

t/db_dependent/Circulation/Chargelostitem.t

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2018-02-13 13:58:58 -03:00
5693d255d5 Bug 20144: [sql_modes] Set default value for Acccountline in TestBuilder
Fix for:
Data too long for column 'proccode'

t/db_dependent/Accounts.t

FIXME LATER - It's a varchar(4), must be integer!

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2018-02-13 13:58:52 -03:00
1c2329b02d Bug 20144: [sql_modes] Set auth_header.marcxml to an empty string in tests
Fix for:
Field 'marcxml' doesn't have a default value

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2018-02-13 13:58:51 -03:00
42e41883a4 Bug 20144: [sql_modes] Set default value for Aqbookseller in TestBuilder
Fix for:
Out of range value for column 'tax_rate'

t/db_dependent/Koha/Acquisition/Basket.t

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2018-02-13 13:58:49 -03:00
efdf8cc964 Bug 20144: [sql_modes] Fix generated value for account_offsets.amount
Fix error:
Out of range value for column 'amount'

DBD::mysql::st execute failed: Out of range value for column 'amount' at
row 1 [for Statement "INSERT INTO `account_offsets` ( `amount`,
`debit_id`, `type`) VALUES ( ?, ?, ? )" with ParamValues:
0=7925469795795194609664.000000, 1='10', 2='Manual Debit'] at
/usr/share/perl5/DBIx/Class/Storage/DBI.pm line 1832.

7925469795795194609664.000000
=> Should be lower anyway

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2018-02-13 13:58:49 -03:00
54d13ca4af Bug 19759: Make TestBuilder generates only 2 decimals for float
For instance items.replacementprice is decimal(8,2) but more than 2 decimals are generated.

It leads to issues when we compare expected objects:

    #          got: '135623.866142537'
    #     expected: '135623.87'

Test plan:
  prove t/db_dependent/TestBuilder.t
must return green

Signed-off-by: Dominic Pichette <dominic@inlibro.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Somehow I have the feeling that we should allow more decimals sometimes
and perhaps have a number of decimals parameter or so. Think of fields
like currency or discount.
But the current issues justify this change.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-12-18 12:16:25 -03:00
e772277a8a Bug 19463: (follow-up) Cosmetic changes
String::Random version 0.26 (on Jessie) does not yet support the rand_gen
parameter (0.27 does, newest is 0.29 on CPAN now).
So alt_rand is only used in determining the size on Jessie.
That might be enough though.
Adding a documention line in this regard.

Removing the obsolete max parameter.

Note: I timed alt_rand for the creation of a new Bytes::Random::Secure
object each time. But each call is about 0.1 milliseconds. So that
should be fine.

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

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-10-18 10:08:03 -03:00
41e63c44e0 Bug 19463: Additional changes to gen_text
Use Bytes::Random::Secure instead of perl rand.
Return a string from 50 to 100% of $size.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-10-17 12:16:48 -03:00
708d02047d Bug 19463: Reduce the chance to have TestBuilder generate twice the same value
When an id is generated by TestBuilder (branchcode for instance) and the
size of the generated string is 1, we have too many chances to get
"Violation of unique constraint in Branch".

This patch increases the number of retries to 5.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Amended to make room for follow-up.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-10-17 12:16:47 -03:00
0b0059afb4 Bug 19403: Add some default values when building patrons for test
To avoid some tests to fail randomly

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-10-03 15:21:22 -03:00
8cb6ed24ff Bug 15339: [QA Follow-up] Add a warning too when source is not supplied
When you do not supply a source and add a few wrong parameters, you
would not be warned. Because build simply returns undef.
Adding a carp and a test for that situation too.

Note: In the earlier subtest 'trivial tests' build was called without
source. This now generates a warning. We just catch if there is a warning
and test the actual warning itself later on.

Test plan:
Run t/db_dependent/TestBuilder.t

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

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-09-07 13:35:06 -03:00
d60cc56613 Bug 15339: Improve parameter validation
Only value and source are allowed

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

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

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-09-07 13:35:06 -03:00
Martin Persson
ebd1039bbd Bug 15339: TestBuilder warnings (code)
Makes TestBuilder::build() alert the user when unreognized
parameters are passed, which happens when the user supplies
the column values directly, forgetting the 'value' hash.

This patch holds the code changes. Examples of the kind of
errors that it catches are in the tests (separate patch).

Sponsored-By: Halland County Library

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

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

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-09-07 13:35:06 -03:00
5bb56bf336 Bug 19003: Add a TestBuilder default for borrowers.login_attempts
Bug 18314 causes t/db/SIP/Message.t to fail (quite often) since
TestBuilder fills login_attempts with a random number. (Note: Only
when FailedLoginAttempts is non-zero.)
Trivial fix: TestBuilder should have a zero default for login_attempts.

Test plan:
Do not yet apply this patch.
Set pref FailedLoginAttempts to say 3.
Run t/db_dependent/SIP/Message.t. Might fail on the password test (CQ).
Apply this patch.
Run t/db_dependent/SIP/Message.t again. Does not fail anymore.

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

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

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-08-08 09:39:04 -03:00
ec288a50de Bug 18361: Koha::Objects->find should accept composite primary keys
Changes the $id parameter to an array. (IssuingRule has three keys.)
The build_object method in TestBuilder.pm has been adjusted to pass
multiple primary key values to find.

Also adjusted the POD section to show more clearly that we accept
the same parameters as DBIx ResultSet does.

Test plan:
Run t/db_dependent/Koha/Object.t
Run t/db_dependent/Koha/Objects.t
Run t/db_dependent/TestBuilder.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-06-16 11:52:18 -03:00
e2d14666d9 Bug 18182: Make TestBuilder capable of returning Koha::Object
This patch adds a new method to t::lib::TestBuilder so it can return
Koha::Object-derived objects. The new method is called ->build_object
and requires the plural of the target class to be passed.

'class' is a mandatory param, and a warning is raised and undef is
returned if absent.

It accepts 'value' as the original ->build() method, and that is passed as-is
to ->build().

To test:
- Apply the patches
- Run:
  $ sudo koha-shell kohadev
 k$ cd kohaclone
 k$ prove t/db_dependent/TestBuilder.t
=> SUCCESS: Tests pass!
- Sign off :-D

Sponsored-by: ByWater Solutions

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
2017-04-21 00:10:49 +00:00
cd771f3686 Bug 17726: biblioitems.marc has been removed
We will certainly have to do something with the biblio_metadata.metadata
field later.

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

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
2017-01-20 13:43:18 +00:00
41358176e1 Bug 17726: TestBuilder - Add default values
The items.more_subfields_xml is set to random data (generated by
TestBuilder), and so GetMarcBiblio does not manage to embed items (if
needed).

The error is:
  :1: parser error : Start tag expected, '<' not found

More precisely it explodes in
C4::Items::_parse_unlinked_item_subfields_from_xml when
MARC::Record->new_from_xml is called with an invalid xml

This patch adds a default values mechanism to TestBuilder to avoid
modifying all the existing calls.

Test plan:
Set SearchEngine to ElasticSearch
prove t/db_dependent/Circulation.pl
should return green with this patch

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

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
2017-01-20 13:43:17 +00:00
06fa67d75a Bug 16890: Make TestBuilder generate date for date columns (and not datetime)
TestBuilder should not generate datetime for date columns, but only for
datetime and timestamp columns.

Test plan:
Make sure the change in t/db_dependent/TestBuilder.t are consistent.
Before this patch, 1 of the 2 tests should fail.
After this patch applied, they both should pass.

Signed-off-by: Srdjan <srdjan@catalyst.net.nz>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
2016-07-15 14:59:46 +00:00
99672d1f00 Bug 16155: Composite keys in TestBuilder and more
The number of tests using TestBuilder is gradually growing. Once you
are familiar with its use, you will appreciate it and find yourself
using it when writing new tests. Although it works quite well, some details
still needs some polishing.

While looking at the handling of composite keys in TestBuilder, a number
of related points came up too. This patch finally ended up in setting
the following design goals:

[1] TB should not only look at the first column of a composite FK.
[2] TB should optionally create records for fixed FK values.
[3] TB should create a new record, never change an existing record.
[4] TB should respect auto_increment columns.
[5] Passing a hash for a foreign key should always imply a new record.
[6] Explicitly passing undef for a column should mean NULL.
[7] Add a delete method; it will replace the clear method.
[8] Simplify by removing $default_values, hash key _fk and param only_fk.

The comments below further clarify these points. Note that they refer to
the old behavior (before this patch) unless stated otherwise.

Comments for point 1
====================
Look at:
    $builder->build({
        source => 'UserPermission',
        value => {
            borrowernumber => $borrowerno,
            module_bit => { flag => 'my flag' },
            code => 'will_be_ignored',
        },
    });
Module_bit and code here are a composite FK to permissions.
TB ignores the value for the code column here and creates a record with a
randomized code.

But if we would pass the hash in the second column of this compound key like:
            borrowernumber => $borrowerno,
            module_bit => 10,
            code => { code => 'new_code' },
TB would now crash when passing the hash for code thru to DBIx.

Comments for point 2
====================
Look at:
    $builder->build({
        source => 'UserPermission',
        value => {
            borrowernumber => $borrowerno,
            module_bit => 99,
            code => 'new_super_tool',
        },
    });
TB detects a fixed value for the module_bit, continues and will crash on
DBIx if the foreign keys are not found. In this case it would be friendly
to create a missing linked record.

Comments for point 3
====================
Look at:
    $builder->build({
        source => 'Branch',
        value  => { branchcode => 'CPL' },
    });
If this branch already exists, this call would modify the branch record and
overwrite all columns with randomized values (expected or not). In any case,
it would be safer here to return undef than modifying an existing record.

Comments for point 4
====================
Look at:
    $builder->build({
        source => 'Borrower',
        value  => { borrowernumber => '123456789' },
    });
If this number would exist, we would update (as earlier). But if this
number does not exist, we would create the record. Although that is
technically possible, I would prefer to have TB respect the auto
increment property of this column.

Comments for point 5
====================
Look at:
    $builder->build({
        source => 'Item',
        value  => { homebranch => { branchcode => 'MPL' } },
    });
As discussed under point 3, we should actually not pass primary key values
if we expect to build new records. The same also holds for the deeper
(recursive) calls to build when using hashes like here for homebranch.
In this case again an existing record might be overwritten.

Comments for point 6
====================
Look at:
    $builder->build({
        source => 'Reserve',
        value => { itemnumber => undef },
    });
As you know, a reserve without an itemnumber is a biblio level hold.
Unfortunately, TB did not care about passing undefs until now. So you would
get an item level hold.
In the new situation TB will respect these explicit undefs, as long as the
corresponding foreign key column is nullable of course.

Comments for point 7
====================
This patch will allow you to delete records created by TB:
    my $patron = $builder->build({ source => 'Borrower' });
    $builder->delete({ source => 'Borrower', records => $patron });
Or:
    $builder->delete({ source => 'Borrower', records => [ $patron, ... ] });
For safety, delete requires you to provide all primary key values in the
passed hashref(s).
Deleting all records in a table via clear is no longer supported and can
still be arranged in one statement.

Comments for point 8
====================
Current use of TestBuilder reveals that $default_values and only_fk
are not really needed. The current $default_values should imo not be in the
module anyway; if you want to use it, you could still pass it to TB:
    $builder->build({ ..., value => { %defa, %your_values } });

Only_fk stops at the very last step of saving the top level record while
storing all linked records at the lower levels. Practical use is not
very obvious; it can be easily simulated by one delete statement.

The hash key _fk is now used to store all linked records one or more levels
down. It is used in a few tests to retrieve a value one level down.
Why not retrieve that one value via the database and get rid of the
whole structure?

Implementation
==============
This highlights the main changes:

The $default_value hash (with some hardcoded values for UserPermission)
is removed from the module. It was used by a test in TestBuilder.t and has
been relocated.
The value of $gen_type is returned now by sub _gen_type. (See new.)

The main change in the build method is moving the foreign keys logic to a
new subroutine _create_links. This routine now looks at all columns of a
composite FK. It checks if a linked record exists for passed values, and
it looks at NULL values.

Routine _buildColumnValues is slightly adjusted to allow for passed undef
values. The theoretically endless loop is replaced by three tries. For
composite unique constraints we only check complete sets of values.

Routine _getForeignKeys contains a check to not return the same relation
twice in case of doubled belongs_to relations in the DBIx scheme.

The eval in _storeColumnValues is removed. The autoincrement check in sub
_buildColumnValue got more priority; the handling of foreign keys has been
adjusted and a check for not-nullable columns has been added.

TEST PLAN
=========
This patch only deals with the TestBuilder module itself. In the follow-up
patches TestBuilder.t and a few other unit tests are adjusted.

[1] Do not yet apply this patch. But apply the 'OldBehavior' patch.
    Verify that all tests pass. (They cover the first six design goals.)
[2] Apply this patch. Does TestBuilder still compile (perl -c)?
[3] Run the OldBehavior test again. Do all tests fail now? This means
    that we got rid of all unwanted side-effects in the list of goals.
[4] Run some other tests that use TestBuilder. (See below.)
    Skip the following tests; a follow-up patch deals with them.
    t/db_dependent/Accounts.t
    t/db_dependent/Barcodes.t
    t/db_dependent/Circulation/AnonymiseIssueHistory.t
    t/db_dependent/Circulation/CalcFine.t
    t/db_dependent/Holds.t
    t/db_dependent/Items/MoveItemFromBiblio.t
    t/db_dependent/Koha/BiblioFrameworks.t
    t/db_dependent/Members.t
    t/db_dependent/TestBuilder.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
The following tests pass:
    t/db_dependent/Acquisition/OrderUsers.t
    t/db_dependent/Auth/haspermission.t
    t/db_dependent/Barcodes_ValueBuilder.t
    t/db_dependent/Budgets.t
    t/db_dependent/Category.t
    t/db_dependent/Circulation.t
    t/db_dependent/Circulation/GetTopIssues.t
    t/db_dependent/Circulation/IsItemIssued.t
    t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t
    t/db_dependent/Circulation/Returns.t
    t/db_dependent/Circulation/TooMany.t
    t/db_dependent/Circulation_dateexpiry.t
    t/db_dependent/Circulation_transfers.t
    t/db_dependent/CourseReserves.t
    t/db_dependent/Creators/Lib.t
    t/db_dependent/DecreaseLoanHighHolds.t
    t/db_dependent/Exporter/Record.t
    t/db_dependent/Holds/LocalHoldsPriority.t
    t/db_dependent/Holds/RevertWaitingStatus.t:
    t/db_dependent/HoldsQueue.t
    t/db_dependent/Holidays.t
    t/db_dependent/Items.t
    t/db_dependent/Items_DelItem.t
    t/db_dependent/Koha/Acquisition/Currencies.t
    t/db_dependent/Koha/Authorities.t
    t/db_dependent/Koha/BiblioFrameworks.t
    t/db_dependent/Koha/Cities.t
    t/db_dependent/Koha/Libraries.t
    t/db_dependent/Koha/Objects.t
    t/db_dependent/Koha/Patron/Categories.t
    t/db_dependent/Koha/Patron/Images.t
    t/db_dependent/Koha/Patron/Messages.t
    t/db_dependent/Koha/Patrons.t
    t/db_dependent/Koha/SMS_Providers.t
    t/db_dependent/Koha_template_plugin_Branches.t
    t/db_dependent/Letters.t
    t/db_dependent/Members/AddEnrolmentFeeIfNeeded.t
    t/db_dependent/Members/GetUpcomingMembershipExpires.t
    t/db_dependent/Members_Attributes.t
    t/db_dependent/Patron/Borrower_Debarments.t
    t/db_dependent/Patron/Borrower_Discharge.t
    t/db_dependent/Patron/Borrower_Files.t
    t/db_dependent/Ratings.t
    t/db_dependent/Reports_Guided.t
    t/db_dependent/Reserves/GetReserveFee.t
    t/db_dependent/Review.t
    t/db_dependent/Serials_2.t
    t/db_dependent/ShelfBrowser.t
    t/db_dependent/Virtualshelves.t
    t/db_dependent/api/v1/patrons.t

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
2016-05-04 13:47:57 +00:00
00900e8a51 Bug 15081: Take transaction handling out from TestBuilder
This patch removes transaction handling code from TestBuilder.
It fixes the TestBuilder.t to handle the transaction on its own.

Verify that t/db_dependent/TestBuilder.t passes.

Followed test plan, TestBuilder.t passes
Signed-off-by: Marc Véron <veron@veron.ch>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2015-11-04 12:32:56 -03:00
Jonathan Druart
f062542978 Bug 14197: TestBuilder - Remove the error on starting the transaction
DBD::mysql::db begin_work failed: Already in a transaction at /usr/share/perl5/DBIx/Class/Storage/DBI.pm line 1560.
DBIx::Class::Storage::DBI::txn_rollback(): Storage transaction_depth 0 does not match false AutoCommit of DBI::db=HASH(0xa429648), attempting ROLLBACK anyway at t/lib/TestBuilder.pm line 363

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

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@unc.edu.ar>
2015-09-16 10:40:35 -03:00
Jonathan Druart
0b6460b191 Bug 14197: Remove the warning on destroying TestBuilder objects
This module will be called by db_dependent tests, which already create a
transaction.
TestBuilder creates a new one (which is certainly useless) and the
rollback does not do anything.

To see the warning see patches on bug 14045.

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

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@unc.edu.ar>
2015-09-16 10:40:35 -03:00
Jonathan Druart
c5bc51d7d1 Bug 14256: (follow-up) Check for unique constraint to regenerate random data
There were some issues in the previous patch. This patch fixes the
following:
- rename $value with $original_value
- remove $at_least_one_constraint_failed and $values_ok which make the
  code unnecessarily complicated
- the constraints have to be checked only if no original value is passed
- _buildColumnValue created a key to the default value hashref, it broke
  the test:
    last BUILD_VALUE if exists( $default_value->{$source} );

Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
2015-06-10 12:47:07 -03:00
395304d3b5 Bug 14256: Check for unique constraint to regenerate random data
Unique constraints should be checked when creating random data. Otherwise
we get failures when the generated data already exists on the DB.

This patch takes advantage of ->unique_constraints() to do the job,
looping through all the unique constraints defined for the source.

Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
2015-06-10 12:47:06 -03:00
Jonathan Druart
ea41ef4ec9 Bug 14195: TestBuilder - A random string should not be longer than the DB field
t::lib::TestBuilder::_gen_text does not use correctly the regex and the
max parameter to generate the random string (String::Random).

This can cause future tests to fail.

http://bugs.koha-community.org/show_bug.cgi?id=14195
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>

Script tested, problem occurs, patch fixes it.
Bad number on commit subject
No errors

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
2015-05-20 11:05:27 -03:00
d8a5d2359f Bug 12603: (QA Followup)
* Fix syntax error
* Remove Schema files for nonexistant tables
* Fix circular dependency
  * Makes unpushed followup for bug 11518 unnessary

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
2015-04-20 10:08:52 -03:00
Yohann Dufour
ec50dc7fd8 Bug 12603: creating TestBuilder to simplify tests
This patch contains a new module t::lib::TestBuilder which allows to write tests easier and it contains the unit tests of this module.
For more information, see the documentation of the module.

This module uses the DBIx::Class schema and works with a clean DBIx::Class schema. In order to use it, you have to remove the current circular dependence (existing in the DBIx::Class) by applying the last patch of the bug 11518.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
2015-04-20 10:07:31 -03:00