aboutsummaryrefslogtreecommitdiffstats
path: root/t/cobrand/restriction.t
diff options
context:
space:
mode:
Diffstat (limited to 't/cobrand/restriction.t')
-rw-r--r--t/cobrand/restriction.t55
1 files changed, 55 insertions, 0 deletions
diff --git a/t/cobrand/restriction.t b/t/cobrand/restriction.t
new file mode 100644
index 000000000..873a396b7
--- /dev/null
+++ b/t/cobrand/restriction.t
@@ -0,0 +1,55 @@
+use strict;
+use warnings;
+
+package FixMyStreet::Cobrand::Tester;
+
+use parent 'FixMyStreet::Cobrand::Default';
+
+sub problems_restriction {
+ my ($self, $rs) = @_;
+ return $rs->search({ cobrand => 'tester' });
+}
+
+sub updates_restriction {
+ my ($self, $rs) = @_;
+ return $rs->search({ 'problem.cobrand' => 'tester' }, { join => 'problem' });
+}
+
+package main;
+
+use Test::More;
+use FixMyStreet::TestMech;
+
+my $c = FixMyStreet::App->new;
+my $cobrand = FixMyStreet::Cobrand::Tester->new({c => $c});
+$c->stash->{cobrand} = $cobrand;
+
+my $mech = FixMyStreet::TestMech->new;
+
+my ($prob1) = $mech->create_problems_for_body(1, 1234, 'Title');
+my ($prob2) = $mech->create_problems_for_body(1, 1234, 'Title', { cobrand => 'tester' });
+$mech->create_problems_for_body(1, 1234, 'Title', { latitude => 0, longitude => 0 });
+$mech->create_problems_for_body(1, 1234, 'Title', { cobrand => 'tester', latitude => 0, longitude => 0 });
+
+for (1..2) {
+ $c->model('DB::Comment')->create({
+ problem_id => $_ == 1 ? $prob1->id : $prob2->id,
+ user_id => $prob2->user_id,
+ name => 'User',
+ mark_fixed => 'false',
+ text => 'This is some update text',
+ state => 'confirmed',
+ cobrand => 'tester',
+ anonymous => 'f',
+ });
+}
+
+is($c->model('DB::Problem')->count, 4, 'Four reports in database');
+is($cobrand->problems->count, 2, 'Two reports in the right cobrand');
+is($cobrand->updates->count, 1, 'One update in the right cobrand');
+
+my $nearby = $c->model('DB::Nearby')->nearby($c, 5, [], 10, 0.003, 0.004);
+is(@$nearby, 1, 'One report close to the origin point');
+
+$mech->delete_problems_for_body(1234);
+done_testing();