CustomTest.pm 2.92 KB
Newer Older
1 2 3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
#
5 6
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
7 8 9 10 11

# This module represents a test with custom URL parameters.
# Tests like this are specified in CUSTOM_SEARCH_TESTS in
# Bugzilla::Test::Search::Constants.
package Bugzilla::Test::Search::CustomTest;
12
use base qw(Bugzilla::Test::Search::FieldTest);
13 14 15 16 17 18 19 20 21 22 23 24 25 26
use strict;
use warnings;

use Bugzilla::Test::Search::FieldTest;
use Bugzilla::Test::Search::OperatorTest;

use Storable qw(dclone);

###############
# Constructor #
###############

sub new {
  my ($class, $test, $search_test) = @_;
27
  bless {raw_test => dclone($test), search_test => $search_test}, $class;
28 29 30 31 32 33 34
}

#############
# Accessors #
#############

sub search_test { return $_[0]->{search_test} }
35 36
sub name        { return 'Custom: ' . $_[0]->test->{name} }
sub test        { return $_[0]->{raw_test} }
37 38

sub operator_test { die "unimplemented" }
39 40 41 42
sub field_object  { die "unimplemented" }
sub main_value    { die "unimplenmented" }
sub test_value    { die "unimplemented" }

43
# Custom tests don't use transforms.
44 45
sub transformed_value_was_equal {0}

46
sub debug_value {
47 48 49 50 51 52 53 54
  my ($self) = @_;
  my $string = '';
  my $params = $self->search_params;
  foreach my $param (keys %$params) {
    $string .= $param . "=" . $params->{$param} . '&';
  }
  chop($string);
  return $string;
55 56 57
}

# The tests we know are broken for this operator/field combination.
58
sub _known_broken                      { return {} }
59 60 61
sub contains_known_broken              { return undef }
sub search_known_broken                { return undef }
sub field_not_yet_implemented          { return undef }
62 63 64 65 66 67 68 69 70
sub invalid_field_operator_combination { return undef }

#########################################
# Accessors: Bugzilla::Search Arguments #
#########################################

# Converts the f, o, v rows into f0, o0, v0, etc. and translates
# the values appropriately.
sub search_params {
71 72
  my ($self) = @_;

73
  my %params  = %{$self->test->{top_params} || {}};
74 75 76 77 78
  my $counter = 0;
  foreach my $row (@{$self->test->{params}}) {
    $row->{v} = $self->translate_value($row) if exists $row->{v};
    foreach my $key (keys %$row) {
      $params{"${key}$counter"} = $row->{$key};
79
    }
80 81
    $counter++;
  }
82

83
  return \%params;
84 85 86
}

sub translate_value {
87 88 89 90 91 92 93 94
  my ($self, $row) = @_;
  my $as_test = {field => $row->{f}, operator => $row->{o}, value => $row->{v}};
  my $operator_test
    = new Bugzilla::Test::Search::OperatorTest($row->{o}, $self->search_test);
  my $field = Bugzilla::Field->check($row->{f});
  my $field_test
    = new Bugzilla::Test::Search::FieldTest($operator_test, $field, $as_test);
  return $field_test->translated_value;
95 96 97
}

sub search_columns {
98 99
  my ($self) = @_;
  return ['bug_id', @{$self->test->{columns} || []}];
100 101 102
}

1;