function __construct(cs_phpDB $db, $location) { parent::__construct($db); $loc = new csb_location($db); $location = $loc->fix_location($location); $criteria = array('isActive' => "t", 'location' => $location); try { $this->validBlogs = $this->get_blogs($criteria, 'blog_display_name DESC'); } catch (exception $e) { throw new exception(__METHOD__ . ": failed to retrieve any valid blogs for location=(" . $location . ")... " . "MORE INFO::: " . $e->getMessage()); } }
function test_locations() { $locObj = new csb_location($this->dbObj); //FORMAT: <name>=>array(test,expected) $testThis = array('multipleSlashes' => array('////x//y/z///a//b/////////////c/', '/x/y/z/a/b/c'), 'noBeginningSlash' => array('x/y/test/you', '/x/y/test/you'), 'endingSlash' => array('/x/y/', '/x/y'), 'invalidCharacters' => array('/x__354-x@2/3/@/#!%^/&*/()+=@/', '/x__354-x2/3')); $existingLocations = array(); try { $existingLocations = $locObj->get_locations(); throw new exception(__METHOD__ . ": locations already exist... " . $e->getMessage()); } catch (exception $e) { // $this->gfObj->debug_print(__METHOD__ .": no pre-existing locations"); } $this->assertEquals(count($existingLocations), 0); $addedLocations = array(); foreach ($testThis as $testName => $data) { //Test Cleaning... $this->assertEquals($locObj->fix_location($data[1]), $data[1], "Unclean test pattern '" . $testName . "' (" . $locObj->fix_location($data[1]) . ")"); $this->assertEquals($locObj->fix_location($data[0]), $data[1], "Cleaning failed for pattern '" . $testName . "' (" . $locObj->fix_location($data[0]) . ")"); //Test adding the locations. $newLocId = $locObj->add_location($data[0]); if (isset($addedLocations[$data[1]])) { $addedLocations[$data[1]]++; } else { $addedLocations[$data[1]] = 1; } $this->assertTrue(is_numeric($newLocId), "Didn't get valid location_id (" . $newLocId . ")"); $locArr = $locObj->get_locations(); $this->assertEquals($locArr[$newLocId], $data[1], "New location (" . $locArr[$newLocId] . ") does not match expected (" . $data[1] . ")"); //make sure retrieving the location_id using clean & unclean data works properly. $getUncleanLoc = $locObj->get_location_id($data[0]); $getCleanLoc = $locObj->get_location_id($data[1]); // $this->assertEquals($newLocId, $getUncleanLoc); $this->assertEquals($getUncleanLoc, $getCleanLoc); } }