From 18f1e3f4ace0646993b52be5aedccd3a4908946a Mon Sep 17 00:00:00 2001
From: Brett Bieber <brett.bieber@gmail.com>
Date: Mon, 29 Apr 2013 12:08:03 -0500
Subject: [PATCH] Remove validation library, no course data is included in the
 database

---
 src/UNL/Catalog/Search.php     |   7 +-
 src/UNL/Catalog/Validate.php   |  84 ---------------------
 tests/Catalog/ValidateTest.php | 134 ---------------------------------
 3 files changed, 1 insertion(+), 224 deletions(-)
 delete mode 100644 src/UNL/Catalog/Validate.php
 delete mode 100644 tests/Catalog/ValidateTest.php

diff --git a/src/UNL/Catalog/Search.php b/src/UNL/Catalog/Search.php
index 5804fae..4c9767a 100644
--- a/src/UNL/Catalog/Search.php
+++ b/src/UNL/Catalog/Search.php
@@ -64,12 +64,7 @@ class UNL_Catalog_Search
     
     public function listings($q)
     {
-        include_once 'UNL/Catalog/Validate.php';
-        if ($r = UNL_Catalog_Validate::subjectAndNumber($q)) {
-            $where = "subject_id LIKE '%{$r[0]['subject_id']}%' AND number LIKE '%{$r[0]['number']}%'";
-        } else {
-            $where = "subject_id LIKE '%$q%' OR number LIKE '%$q%' OR title LIKE '%$q%'";
-        }
+        $where = "subject_id LIKE '%$q%' OR number LIKE '%$q%' OR title LIKE '%$q%'";
         $listings = $this->catalog->factory('course_listings');
         $courses  = $this->catalog->factory('courses');
         $listings->joinAdd($courses);
diff --git a/src/UNL/Catalog/Validate.php b/src/UNL/Catalog/Validate.php
deleted file mode 100644
index 4883bc4..0000000
--- a/src/UNL/Catalog/Validate.php
+++ /dev/null
@@ -1,84 +0,0 @@
-<?php
-/**
- * This file contains everything necessary for validating sections of the catalog.
- * 
- */
-
-/**
- * This class contains methods for validating specific pieces of information for
- * the catalog. Use the methods below to check strings for validity when inputting
- * data.
- */
-class UNL_Catalog_Validate
-{
-    /**
-     * Determines if the subject and number are in a recognizable format.
-     *
-     * @param string $text eg 'AHIS *854Y'
-     * 
-     * @return array subject_id, number, gradonly
-     */
-    public static function subjectAndNumber($text)
-    {
-        $text = strtoupper($text);
-        if (preg_match('/^([A-Z]{3,4})\s((\*)?(\d{3,4}[a-zA-Z]?)\/?)+$/',$text,$matches)) {
-            $subject_id = $matches[1];
-            $text = trim(str_replace($subject_id, '', $text));
-            $numbers = explode('/', $text);
-            $data = array();
-            foreach ($numbers as $number) {
-                $course['subject_id'] = $subject_id;
-                if (preg_match('/(\*)?(\d{3,4}[a-zA-Z]?)/', $number, $matches)) {
-                    $course['number'] = $matches[2];
-                    if ($matches[1]=='*') {
-                        $course['gradonly'] = true;
-                    } else {
-                        $course['gradonly'] = false;
-                    }
-                } else {
-                    throw new Exception('Malformed course number.. should never reach this.');
-                }
-                $data[] = $course;
-            }
-            return $data;
-        } else {
-            return false;
-        }
-    }
-    
-    /**
-     * Checks if a textual list of crosslistings is formatted correctly.
-     * 
-     * <code>
-     * $res = UNL_Catalog_Validate::crosslistings('(ARCH 558/858)');
-     * </code>
-     *
-     * @param unknown_type $text
-     * @return unknown
-     */
-    public static function crosslistings($text)
-    {
-        $text = trim($text, ' ()');
-        if (preg_match('/([A-Z]{3,4})\s([*]?[\d]{3,4}[A-Z]?)/', $text, $matches)) {
-            $xlist = array();
-            // Appears to be a correctly formatted string of crosslistings.
-            $crosslistings = explode(';', $text);
-            foreach ($crosslistings as $crosslist) {
-                $crosslist = trim(str_replace(', ',',',$crosslist));
-                $crosslist = explode(',',$crosslist);
-                $crosslist = array_reverse($crosslist);
-                $course_num = '';
-                foreach ($crosslist as $subject_and_course) {
-                    if ($subject_and_course = UNL_Catalog_Validate::subjectAndNumber($subject_and_course)) {
-                        $xlist = array_merge($xlist, $subject_and_course);
-                    }
-                }
-            }
-            return $xlist;
-        } else {
-            return false;
-        }
-    }
-}
-
-?>
\ No newline at end of file
diff --git a/tests/Catalog/ValidateTest.php b/tests/Catalog/ValidateTest.php
deleted file mode 100644
index 0470a1a..0000000
--- a/tests/Catalog/ValidateTest.php
+++ /dev/null
@@ -1,134 +0,0 @@
-<?php
-// Call UNL_Catalog_ValidateTest::main() if this source file is executed directly.
-if (!defined('PHPUnit_MAIN_METHOD')) {
-    define('PHPUnit_MAIN_METHOD', 'UNL_Catalog_ValidateTest::main');
-}
-
-require_once 'PHPUnit/Framework.php';
-
-require_once 'Catalog/Validate.php';
-
-/**
- * Test class for UNL_Catalog_Validate.
- * Generated by PHPUnit on 2007-09-12 at 10:42:22.
- */
-class UNL_Catalog_ValidateTest extends PHPUnit_Framework_TestCase {
-    /**
-     * Runs the test methods of this class.
-     *
-     * @access public
-     * @static
-     */
-    public static function main() {
-        require_once 'PHPUnit/TextUI/TestRunner.php';
-
-        $suite  = new PHPUnit_Framework_TestSuite('UNL_Catalog_ValidateTest');
-        $result = PHPUnit_TextUI_TestRunner::run($suite);
-    }
-
-    /**
-     * Sets up the fixture, for example, opens a network connection.
-     * This method is called before a test is executed.
-     *
-     * @access protected
-     */
-    protected function setUp() {
-    }
-
-    /**
-     * Tears down the fixture, for example, closes a network connection.
-     * This method is called after a test is executed.
-     *
-     * @access protected
-     */
-    protected function tearDown() {
-    }
-
-    /**
-     * @todo Implement testSubjectAndNumber().
-     */
-    public function testSubjectAndNumber() {
-        $r = UNL_Catalog_Validate::subjectAndNumber('CSCE 855');
-        $this->assertEquals('CSCE', $r[0]['subject_id']);
-        $this->assertEquals('855', $r[0]['number']);
-        $r = UNL_Catalog_Validate::subjectAndNumber('csce 855');
-        $this->assertEquals('CSCE', $r[0]['subject_id']);
-        $this->assertEquals('855', $r[0]['number']);
-        $r = UNL_Catalog_Validate::subjectAndNumber('CSCE *855');
-        $this->assertEquals('CSCE', $r[0]['subject_id']);
-        $this->assertEquals('855', $r[0]['number']);
-        $r = UNL_Catalog_Validate::subjectAndNumber('CSCE *855A');
-        $this->assertEquals('CSCE', $r[0]['subject_id']);
-        $this->assertEquals('855A', $r[0]['number']);
-        $r = UNL_Catalog_Validate::subjectAndNumber('LAW 1000');
-        $this->assertEquals('LAW', $r[0]['subject_id']);
-        $this->assertEquals('1000', $r[0]['number']);
-        $r = UNL_Catalog_Validate::subjectAndNumber('LAW *1000A');
-        $this->assertEquals('LAW', $r[0]['subject_id']);
-        $this->assertEquals('1000A', $r[0]['number']);
-        $this->assertEquals(true, $r[0]['gradonly']);
-        $r = UNL_Catalog_Validate::subjectAndNumber('CSCE');
-        $this->assertEquals(false, $r);
-    }
-    
-    public function testSubjectAndNumber_MultipleNumbers() {
-        $r = UNL_Catalog_Validate::subjectAndNumber('ARCH 699/*899');
-        $this->assertEquals('ARCH', $r[0]['subject_id']);
-        $this->assertEquals('699', $r[0]['number']);
-        $this->assertFalse($r[0]['gradonly']);
-        $this->assertEquals('ARCH', $r[1]['subject_id']);
-        $this->assertEquals('899', $r[1]['number']);
-        $this->assertTrue($r[1]['gradonly']);
-    }
-    
-    public function testCrosslistings()
-    {
-        $this->assertFalse(UNL_Catalog_Validate::crosslistings('LAW'));
-        $r = UNL_Catalog_Validate::crosslistings('(LAW *1000A)');
-        $this->assertEquals(array(array(
-                                    'subject_id'=> 'LAW',
-                                    'number'    => '1000A',
-                                    'gradonly'  => true)),$r);
-        $r = UNL_Catalog_Validate::crosslistings('(BIOS *817; NRES *807)');
-        $this->assertEquals(array(array(
-                                    'subject_id'=> 'BIOS',
-                                    'number'    => '817',
-                                    'gradonly'  => true),
-                                    array(
-                                    'subject_id'=> 'NRES',
-                                    'number'    => '807',
-                                    'gradonly'  => true)),$r);
-        $r = UNL_Catalog_Validate::crosslistings('(BIOC 834; BIOS *834; CHEM 834)');
-        $this->assertEquals(array(array(
-                                    'subject_id'=> 'BIOC',
-                                    'number'    => '834',
-                                    'gradonly'  => false),
-                                    array(
-                                    'subject_id'=> 'BIOS',
-                                    'number'    => '834',
-                                    'gradonly'  => true),
-                                    array(
-                                    'subject_id'=> 'CHEM',
-                                    'number'    => '834',
-                                    'gradonly'  => false)),$r);
-    }
-    
-    public function testCrosslistings2()
-    {
-        $r = UNL_Catalog_Validate::crosslistings('(ARCH 558/858)');
-        $this->assertEquals(array(array(
-                                    'subject_id'=> 'ARCH',
-                                    'number'    => '558',
-                                    'gradonly'  => false),
-                                    array(
-                                    'subject_id'=> 'ARCH',
-                                    'number'    => '858',
-                                    'gradonly'  => false)),$r);
-    }
-}
-
-// Call UNL_Catalog_ValidateTest::main() if this source file is executed directly.
-if (PHPUnit_MAIN_METHOD == 'UNL_Catalog_ValidateTest::main') {
-    UNL_Catalog_ValidateTest::main();
-}
-?>
-- 
GitLab