BZ-Client

 view release on metacpan or  search on metacpan

t/600product.t  view on Meta::CPAN

                get_enterable_products  => 1,
                get_accessible_products => 1,
                get_selectable_products => 1,
                name                    => 'testing-funky-hyphens',
                description             => 'Hyphen testing product'
            },
        },
    },

);

sub TestGetList {
    my ( $method, $allowEmpty ) = @_;
    my $client = $tester->client();
    my $ids;
  SKIP: {
        skip( "BZ::Client::Product cannot do method: $method ?", 1 )
          unless ok( BZ::Client::Product->can($method),
            "BZ::Client::Product implements method: $method" );

        eval {
            $ids = BZ::Client::Product->$method($client);
            $client->logout();
        };

        if ($@) {
            my $err = $@;
            my $msg;
            if ( ref($err) eq 'BZ::Client::Exception' ) {
                $msg =
                  'Error: '
                  . (
                    defined( $err->http_code() ) ? $err->http_code() : 'undef' )
                  . ', '
                  . (
                    defined( $err->xmlrpc_code() )
                    ? $err->xmlrpc_code()
                    : 'undef'
                  )
                  . ', '
                  . ( defined( $err->message() ) ? $err->message() : 'undef' );
            }

            else {
                $msg = "Error $err";
            }
            ok( 0, 'No errors: ' . $method );
            diag($msg);
            return;
        }
        else {
            ok( 1, 'No errors: ' . $method );
        }

        if ( !$ids or ref $ids ne 'ARRAY' or ( !$allowEmpty and !@$ids ) ) {
            diag q/No product ID's returned./;
            return;
        }

        {
            is_deeply( # this may prove too fragile, as changes on landfil will break it
                [ sort @$ids ],
                [
                    sort grep {
                        $quirks{ $tester->{version} }{products}{$_}{$method}
                    } keys %{ $quirks{ $tester->{version} }{products} }
                ],
                'IDs returned correctly for: ' . $method
            ) or diag $method . ', ID: ' . join( ', ', sort @$ids );
        }

        return $ids

    }
}

sub TestGet {
    my $client = $tester->client();

    my $ids;
    my $products;
    eval {
        $ids = BZ::Client::Product->get_accessible_products($client);
        $products = BZ::Client::Product->get( $client, { ids => $ids } );
        $client->logout();
    };

    if ($@) {
        my $err = $@;
        my $msg;
        if ( ref $err eq 'BZ::Client::Exception' ) {
            $msg =
                'Error: '
              . ( defined( $err->http_code() ) ? $err->http_code() : 'undef' )
              . ', '
              . (
                defined( $err->xmlrpc_code() ) ? $err->xmlrpc_code() : 'undef' )
              . ', '
              . ( defined( $err->message() ) ? $err->message() : 'undef' );
        }
        else {
            $msg = "Error $err\n";
        }
        ok( 0, 'No errors: get' );
        diag($msg);
        return;
    }
    else {
        ok( 1, 'No errors: get' );
    }

    my $return;

    # careful of the list context, scalar () forces it to be a number
    ok(
        scalar @$ids == scalar(
            grep {
                my $id = $_;
                grep { $_->id() eq $id } @$products
            } @$ids
        ),



( run in 2.318 seconds using v1.01-cache-2.11-cpan-364913b4093 )