Commit | Line | Data |
0567538f |
1 | sub run_tests { |
1edaf6fe |
2 | my $schema = shift; |
0567538f |
3 | |
4 | my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}; |
5 | |
6 | #warn "$dsn $user $pass"; |
7 | |
8 | plan skip_all, 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test' |
9 | unless ($dsn && $user); |
10 | |
a953d8d9 |
11 | plan tests => 5; |
0567538f |
12 | |
70fe6d6e |
13 | DBICTest::Schema->compose_connection('MySQLTest' => $dsn, $user, $pass); |
0567538f |
14 | |
a953d8d9 |
15 | my $dbh = MySQLTest->schema->storage->dbh; |
0567538f |
16 | |
17 | $dbh->do("DROP TABLE IF EXISTS artist;"); |
18 | |
103e3e03 |
19 | $dbh->do("CREATE TABLE artist (artistid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), charfield CHAR(10));"); |
0567538f |
20 | |
21 | #'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', ''); |
22 | |
843f8ecd |
23 | MySQLTest::Artist->load_components('PK::Auto'); |
0567538f |
24 | |
25 | # test primary key handling |
26 | my $new = MySQLTest::Artist->create({ name => 'foo' }); |
27 | ok($new->artistid, "Auto-PK worked"); |
28 | |
29 | # test LIMIT support |
30 | for (1..6) { |
31 | MySQLTest::Artist->create({ name => 'Artist ' . $_ }); |
32 | } |
33 | my $it = MySQLTest::Artist->search( {}, |
34 | { rows => 3, |
35 | offset => 2, |
36 | order_by => 'artistid' } |
37 | ); |
38 | is( $it->count, 3, "LIMIT count ok" ); |
39 | is( $it->next->name, "Artist 2", "iterator->next ok" ); |
40 | $it->next; |
41 | $it->next; |
42 | is( $it->next, undef, "next past end of resultset ok" ); |
43 | |
a953d8d9 |
44 | my $test_type_info = { |
45 | 'artistid' => { |
103e3e03 |
46 | 'data_type' => 'INT', |
47 | 'is_nullable' => 0, |
fc22fbac |
48 | 'size' => 11, |
49 | 'default_value' => undef, |
a953d8d9 |
50 | }, |
51 | 'name' => { |
103e3e03 |
52 | 'data_type' => 'VARCHAR', |
a953d8d9 |
53 | 'is_nullable' => 1, |
fc22fbac |
54 | 'size' => 255, |
55 | 'default_value' => undef, |
103e3e03 |
56 | }, |
57 | 'charfield' => { |
58 | 'data_type' => 'VARCHAR', |
59 | 'is_nullable' => 1, |
fc22fbac |
60 | 'size' => 10, |
61 | 'default_value' => undef, |
103e3e03 |
62 | }, |
a953d8d9 |
63 | }; |
64 | |
65 | |
faa78b0b |
66 | my $type_info = MySQLTest->schema->storage->columns_info_for('artist'); |
a953d8d9 |
67 | is_deeply($type_info, $test_type_info, 'columns_info_for - column data types'); |
68 | |
69 | |
70 | |
0567538f |
71 | # clean up our mess |
72 | $dbh->do("DROP TABLE artist"); |
73 | |
74 | } |
75 | |
76 | 1; |