File: unique_values.t

package info (click to toggle)
request-tracker4 4.4.7%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 62,888 kB
  • sloc: javascript: 130,444; perl: 65,442; sh: 1,350; makefile: 480; python: 37; php: 30
file content (57 lines) | stat: -rw-r--r-- 2,044 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use warnings;
use strict;

use RT::Test tests => undef;

{
    diag "testing freeform single cf";
    my $unique_single = RT::Test->load_or_create_custom_field(
        Name         => 'unique single',
        Type         => 'FreeformSingle',
        Queue        => 0,
        UniqueValues => 1,
    );
    ok($unique_single->UniqueValues, 'unique values for this CF');

    my @tests = (
        ['foo', 'bar'], # Content
        [('foo' x 256), ('bar' x 256)], # LargeContent
    );

    for (@tests) {
        my ($foo, $bar) = @$_;
        my $alpha = RT::Test->create_ticket( Subject => 'test unique values alpha', Queue => 'General' );
        my $beta = RT::Test->create_ticket( Subject => 'test unique values beta', Queue => 'General' );

        my ( $ret, $msg ) =
          $alpha->AddCustomFieldValue( Field => $unique_single, Value => $foo );
        ok( $ret, $msg );
        is( $alpha->FirstCustomFieldValue($unique_single), $foo, 'value is foo' );

        ( $ret, $msg ) =
          $beta->AddCustomFieldValue( Field => $unique_single, Value => $foo );
        ok( !$ret, "can't reuse the OCFV 'foo'");
        like($msg, qr/ is not a unique value/);
        is( $beta->FirstCustomFieldValue($unique_single), undef, 'no value since it was a duplicate' );

        ( $ret, $msg ) =
          $alpha->AddCustomFieldValue( Field => $unique_single, Value => $bar );
        ok( $ret, $msg );

        is( $alpha->FirstCustomFieldValue($unique_single), $bar, 'value is now bar' );

        ( $ret, $msg ) =
          $beta->AddCustomFieldValue( Field => $unique_single, Value => $foo );
        ok( $ret, "can reuse foo since alpha switched away");
        is( $beta->FirstCustomFieldValue($unique_single), $foo, 'now beta has foo' );

        ( $ret, $msg ) =
          $alpha->AddCustomFieldValue( Field => $unique_single, Value => $foo );
        ok( !$ret, "alpha can't switch back to foo since beta uses it");

        is( $alpha->FirstCustomFieldValue($unique_single), $bar, 'value is still bar' );
    }
}

done_testing;