Skip to content

Commit

Permalink
Merge pull request #2441 from reosarevok/document-tests-7
Browse files Browse the repository at this point in the history
Improve test documentation (VII): Shared tests (Aliases)
  • Loading branch information
reosarevok committed Jun 13, 2022
2 parents 8b4d5b7 + 64c12ba commit 2980adc
Show file tree
Hide file tree
Showing 28 changed files with 1,250 additions and 527 deletions.
14 changes: 7 additions & 7 deletions admin/sql/InsertTestData.sql
Expand Up @@ -61,9 +61,9 @@ INSERT INTO release_group (id, gid, name, artist_credit, type) VALUES
INSERT INTO release_group (id, gid, name, artist_credit, type) VALUES
(4, '7348f3a0-454e-11de-8a39-0800200c9a66', 'Test RG 2', 4, 1);

INSERT INTO release_group_alias (id, name, sort_name, release_group, edits_pending)
VALUES (1, 'Test RG 1 Alias 1', 'Test RG 1 Alias Sort Name 1', 3, 0),
(2, 'Test RG 1 Alias 2', 'Test RG 1 Alias Sort Name 2', 3, 0);
INSERT INTO release_group_alias (id, name, sort_name, release_group, type, edits_pending)
VALUES (1, 'Test RG 1 Alias 1', 'Test RG 1 Alias Sort Name 1', 3, 1, 0),
(2, 'Test RG 1 Alias 2', 'Test RG 1 Alias Sort Name 2', 3, 2, 0);

INSERT INTO work (id, gid, name, type) VALUES
(1, '745c079d-374e-4436-9448-da92dedef3ce', 'Dancing Queen', 1);
Expand Down Expand Up @@ -143,8 +143,8 @@ INSERT INTO release_group (id, gid, name, artist_credit, type) VALUES
INSERT INTO release (id, gid, name, artist_credit, release_group, status, barcode) VALUES (2, 'f205627f-b70a-409d-adbe-66289b614e80', 'Aerial', 3, 2, 1, '0094634396028');
INSERT INTO release_country (release, country, date_year, date_month, date_day) VALUES (2, 221, 2005, 11, 7);

INSERT INTO release_alias (id, name, sort_name, release, edits_pending)
VALUES (1, 'Ærial', 'Ærial', 2, 0);
INSERT INTO release_alias (id, name, sort_name, release, type, edits_pending)
VALUES (1, 'Ærial', 'Ærial', 2, 1, 0);

INSERT INTO release (id, gid, name, artist_credit, release_group, status, barcode) VALUES (3, '9b3d9383-3d2a-417f-bfbb-56f7c15f075b', 'Aerial', 3, 2, 1, '0827969777220');
INSERT INTO release_country (release, country, date_year, date_month, date_day) VALUES (3, 222, 2005, 11, 8);
Expand Down Expand Up @@ -195,8 +195,8 @@ INSERT INTO recording (id, gid, name, artist_credit, length) VALUES
INSERT INTO recording (id, gid, name, artist_credit, length) VALUES
(17, '1539ac10-5081-4469-b8f2-c5896132724e', 'Aerial', 3, 472880);

INSERT INTO recording_alias (id, name, sort_name, recording, edits_pending)
VALUES (1, 'King of the Mt.', 'King of the Mt.', 2, 0);
INSERT INTO recording_alias (id, name, sort_name, recording, type, edits_pending)
VALUES (1, 'King of the Mt.', 'King of the Mt.', 2, 1, 0);

INSERT INTO track (id, gid, medium, position, number, recording, name, artist_credit, length) VALUES (4, '39164965-d4bd-49e6-925d-72026ad03dce', 3, 1, 1, 2, 'King of the Mountain', 3, 293720);
INSERT INTO track (id, gid, medium, position, number, recording, name, artist_credit, length) VALUES (5, '82edb036-4097-484d-ac8a-cf4971451ca0', 3, 2, 2, 3, 'π', 3, 369680);
Expand Down
10 changes: 7 additions & 3 deletions t/lib/t/MusicBrainz/Server/Controller/Area/Aliases.pm
@@ -1,17 +1,18 @@
package t::MusicBrainz::Server::Controller::Area::Aliases;
use Test::Routine;
use MusicBrainz::Server::Test qw( html_ok page_test_jsonld );
use utf8;

with 't::Mechanize', 't::Context';

=head2 Test description
This test checks whether area aliases are correctly listed in the JSON-LD
of an area's alias page.
This test checks whether area aliases are correctly listed on the area
alias page, both on the site itself and on the JSON-LD data.
=cut

test 'Area alias appears on JSON-LD' => sub {
test 'Area alias appears on alias page content and on JSON-LD' => sub {
my $test = shift;
my $mech = $test->mech;
my $c = $test->c;
Expand All @@ -24,6 +25,9 @@ test 'Area alias appears on JSON-LD' => sub {
);
html_ok($mech->content);

$mech->text_contains('オーストラリア', 'Alias page lists the alias');
$mech->text_contains('Area name', 'Alias page lists the alias type');

page_test_jsonld $mech => {
'@id' => 'http://musicbrainz.org/area/106e0bec-b638-3b37-b731-f53d507dc00e',
'alternateName' => ["\x{30aa}\x{30fc}\x{30b9}\x{30c8}\x{30e9}\x{30ea}\x{30a2}"],
Expand Down
19 changes: 13 additions & 6 deletions t/lib/t/MusicBrainz/Server/Controller/Artist/AddAlias.pm
Expand Up @@ -12,19 +12,22 @@ the sort name defaults to the name when not explicitly entered.
=cut

test 'Test adding alias with sort name' => sub {
test 'Adding alias with sort name' => sub {
my $test = shift;
my $mech = $test->mech;

prepare_test($test);

$mech->get_ok('/artist/745c079d-374e-4436-9448-da92dedef3ce/add-alias');
$mech->get_ok(
'/artist/745c079d-374e-4436-9448-da92dedef3ce/add-alias',
'Fetched the add alias page',
);

my @edits = capture_edits {
$mech->submit_form_ok({
with_fields => {
'edit-alias.name' => 'An alias',
'edit-alias.sort_name' => 'Artist, Test'
'edit-alias.sort_name' => 'Artist, Test',
},
},
'The form returned a 2xx response code')
Expand Down Expand Up @@ -56,7 +59,7 @@ test 'Test adding alias with sort name' => sub {
day => undef
},
type_id => undef,
ended => 0
ended => 0,
},
'The edit contains the right data',
);
Expand All @@ -76,14 +79,18 @@ test 'Test adding alias with sort name' => sub {
);
};

test 'MBS-6896: Test adding alias without sort name' => sub {
test 'MBS-6896: Adding alias without sort name defaults it to name' => sub {
my $test = shift;
my $mech = $test->mech;

prepare_test($test);

$mech->get_ok(
'/artist/745c079d-374e-4436-9448-da92dedef3ce/add-alias',
'Fetched the add alias page',
);

my @edits = capture_edits {
$mech->get_ok('/artist/745c079d-374e-4436-9448-da92dedef3ce/add-alias');
$mech->submit_form_ok({
with_fields => {
'edit-alias.name' => 'Another alias',
Expand Down
11 changes: 6 additions & 5 deletions t/lib/t/MusicBrainz/Server/Controller/Artist/Aliases.pm
Expand Up @@ -12,7 +12,6 @@ alias page, both on the site itself and on the JSON-LD data.
=cut

test 'Artist alias appears on alias page content and on JSON-LD' => sub {

my $test = shift;
my $mech = $test->mech;
my $c = $test->c;
Expand All @@ -24,15 +23,17 @@ test 'Artist alias appears on alias page content and on JSON-LD' => sub {

$mech->get_ok(
'/artist/745c079d-374e-4436-9448-da92dedef3ce/aliases',
'Fetched artist alias page',
'Fetched artist aliases page',
);
html_ok($mech->content);
$mech->content_contains('Test Alias', 'Alias page lists the alias');
$mech->content_contains(

$mech->text_contains('Test Alias', 'Alias page lists the alias');
$mech->text_contains('Artist name', 'Alias page lists the alias type');
$mech->text_contains(
'2000-01-01',
'Alias page lists the alias begin date',
);
$mech->content_contains(
$mech->text_contains(
'2005-05-06',
'Alias page lists the alias end date',
);
Expand Down
52 changes: 29 additions & 23 deletions t/lib/t/MusicBrainz/Server/Controller/Artist/DeleteAlias.pm
Expand Up @@ -12,20 +12,16 @@ an edit note.
=cut

test 'Test alias deletion' => sub {
test 'Deleting an alias' => sub {
my $test = shift;
my $mech = $test->mech;
my $c = $test->c;

MusicBrainz::Server::Test->prepare_test_database(
$c,
'+controller_artist',
);
prepare_test($test);

$mech->get_ok('/login');
$mech->submit_form( with_fields => { username => 'new_editor', password => 'password' } );

$mech->get_ok('/artist/745c079d-374e-4436-9448-da92dedef3ce/alias/1/delete');
$mech->get_ok(
'/artist/745c079d-374e-4436-9448-da92dedef3ce/alias/1/delete',
'Fetched the delete alias page',
);
my @edits = capture_edits {
$mech->submit_form_ok({
with_fields => {
Expand All @@ -35,7 +31,7 @@ test 'Test alias deletion' => sub {
},
'The form returned a 2xx response code',
);
} $c;
} $test->c;

is(@edits, 1, 'The edit was entered');

Expand Down Expand Up @@ -65,7 +61,7 @@ test 'Test alias deletion' => sub {
day => 6
},
ended => 1,
type_id => undef
type_id => 1,
},
'The edit contains the right data',
);
Expand All @@ -82,20 +78,16 @@ test 'Test alias deletion' => sub {
);
};

test 'Test edit note is required' => sub {
test 'Edit note is required' => sub {
my $test = shift;
my $mech = $test->mech;
my $c = $test->c;

MusicBrainz::Server::Test->prepare_test_database(
$c,
'+controller_artist',
);

$mech->get_ok('/login');
$mech->submit_form( with_fields => { username => 'new_editor', password => 'password' } );
prepare_test($test);

$mech->get_ok('/artist/745c079d-374e-4436-9448-da92dedef3ce/alias/1/delete');
$mech->get_ok(
'/artist/745c079d-374e-4436-9448-da92dedef3ce/alias/1/delete',
'Fetched the delete alias page',
);
my @edits = capture_edits {
$mech->submit_form_ok({
with_fields => {
Expand All @@ -104,7 +96,7 @@ test 'Test edit note is required' => sub {
},
'The form returned a 2xx response code',
);
} $c;
} $test->c;

is(@edits, 0, 'No edit was entered');

Expand All @@ -114,4 +106,18 @@ test 'Test edit note is required' => sub {
);
};

sub prepare_test {
my $test = shift;

MusicBrainz::Server::Test->prepare_test_database(
$test->c,
'+controller_artist',
);

$test->mech->get('/login');
$test->mech->submit_form(
with_fields => { username => 'new_editor', password => 'password' }
);
}

1;
20 changes: 15 additions & 5 deletions t/lib/t/MusicBrainz/Server/Controller/Artist/EditAlias.pm
Expand Up @@ -12,17 +12,23 @@ the sort name defaults to the name when not explicitly entered (blanked).
=cut

test 'Test editing alias' => sub {
test 'Editing alias' => sub {
my $test = shift;
my $mech = $test->mech;

prepare_test($test);

$mech->get_ok(
'/artist/745c079d-374e-4436-9448-da92dedef3ce/alias/1/edit',
'Fetched the edit alias page',
);
my @edits = capture_edits {
$mech->get_ok('/artist/745c079d-374e-4436-9448-da92dedef3ce/alias/1/edit');
$mech->submit_form(
with_fields => {
'edit-alias.name' => 'Edited alias'
'edit-alias.name' => 'Edited alias',
# HTML::Form doesn't understand selected=""
# so we need to specifically set this
'edit-alias.type_id' => '1',
});
} $test->c;

Expand Down Expand Up @@ -65,14 +71,18 @@ test 'Test editing alias' => sub {
);
};

test 'MBS-6896: Test editing alias and emptying sort name' => sub {
test 'MBS-6896: Removing alias sort name defaults it to name' => sub {
my $test = shift;
my $mech = $test->mech;

prepare_test($test);

$mech->get_ok(
'/artist/745c079d-374e-4436-9448-da92dedef3ce/alias/1/edit',
'Fetched the edit alias page',
);

my @edits = capture_edits {
$mech->get_ok('/artist/745c079d-374e-4436-9448-da92dedef3ce/alias/1/edit');
$mech->submit_form(
with_fields => {
'edit-alias.name' => 'Edit #2',
Expand Down

0 comments on commit 2980adc

Please sign in to comment.