Apache-Voodoo

 view release on metacpan or  search on metacpan

t/Table.t  view on Meta::CPAN

	}
	close(F);
}

sub table_tests {
	my $type = shift;
	my $dbh  = shift;


	my $table = Apache::Voodoo::Table->new($avt_table_config);
	is_deeply(
		$table->view({dbh => $dbh,'params' => {'id' => 1}}),
		{
          'a_text' => 'a much larger text string',
          'a_date' => '01/01/2009',
          'a_varchar' => 'a text string',
          'avt_ref_table_id' => 1,
          'a_datetime' => '2000-02-01 12:00:00',
          'a_time' => ' 1:00 PM',
		  'avt_ref_table.name' => 'First Value',
          'id' => 1
        },
		"($type) Simple view with valid id"
	);

	my $v;
	eval {
		$v = $table->view({dbh => $dbh,'params' => {'id' => 100}});
	};
	$e = Exception::Class->caught();
	isa_ok($e,"Apache::Voodoo::Exception::Application::DisplayError");

	is_deeply(
		$table->list({ dbh => $dbh }),
		{
			'PATTERN' => '',
			'SORT_PARAMS' => 'desc=1&last_sort=varchar&showall=0',
			'DATA' => [
				{
					'a_text' => 'a much larger text string',
					'a_date' => '01/01/2009',
					'a_varchar' => 'a text string',
					'avt_ref_table.name' => 'First Value',
					'a_datetime' => '2000-02-01 12:00:00',
					'avt_ref_table_id' => 1,
					'id' => 1,
					'a_time' => ' 1:00 PM'
				},
				{
					'a_text' => 'different much longer string',
					'a_date' => '01/01/2010',
					'a_varchar' => 'another text string',
					'avt_ref_table.name' => 'Second Value',
					'a_datetime' => '2010-02-01 14:00:00',
					'avt_ref_table_id' => 2,
					'id' => 2,
					'a_time' => ' 5:00 PM'
				},
				{
					'a_varchar' => 'loren ipsum solor sit amet',
					'a_text' => 'consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
					'a_date' => '03/15/2010',
					'avt_ref_table.name' => 'Fourth Value',
					'a_datetime' => '2010-01-01 12:00:00',
					'avt_ref_table_id' => 4,
					'id' => 3,
					'a_time' => ' 4:00 PM'
				}
			],
			'NUM_MATCHES' => 3,
			'LIMIT' => []
		},
		"($type) list results"
	);

	is_deeply(
		$table->list({ dbh => $dbh, params => { 'search_a_varchar' => 'a text' }}),
		{
			'PATTERN' => '',
			'SORT_PARAMS' => 'desc=1&last_sort=varchar&showall=0',
			'DATA' => [
				{
					'a_text' => 'a much larger text string',
					'a_date' => '01/01/2009',
					'a_varchar' => 'a text string',
					'avt_ref_table.name' => 'First Value',
					'a_datetime' => '2000-02-01 12:00:00',
					'avt_ref_table_id' => 1,
					'id' => 1,
					'a_time' => ' 1:00 PM'
				}
			],
			'NUM_MATCHES' => 1,
			'LIMIT' => []
		},
		"($type) list search results"
	);

}

sub probe_tests {
	my $type = shift;
	my $dbh  = shift;

	my $probe = Apache::Voodoo::Table::Probe->new($dbh);
	my $no_such;
	eval {
		$no_such = $probe->probe_table('no_such_table_as_this_in_the_db');
	};
	ok($@ =~ /doesn't exist/, "($type) no such table");

	my $config = $probe->probe_table('avt_all_types');
	my $table;
	eval {
		$table = Apache::Voodoo::Table->new($config);
	};
	my $e = Exception::Class->caught();
	ok(!$e,"($type) probe produces output that table accepts") || diag($e);
}



( run in 2.679 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )