#!perl -wT
BEGIN {
use_ok(
'Mango::Catalyst::Controller::Form'
);
use_ok(
'Mango::Catalyst::Plugin::I18N'
);
use_ok(
'Mango::Exception'
,
':try'
);
*Mango::Test::Catalyst::localize
= \
&Mango::Catalyst::Plugin::I18N::localize
;
*Mango::Test::Catalyst::languages
= \
&Mango::Catalyst::Plugin::I18N::languages
;
};
{
my
$var
= catdir(
't'
,
'var'
);
my
$dir
= catdir(
$var
,
qw/root forms form/
);
mkdir
(
$var
)
unless
-d
$var
;
mkpath(
$dir
);
copy(catfile(
qw/share forms admin products create.yml/
),
$dir
);
copy(catfile(
qw/share forms admin products edit.yml/
),
$dir
);
};
{
my
$c
= Mango::Test::Catalyst->new({
config
=> {
home
=> catdir(
qw/t var/
)
}
});
my
$controller
=
$c
->controller(
'Form'
);
my
$form
=
$controller
->form(
'edit'
);
isa_ok(
$form
,
'Mango::Form'
);
is(refaddr
$form
, refaddr
$controller
->form(
'form/edit'
));
ok(!
$form
->submitted);
$c
->request->{
'_submitted_products_edit'
} = 1;
ok(
$form
->submitted);
my
$results
=
$form
->validate;
isa_ok(
$results
,
'Mango::Form::Results'
);
ok(!
$results
->success);
is_deeply(
$results
->errors, [
'ID_NOT_BLANK'
,
'SKU_NOT_BLANK'
,
'NAME_NOT_BLANK'
,
'DESCRIPTION_NOT_BLANK'
,
'PRICE_NOT_BLANK'
]);
$form
=
$controller
->form(
'create'
);
isa_ok(
$form
,
'Mango::Form'
);
is(refaddr
$form
, refaddr
$controller
->form(
'form/create'
));
ok(!
$form
->submitted);
$c
->request->{
'_submitted_products_create'
} = 1;
ok(
$form
->submitted);
$results
=
$form
->validate;
isa_ok(
$results
,
'Mango::Form::Results'
);
ok(!
$results
->success);
is_deeply(
$results
->errors, [
'SKU_NOT_BLANK'
,
'NAME_NOT_BLANK'
,
'DESCRIPTION_NOT_BLANK'
,
'PRICE_NOT_BLANK'
]);
$c
->action->
reverse
(
'form/edit'
);
delete
$c
->request->{
'_submitted_products_edit'
};
$form
=
$controller
->form;
isa_ok(
$form
,
'Mango::Form'
);
is(refaddr
$form
, refaddr
$controller
->form(
'form/edit'
));
ok(!
$form
->submitted);
$c
->request->{
'_submitted_products_edit'
} = 1;
ok(
$form
->submitted);
$results
=
$form
->validate;
isa_ok(
$results
,
'Mango::Form::Results'
);
ok(!
$results
->success);
is_deeply(
$results
->errors, [
'ID_NOT_BLANK'
,
'SKU_NOT_BLANK'
,
'NAME_NOT_BLANK'
,
'DESCRIPTION_NOT_BLANK'
,
'PRICE_NOT_BLANK'
]);
rmtree(catdir(
't'
,
'var'
));
};
{
Mango::Catalyst::Controller::Form->config(
form_directory
=> catdir(
qw/share forms admin products/
)
);
my
$c
= Mango::Test::Catalyst->new({
config
=> {
home
=> catdir(
qw/t var/
)
}
});
my
$controller
=
$c
->controller(
'Form'
);
my
$form
=
$controller
->form(
'edit'
);
isa_ok(
$form
,
'Mango::Form'
);
is(refaddr
$form
, refaddr
$controller
->form(
'form/edit'
));
ok(!
$form
->submitted);
$c
->request->{
'_submitted_products_edit'
} = 1;
ok(
$form
->submitted);
my
$results
=
$form
->validate;
isa_ok(
$results
,
'Mango::Form::Results'
);
ok(!
$results
->success);
is_deeply(
$results
->errors, [
'ID_NOT_BLANK'
,
'SKU_NOT_BLANK'
,
'NAME_NOT_BLANK'
,
'DESCRIPTION_NOT_BLANK'
,
'PRICE_NOT_BLANK'
]);
$form
=
$controller
->form(
'create'
);
isa_ok(
$form
,
'Mango::Form'
);
is(refaddr
$form
, refaddr
$controller
->form(
'form/create'
));
ok(!
$form
->submitted);
$c
->request->{
'_submitted_products_create'
} = 1;
ok(
$form
->submitted);
$results
=
$form
->validate;
isa_ok(
$results
,
'Mango::Form::Results'
);
ok(!
$results
->success);
is_deeply(
$results
->errors, [
'SKU_NOT_BLANK'
,
'NAME_NOT_BLANK'
,
'DESCRIPTION_NOT_BLANK'
,
'PRICE_NOT_BLANK'
]);
$c
->action->
reverse
(
'form/edit'
);
delete
$c
->request->{
'_submitted_products_edit'
};
$form
=
$controller
->form;
isa_ok(
$form
,
'Mango::Form'
);
is(refaddr
$form
, refaddr
$controller
->form(
'form/edit'
));
ok(!
$form
->submitted);
$c
->request->{
'_submitted_products_edit'
} = 1;
ok(
$form
->submitted);
$results
=
$form
->validate;
isa_ok(
$results
,
'Mango::Form::Results'
);
ok(!
$results
->success);
is_deeply(
$results
->errors, [
'ID_NOT_BLANK'
,
'SKU_NOT_BLANK'
,
'NAME_NOT_BLANK'
,
'DESCRIPTION_NOT_BLANK'
,
'PRICE_NOT_BLANK'
]);
};