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