Corrected test plan for t/11mysql.t
[dbsrgits/DBIx-Class.git] / t / 11mysql.t
1 use lib qw(lib t/lib);
2 use DBICTest::Schema;
3
4 use Test::More;
5
6 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/};
7
8 #warn "$dsn $user $pass";
9
10 plan skip_all, 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test'
11   unless ($dsn && $user);
12
13 plan tests => 4;
14
15 DBICTest::Schema->compose_connection('MySQLTest' => $dsn, $user, $pass);
16
17 my $dbh = MySQLTest::Artist->storage->dbh;
18
19 $dbh->do("DROP TABLE IF EXISTS artist;");
20
21 $dbh->do("CREATE TABLE artist (artistid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255));");
22
23 #'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', '');
24
25 MySQLTest::Artist->load_components('PK::Auto::MySQL');
26
27 # test primary key handling
28 my $new = MySQLTest::Artist->create({ name => 'foo' });
29 ok($new->artistid, "Auto-PK worked");
30
31 # test LIMIT support
32 for (1..6) {
33     MySQLTest::Artist->create({ name => 'Artist ' . $_ });
34 }
35 my $it = MySQLTest::Artist->search( {},
36     { rows => 3,
37       offset => 2,
38       order_by => 'artistid' }
39 );
40 is( $it->count, 3, "LIMIT count ok" );
41 is( $it->next->name, "Artist 2", "iterator->next ok" );
42 $it->next;
43 $it->next;
44 is( $it->next, undef, "next past end of resultset ok" );
45
46 # clean up our mess
47 $dbh->do("DROP TABLE artist");
48
49 1;