View | Details | Raw Unified | Return to bug 13849
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tt (-6 / +10 lines)
Lines 44-50 Link Here
44
	return true;
44
	return true;
45
	}
45
	}
46
	// to check if the data are correctly entered.
46
	// to check if the data are correctly entered.
47
	function Check(ff) {
47
    $(document).ready(function() {
48
    $('form[name="Aform"]').on('submit', function(e) {
49
        var ff = this;
48
	    var ok=0;
50
	    var ok=0;
49
		var _alertString=_("Form not submitted because of the following problem(s)");
51
		var _alertString=_("Form not submitted because of the following problem(s)");
50
		_alertString +="\n-------------------------------------------------------------------\n\n";
52
		_alertString +="\n-------------------------------------------------------------------\n\n";
Lines 79-94 Link Here
79
                }
81
                }
80
		if(ff.enrolmentperioddate.value && ff.enrolmentperiod.value){
82
		if(ff.enrolmentperioddate.value && ff.enrolmentperiod.value){
81
			document.getElementById('enrolmentmessage').className = "error";
83
			document.getElementById('enrolmentmessage').className = "error";
82
			return false;
84
            e.preventDefault();
83
		}
85
		}
84
		
86
		
85
		if (ok) { // if there is a problem
87
		if (ok) { // if there is a problem
86
		    alert(_alertString);
88
		    alert(_alertString);
87
                    return false;
89
            e.preventDefault();
88
                }
90
                }
89
                // if all is good
91
                // if all is good
90
		ff.submit();
92
    });
91
	}
93
    });
92
	//]]>
94
	//]]>
93
</script>
95
</script>
94
<style type="text/css">#enrolmentmessage.hint { display : none; }</style>
96
<style type="text/css">#enrolmentmessage.hint { display : none; }</style>
Lines 253-259 Link Here
253
        [% INCLUDE 'messaging-preference-form.inc' %]
255
        [% INCLUDE 'messaging-preference-form.inc' %]
254
      </fieldset>
256
      </fieldset>
255
    [% END %]
257
    [% END %]
256
	<fieldset class="action"><input type="button" value="Save" onclick="Check(this.form);" /> </fieldset>
258
    <fieldset class="action">
259
        <input type="submit" value="Save" />
260
    </fieldset>
257
	</form>
261
	</form>
258
262
259
[% END %]
263
[% END %]
(-)a/t/db_dependent/cucumber/features/0-category.feature (+21 lines)
Line 0 Link Here
1
Feature: Create a category
2
 As a librarian
3
 In order to create a patron
4
 I want to create a new patron category
5
6
 Background:
7
   Given I am logged in as a library admin
8
9
 Scenario: Go to the new patron category page
10
  Given I have gone to the patron category list page
11
  When I have clicked on the newcategory link
12
  Then I should see the new patron category page
13
14
 Scenario: Create a patron category
15
   Given I have gone to the new patron category page
16
   When I have filled the field categorycode with "test_cat"
17
   And I have filled the field description with "test cat description"
18
   And I have filled the field enrolmentperiod with "12"
19
   And I have filled the field category_type with "A"
20
   And I have clicked on the submit button
21
   Then The patron category "TEST_CAT" should exist
(-)a/t/db_dependent/cucumber/features/1-patron.feature (+22 lines)
Line 0 Link Here
1
Feature: Create a patron
2
 As a librarian
3
 I want to create a new patron
4
5
 Background:
6
   Given I am logged in as a library admin
7
8
   # FIXME No id on the link
9
   # Scenario: Go to the new patron page
10
   #  Given I have gone to the patron home page
11
   #  When I have clicked on the "New patron" link
12
   #  Then I should see the new patron page
13
14
 Scenario: Create a patron
15
   Given I have gone to the new patron page
16
   When I have filled the field surname with "test_patron_surname"
17
   And I have filled the field cardnumber with "4242424242"
18
   And I have filled the field userid with "test_username"
19
   And I have filled the field password with "password"
20
   And I have filled the field password2 with "password"
21
   And I have clicked on the submit button
22
   Then The patron "test_username" should have been created
(-)a/t/db_dependent/cucumber/features/step_definitions/0-category_steps.pl (+13 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
use Test::More;
4
use Test::BDD::Cucumber::StepFile;
5
use Selenium::Remote::Driver;
6
use t::lib::Cucumber;
7
8
Then qr{The patron category "(.*)" should exist}, sub {
9
    S->{patron_category_code} = $1;
10
    my @e = S->{driver}->find_elements('//td');
11
    my $elt = S->{driver}->find_element('//td[contains(.,"'.S->{patron_category_code}.'")]');
12
    is( ref($elt), 'Selenium::Remote::WebElement' );
13
};
(-)a/t/db_dependent/cucumber/features/step_definitions/1-patron_steps.pl (+13 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
use Test::More;
4
use Test::BDD::Cucumber::StepFile;
5
use C4::Context;
6
7
Then qr(The patron "(.*)" should have been created), sub {
8
    S->{userid} = $1;
9
    my $dbh = C4::Context->dbh;
10
    my $exists = $dbh->selectcol_arrayref(q|
11
        SELECT COUNT(*) FROM borrowers where userid = ?|, {}, S->{userid} );
12
    is( $exists->[0], 1, 'The patron '.S->{userid}.' should exist' );
13
};
(-)a/t/db_dependent/cucumber/features/step_definitions/basic_steps.pl (+75 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
use Test::More;
4
use Test::BDD::Cucumber::StepFile;
5
use Selenium::Remote::Driver;
6
use t::lib::Cucumber::Form;
7
use t::lib::Cucumber::Paths;
8
use C4::Context;
9
10
our $login = 'koha';
11
our $password = 'koha';
12
13
# FIXME The body ids don't depend on the action we are doing (list or add views)
14
#our $body_ids = {
15
#    'new patron category' => 'admin/admin-home.pl',
16
#};
17
18
19
Given qr{I am logged in as a library admin}, sub {
20
    my $driver = Selenium::Remote::Driver->new({remote_server_addr => 'localhost'});
21
    my $mainpage = t::lib::Cucumber::Paths::get('mainpage');
22
    $driver->get($mainpage);
23
    t::lib::Cucumber::Form::fill( $driver, { userid => $login, password => $password } );
24
    my $login_button = $driver->find_element('//input[@id="submit"]');
25
    $login_button->submit();
26
    S->{driver} = $driver;
27
};
28
29
Given qr{I have gone to the (.*) page}, sub {
30
    my $page = $1;
31
    my $path = t::lib::Cucumber::Paths::get( $page );
32
    S->{driver}->get( $path );
33
};
34
35
When qr(I have clicked on the submit button), sub {
36
    my $button;
37
    # Try to find submit button
38
    eval {
39
         $button = S->{driver}->find_element('//fieldset[@class="action"]/input[@type="submit"]');
40
    };
41
    eval {
42
        $button = S->{driver}->find_element('//input[@id="submit"]');
43
    } unless $button;
44
    eval {
45
        $button = S->{driver}->find_element('//input[@type="submit"]');
46
    } unless $button;
47
 
48
    die "There is no submit button on this page" unless $button;
49
    $button->click;
50
};
51
52
When qr(I have clicked on the (\S+) (\S+)), sub {
53
    my $id = $1;
54
    my $type = $2;
55
56
    my $tag;
57
    if ( $type eq 'link' ) {
58
        $tag = 'a';
59
    }
60
    S->{driver}->find_element('//'.$tag.'[@id="'.$id.'"]')->click;
61
};
62
63
When qr{I have filled the field (\S+) with "(.*)"}, sub {
64
    my ($id, $value) = ($1, $2);
65
    t::lib::Cucumber::Form::fill( S->{driver}, { $id => $value } );
66
};
67
68
Then qr{I should see the (.*) page}, sub {
69
    my $page = $1;
70
    my $title;
71
    if ( $page eq "new patron category" ) {
72
        $title = 'New category';
73
    }
74
    like( S->{driver}->get_title(), qr($title) );
75
};
(-)a/t/db_dependent/cucumber/features/step_definitions/hooks_steps.pl (+5 lines)
Line 0 Link Here
1
After sub {
2
    my $dbh = C4::Context->dbh;
3
    $dbh->do(q|DELETE FROM categories WHERE categorycode = ?|, {}, S->{patron_category_code});
4
    $dbh->do(q|DELETE FROM borrowers WHERE userid=?|, {}, S->{patron_userid});
5
};
(-)a/t/db_dependent/cucumber/tests.t (+23 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use Test::More;
3
4
# This will find step definitions and feature files in the directory you point
5
# it at below
6
use Test::BDD::Cucumber::Loader;
7
8
# This harness prints out nice TAP
9
use Test::BDD::Cucumber::Harness::TestBuilder;
10
11
# Load a directory with Cucumber files in it. It will recursively execute any
12
# file matching .*_steps.pl as a Step file, and .*\.feature as a feature file.
13
# The features are returned in @features, and the executor is created with the
14
# step definitions loaded.
15
my ( $executor, @features ) = Test::BDD::Cucumber::Loader->load(
16
       'features/' );
17
18
# Create a Harness to execute against. TestBuilder harness prints TAP
19
my $harness = Test::BDD::Cucumber::Harness::TestBuilder->new({});
20
21
# For each feature found, execute it, using the Harness to print results
22
$executor->execute( $_, $harness ) for @features;
23
done_testing;
(-)a/t/lib/Cucumber.pm (+3 lines)
Line 0 Link Here
1
package t::lib::Cucumber;
2
3
1;
(-)a/t/lib/Cucumber/Form.pm (+16 lines)
Line 0 Link Here
1
package t::lib::Cucumber::Form;
2
3
sub fill {
4
    my ( $driver, $values ) = @_;
5
    while ( my ( $id, $value ) = each %$values ) {
6
        my $element = $driver->find_element('//*[@id="'.$id.'"]');
7
        my $tag = $element->get_tag_name();
8
        if ( $tag eq 'input' ) {
9
            $driver->find_element('//input[@id="'.$id.'"]')->send_keys($value);
10
        } elsif ( $tag eq 'select' ) {
11
            $driver->find_element('//select[@id="'.$id.'"]/option[@value="'.$value.'"]')->click;
12
        }
13
    }
14
}
15
16
1;
(-)a/t/lib/Cucumber/Paths.pm (-1 / +19 lines)
Line 0 Link Here
0
- 
1
package t::lib::Cucumber::Paths;
2
3
use C4::Context;
4
5
sub get {
6
    my ( $page ) = @_;
7
    my $base_url = 'http://'.C4::Context->preference("staffClientBaseURL")."/cgi-bin/koha/";
8
    my $paths = {
9
        'mainpage' => $base_url.'mainpage.pl?logout.x=1',
10
        'patron category list' => $base_url.'admin/categorie.pl',
11
        'new patron category' => $base_url.'admin/categorie.pl?op=add_form',
12
        'patron home' => $base_url.'members/members-home.pl',
13
        'new patron' => $base_url.'members/memberentry.pl?op=add&category_type=A'
14
    };
15
    die "Invalid path" unless exists $paths->{$page};
16
    return $paths->{$page};
17
}
18
19
1;

Return to bug 13849