[Rt-commit] rt branch 4.4/validate-cf-unique-values-on-web-create created. rt-4.4.5-40-g3a6a0d3bdb
BPS Git Server
git at git.bestpractical.com
Fri Apr 29 20:14:48 UTC 2022
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".
The branch, 4.4/validate-cf-unique-values-on-web-create has been created
at 3a6a0d3bdb0d4730e44d136dd2a9b4c511bc1d35 (commit)
- Log -----------------------------------------------------------------
commit 3a6a0d3bdb0d4730e44d136dd2a9b4c511bc1d35
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sat Apr 2 06:00:02 2022 +0800
Test validation of "unique values" custom fields on web UI
diff --git a/t/web/basic.t b/t/web/basic.t
index b72d8633ca..d795c2743f 100644
--- a/t/web/basic.t
+++ b/t/web/basic.t
@@ -95,4 +95,86 @@ is(
$agent->title_is('Create a new ticket in foo&bar');
}
+diag "test custom field unique values";
+{
+ my $queue = RT::Test->load_or_create_queue( Name => 'General' );
+ ok $queue && $queue->id, 'loaded or created queue';
+
+ my $cf = RT::Test->load_or_create_custom_field(
+ Name => 'External ID',
+ Queue => 'General',
+ Type => 'FreeformSingle',
+ UniqueValues => 1,
+ );
+ my $cf_id = $cf->Id;
+
+ $agent->goto_create_ticket($queue);
+ $agent->submit_form_ok(
+ {
+ form_name => 'TicketCreate',
+ fields => { Subject => 'Test unique values', "Object-RT::Ticket--CustomField-$cf_id-Value" => '123' },
+ },
+ 'Create ticket with cf value 123',
+ );
+
+ $agent->text_like(qr/Ticket \d+ created in queue/);
+ my $ticket = RT::Test->last_ticket;
+ is( $ticket->FirstCustomFieldValue($cf), 123, 'CF value is set' );
+
+ $agent->goto_create_ticket($queue);
+ $agent->submit_form_ok(
+ {
+ form_name => 'TicketCreate',
+ fields => { Subject => 'Test unique values', "Object-RT::Ticket--CustomField-$cf_id-Value" => '123' },
+ },
+ 'Create ticket with cf value 123',
+ );
+ $agent->text_contains("'123' is not a unique value");
+ $agent->text_unlike(qr/Ticket \d+ created in queue/);
+
+ $agent->submit_form_ok(
+ {
+ form_name => 'TicketCreate',
+ fields => { Subject => 'Test unique values', "Object-RT::Ticket--CustomField-$cf_id-Value" => '456' },
+ },
+ 'Create ticket with cf value 456'
+ );
+ $agent->text_like(qr/Ticket \d+ created in queue/);
+ $ticket = RT::Test->last_ticket;
+ is( $ticket->FirstCustomFieldValue($cf), 456, 'CF value is set' );
+ my $ticket_id = $ticket->Id;
+
+ $agent->follow_link_ok( { text => 'Basics' } );
+ $agent->submit_form_ok(
+ {
+ form_name => 'TicketModify',
+ fields => { "Object-RT::Ticket-$ticket_id-CustomField-$cf_id-Value" => '123' },
+ },
+ 'Update ticket with cf value 123'
+
+ );
+ $agent->text_contains("'123' is not a unique value");
+ $agent->text_lacks( 'External ID 456 changed to 123', 'Can not change to an existing value' );
+
+ $agent->submit_form_ok(
+ {
+
+ form_name => 'TicketModify',
+ fields => { "Object-RT::Ticket-$ticket_id-CustomField-$cf_id-Value" => '789' },
+ },
+ 'Update ticket with cf value 789'
+ );
+ $agent->text_contains( 'External ID 456 changed to 789', 'Changed cf to a new value' );
+
+ $agent->submit_form_ok(
+ {
+
+ form_name => 'TicketModify',
+ fields => { "Object-RT::Ticket-$ticket_id-CustomField-$cf_id-Value" => '456' },
+ },
+ 'Update ticket with cf value 456'
+ );
+ $agent->text_contains( 'External ID 789 changed to 456', 'Changed cf back to old value' );
+}
+
done_testing;
commit 3dd61d4f3c3e92c74718603ab000cb82566305de
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sat Apr 30 04:08:07 2022 +0800
Move query-builder related tests to its own test file
diff --git a/t/web/basic.t b/t/web/basic.t
index 4e3dbe749b..b72d8633ca 100644
--- a/t/web/basic.t
+++ b/t/web/basic.t
@@ -88,44 +88,6 @@ is(
"got a file of the correct size ($file)",
);
-#
-# XXX: hey-ho, we have these tests in t/web/query-builder
-# TODO: move everything about QB there
-
-my $response = $agent->get($url."Search/Build.html");
-ok( $response->is_success, "Fetched " . $url."Search/Build.html" );
-
-# Parsing TicketSQL
-#
-# Adding items
-
-# set the first value
-ok($agent->form_name('BuildQuery'));
-$agent->field("AttachmentField", "Subject");
-$agent->field("AttachmentOp", "LIKE");
-$agent->field("ValueOfAttachment", "aaa");
-$agent->submit("AddClause");
-
-# set the next value
-ok($agent->form_name('BuildQuery'));
-$agent->field("AttachmentField", "Subject");
-$agent->field("AttachmentOp", "LIKE");
-$agent->field("ValueOfAttachment", "bbb");
-$agent->submit("AddClause");
-
-ok($agent->form_name('BuildQuery'));
-
-# get the query
-my $query = $agent->current_form->find_input("Query")->value;
-# strip whitespace from ends
-$query =~ s/^\s*//g;
-$query =~ s/\s*$//g;
-
-# collapse other whitespace
-$query =~ s/\s+/ /g;
-
-is ($query, "Subject LIKE 'aaa' AND Subject LIKE 'bbb'");
-
{
my $queue = RT::Test->load_or_create_queue( Name => 'foo&bar' );
$agent->goto_create_ticket( $queue->id );
diff --git a/t/web/query_builder.t b/t/web/query_builder.t
index 94a167041a..341350e9f9 100644
--- a/t/web/query_builder.t
+++ b/t/web/query_builder.t
@@ -41,6 +41,29 @@ sub selectedClauses {
return [ @clauses ];
}
+diag "add the first condition";
+{
+ ok $agent->form_name('BuildQuery'), "found the form once";
+ $agent->field("AttachmentField", "Subject");
+ $agent->field("AttachmentOp", "LIKE");
+ $agent->field("ValueOfAttachment", "aaa");
+ $agent->submit("AddClause");
+ is getQueryFromForm($agent), "Subject LIKE 'aaa'";
+}
+
+diag "set the next condition";
+{
+ ok($agent->form_name('BuildQuery'), "found the form again");
+ $agent->field("AttachmentField", "Subject");
+ $agent->field("AttachmentOp", "LIKE");
+ $agent->field("ValueOfAttachment", "bbb");
+ $agent->submit("AddClause");
+ is getQueryFromForm($agent), "Subject LIKE 'aaa' AND Subject LIKE 'bbb'",
+ 'correct query';
+}
+
+$response = $agent->get($url."Search/Build.html?NewQuery=1");
+ok( $response->is_success, "Fetched new query builder page" );
diag "add the first condition";
{
commit cd3aa133b6127a22f0bf5560f1e384847b7989a0
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sat Apr 2 05:26:19 2022 +0800
Validate "unique values" custom fields correctly on web create
As $Object->id is undef and the generated "!= NULL" SQL doesn't return
anything, all values could pass the unique check previously.
diff --git a/share/html/Elements/ValidateCustomFields b/share/html/Elements/ValidateCustomFields
index d079100b59..8e04cb11f8 100644
--- a/share/html/Elements/ValidateCustomFields
+++ b/share/html/Elements/ValidateCustomFields
@@ -129,7 +129,7 @@ while ( my $CF = $CustomFields->Next ) {
$existing->LimitToCustomField($CF->Id);
$existing->LimitToEnabled;
$existing->Limit(FIELD => 'ObjectType', VALUE => ref($Object));
- $existing->Limit(FIELD => 'ObjectId', VALUE => $Object->id, OPERATOR => '!=');
+ $existing->Limit(FIELD => 'ObjectId', VALUE => $Object->id || 0, OPERATOR => '!=');
$existing->Limit(
FIELD => 'Content',
VALUE => $value,
-----------------------------------------------------------------------
hooks/post-receive
--
rt
More information about the rt-commit
mailing list