Skip to content

Commit

Permalink
Merge branch 'DOT-1428_sentry_automated_tests' into DOT-1513_sentry_a…
Browse files Browse the repository at this point in the history
…utomated_tests

# Conflicts:
#	tests/Feature/GroupStatsTest.php
#	tests/Feature/Users/MenusTest.php
  • Loading branch information
edwh committed Aug 2, 2021
2 parents 12b55a9 + 4c16e8f commit 63d53cc
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/Http/Controllers/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,10 @@ public static function stats($id, $format = 'row')
$emissionRatio = $footprintRatioCalculator->calculateRatio();

$group = Group::where('idgroups', $id)->first();
if (!$group) {
return abort(404, 'Invalid group id');
}

$groupStats = $group->getGroupStats($emissionRatio);

$groupStats['format'] = $format;
Expand Down
6 changes: 5 additions & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1190,9 +1190,13 @@ public function getUserMenus(Request $request)
{
$user = User::where('mediawiki', $request->input('wiki_username'))->first();

if (!$user) {
abort('404', 'Wiki user not found');
}

$menus = [];

if ($user->hasRole('Administrator') || $user->hasPermission('verify-translation-access') || $user->hasRole('NetworkCoordinator')) {
if (($user->hasRole('Administrator') || $user->hasPermission('verify-translation-access') || $user->hasRole('NetworkCoordinator'))) {
$items = [];

if ($user->hasRole('Administrator')) {
Expand Down
2 changes: 0 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,6 @@

Route::get('/set-lang/{locale}', 'LocaleController@setLang');

Route::get('/set-lang/{locale}', 'LocaleController@setLang');

Route::post('/set-cookie', 'InformationAlertCookieController');

Route::get('/test/check-auth', function () {
Expand Down
8 changes: 8 additions & 0 deletions tests/Feature/GroupStatsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use App\Party;
use Carbon\Carbon;
use DB;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

Expand Down Expand Up @@ -65,4 +67,10 @@ public function a_group_with_one_past_event_has_stats_for_that_event()
];
$this->assertEquals($expectedStats, $group->getGroupStats(0.5));
}

/** @test */
public function stats_for_invalid_group() {
$this->expectException(NotFoundHttpException::class);
$response = $this->get("/group/stats/37/mini");
}
}
16 changes: 16 additions & 0 deletions tests/Feature/Users/EditLanguageSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,20 @@ public function user_language_update_triggers_language_sync()
// assert
Event::assertDispatched(UserLanguageUpdated::class);
}

/** @test */
// Added these to try (and fail) to reproduce a Sentry error.
public function user_sets_language() {
$this->loginAsTestUser();

$this->followingRedirects();
$response = $this->from('/')->get('/set-lang/en');
$response->assertSuccessful();
$this->assertEquals('en', session('locale'));

$this->followingRedirects();
$response = $this->from('/')->get('/set-lang/zz');
$response->assertSuccessful();
$this->assertEquals('zz', session('locale'));
}
}
11 changes: 8 additions & 3 deletions tests/Feature/Users/MenusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
use App\Events\UserUpdated;
use App\User;
use Carbon\Carbon;
use DB;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Tests\TestCase;
use Illuminate\Support\Facades\Event;
use Illuminate\Foundation\Testing\RefreshDatabase;

class MenusTest extends TestCase
{
Expand Down Expand Up @@ -59,4 +59,9 @@ public function testSections($role, $present)

$this->assertEquals($present, array_keys($menus));
}

public function testLoggedOut() {
$this->expectException(NotFoundHttpException::class);
$this->get('/user/menus');
}
}

0 comments on commit 63d53cc

Please sign in to comment.