Skip to content

Commit

Permalink
#47: Add tests for term visibility admin.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamfranco committed Dec 2, 2024
1 parent 378d297 commit f2fff05
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Controller/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function termsAction(Request $request)
$data = [];
$db = $this->entityManager->getConnection();

$searches = $db->executeQuery('SELECT * FROM catalog_term_match')->fetchAll();
$searches = $db->executeQuery('SELECT * FROM catalog_term_match')->fetchAllAssociative();
$catalogs = [];
$queries = [];
foreach ($searches as $search) {
Expand Down Expand Up @@ -92,7 +92,7 @@ public function termsAction(Request $request)
$stmt->bindValue(3, $catalog);
$result = $stmt->executeQuery();
$data['selectedCatalog'] = $catalog;
$data['terms'] = $result->fetchAll();
$data['terms'] = $result->fetchAllAssociative();
foreach ($data['terms'] as &$term) {
$term['active'] = intval($term['num_sections']) && !intval($term['manually_disabled']);
}
Expand Down Expand Up @@ -181,7 +181,7 @@ public function exportAction()
{
$db = Zend_Registry::get('db');

$this->view->configs = $db->query('SELECT * FROM archive_configurations')->fetchAll();
$this->view->configs = $db->query('SELECT * FROM archive_configurations')->fetchAllAssociative();

$this->view->config = null;
if ($this->_getParam('config') && -1 != $this->_getParam('config')) {
Expand Down Expand Up @@ -250,7 +250,7 @@ public function antirequisitesAction()
}

// Select our already-created antirequisites
$this->view->antirequisites = $db->query('SELECT * FROM antirequisites ORDER BY subj_code, crse_numb, subj_code_eqiv, crse_numb_eqiv')->fetchAll();
$data['antirequisites'] = $db->query('SELECT * FROM antirequisites ORDER BY subj_code, crse_numb, subj_code_eqiv, crse_numb_eqiv')->fetchAllAssociative();

// Supply search results.
$this->view->search_subj_code = $this->_getParam('search_subj_code');
Expand Down
2 changes: 1 addition & 1 deletion templates/admin/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block body %}
<h1>Course Catalog Administration</h1>
<ul>
<li><a href="{{ url("admin_terms") }}">Manage Term Visibility</a></li>
<li><a href="{{ url("admin_terms_list") }}">Manage Term Visibility</a></li>
<li><a href="{{ url("admin_antirequisites") }}">Manage Anti-Requisites</a></li>
<li><a href="{{ url("admin_archive_config") }}">Manage Catalog Archive Configurations</a></li>
<li><a href="{{ url("admin_archive_schedule") }}">Manage Catalog Archive Scheduling</a></li>
Expand Down
75 changes: 75 additions & 0 deletions tests/Controller/AdminTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace App\Tests\Controller;

use App\Security\SamlUser;
use App\Tests\AppDatabaseTestTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class AdminTest extends WebTestCase
{
use AppDatabaseTestTrait;

private function setUpUser(): SamlUser
{
$user = new SamlUser('WEBID99999990');
$user->setSamlAttributes([
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress' => ['[email protected]'],
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname' => ['Winnie'],
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname' => ['The-Pooh'],
'AssignedRoles' => ['App.EmailSendAllowed', 'App.Manager'],
]);

return $user;
}

public function testIndex(): void
{
$client = static::createClient();
$client->loginUser($this->setUpUser());

$crawler = $client->request('GET', '/admin');

$this->assertResponseIsSuccessful();
}

public function testIndexAnonymous(): void
{
$client = static::createClient();

$crawler = $client->request('GET', '/admin');

$this->assertResponseRedirects();
}

public function testIndexNonManager(): void
{
$client = static::createClient();

$user = new SamlUser('WEBID99999990');
$user->setSamlAttributes([
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress' => ['[email protected]'],
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname' => ['Winnie'],
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname' => ['The-Pooh'],
'AssignedRoles' => ['App.EmailSendAllowed'],
]);
$client->loginUser($user);

$client->request('GET', '/admin');

$this->assertEquals(403, $client->getResponse()->getStatusCode());
}

public function testTermVisibilityList(): void
{
$client = static::createClient();
$client->loginUser($this->setUpUser());

$crawler = $client->request('GET', '/admin/terms');
$this->assertResponseIsSuccessful();

$crawler = $client->request('GET', '/admin/terms?catalog=MCUG');
$this->assertResponseIsSuccessful();
$this->assertSelectorTextContains('.section_admin', '200990');
}
}

0 comments on commit f2fff05

Please sign in to comment.