-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path55_phrases.pl
76 lines (61 loc) · 1.82 KB
/
55_phrases.pl
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/perl
use Test::More tests => 7;
use Digest::MD5;
use strict;
use warnings;
BEGIN { use_ok( "EPrints" ); }
BEGIN { use_ok( "EPrints::Test" ); }
BEGIN { use_ok( "EPrints::Test::RepositoryLog" ); }
my $repoid = EPrints::Test::get_test_id();
my $ep = EPrints->new();
isa_ok( $ep, "EPrints", "EPrints->new()" );
if( !defined $ep ) { BAIL_OUT( "Could not obtain the EPrints System object" ); }
my $repo = $ep->repository( $repoid );
isa_ok( $repo, "EPrints::Repository", "Get a repository object ($repoid)" );
if( !defined $repo ) { BAIL_OUT( "Could not obtain the Repository object" ); }
EPrints::Test::RepositoryLog->logs; # clear logs
my $phrase = $repo->phrase( "xxx_invalid" );
my( $err ) = EPrints::Test::RepositoryLog->logs;
diag($err);
ok($err =~ /^Undefined phrase/, "invalid phrase triggers warning");
SKIP: {
skip "Set EPRINTS_LANG_DUPES=n, n >= 1", 1
unless $ENV{EPRINTS_LANG_DUPES};
my $lang = $repo->get_language;
my %phrases;
foreach my $data ($lang->_get_data, $lang->_get_repositorydata)
{
%phrases = (%phrases, %{$data->{xml}});
}
my %seen;
while(my( $id, $xml ) = each %phrases)
{
push @{$seen{Digest::MD5::md5(_phrase_toString($xml))}}, $id;
}
diag("");
diag(sprintf("%d of %d phrases are unique", scalar keys %seen, scalar keys %phrases));
my $show = $ENV{EPRINTS_LANG_DUPES};
foreach my $md5 (sort { @{$seen{$b}} <=> @{$seen{$a}} } keys %seen)
{
my $c = scalar @{$seen{$md5}};
last if $c == 1;
my $id = $seen{$md5}->[0];
my $phrase = _phrase_toString($phrases{$id});
next if $phrase eq "";
$phrase =~ s/\n/\\n/s;
$phrase =~ s/^(.{20}).+$/$1 .../s;
diag(sprintf("%d x '%s': %s", $c, $phrase, $id));
last if !$show--;
}
ok(1, "lang dupes detection");
};
sub _phrase_toString
{
my( $node ) = @_;
my $str = "";
for($node->childNodes)
{
$str .= $_->toString;
}
return $str;
}