Example #1
0
 public function testMatchAll()
 {
     $this->assertEquals(array("#str rst#", "str", "rst"), StrUtil::matchAll('@#([a-z]*) ([a-z]*)#@', 'yxa#str rst#bxy'));
     // named patterns
     $this->assertEquals(array("#str rst#", "str", "rst", "first" => "str", "second" => "rst"), StrUtil::matchAll('@#(?P<first>[a-z]*) (?P<second>[a-z]*)#@', 'yxa#str rst#bxy'));
     $this->assertEquals(false, StrUtil::matchAll('@x(.*)x@', 'yyabxy'));
 }
 /**
  * Parses the AIS2 version from html page.
  *
  * @param string $html AIS2 html reply to be parsed
  *
  * @returns AIS2Version AIS2 version
  * @throws ParseException on error
  */
 public function parseVersionStringFromMainPage($html)
 {
     $data = StrUtil::matchAll(self::VERSION_PATTERN, $html);
     if ($data === false) {
         throw new ParseException("Cannot parse AIS version from response.");
     }
     return new AIS2Version(2, $data['major'], $data['minor'], $data['patch']);
 }
 /**
  * Parses user name from AIS2 start page
  *
  * @param string $html AIS2 html reply to be parsed
  *
  * @returns AIS2Version AIS2 version
  * @throws ParseException on error
  */
 public function parseUserNameFromMainPage($html)
 {
     Preconditions::checkIsString($html);
     $data = StrUtil::matchAll(self::USERNAME_PATTERN, $html);
     if ($data === false) {
         throw new ParseException("Cannot parse username from response.");
     }
     return $data['username'];
 }
Example #4
0
 /**
  *
  * @param str predpokladame range v 2 moznych standardnych ais formatoch
  *    - "do [datum a cas]"
  *    - "[datum a cas] do [datum a cas]"
  * @see parseAISDateTime
  * @returns array('od'=>timestamp, 'do'=>timestamp)
  */
 public static function parseAISDateTimeRange($str)
 {
     $pattern = '@(?P<od>[0-9:. ]*)do (?P<do>[0-9:. ]*)@';
     $data = StrUtil::matchAll($pattern, $str);
     $result = array();
     if ($data['od'] == '') {
         $result['od'] = null;
     } else {
         $result['od'] = self::parseAISDateTime($data['od']);
     }
     $result['do'] = self::parseAISDateTime($data['do']);
     return $result;
 }
 public function prihlasNaTermin(Trace $trace, $terminIndex)
 {
     $this->openIfNotAlready($trace);
     $data = $this->executor->doRequest($trace, array('compName' => 'enterAction', 'eventClass' => 'avc.ui.event.AVCActionEvent', 'embObj' => array('objName' => 'zoznamTerminovTable', 'dataView' => array('activeIndex' => $terminIndex, 'selectedIndexes' => $terminIndex))));
     $error = StrUtil::match('@webui\\(\\)\\.messageBox\\("([^"]*)",@', $data);
     if ($error) {
         throw new Exception('Nepodarilo sa prihlásiť na zvolený termín.<br/>' . 'Dôvod: <b>' . $error . '</b>');
     }
     if (!preg_match("@dm\\(\\)\\.closeDialog\\(" . "\"VSES206_VyberTerminuHodnoteniaDlg1\"\\);@", $data)) {
         throw new Exception("Problém pri prihlasovaní: " . "Neočakávaná odozva od AISu");
     }
     $this->closeIfNeeded($trace);
     return true;
 }
 /**
  * Ensure that all fake data we use are valid FileStorage
  * data files. This should ensure, that fake backend and
  * other services depending on fake data will not encounter
  * broken data.
  */
 public function testAllData()
 {
     $dir = fake_data::getDirectory();
     $storage = new FileStorage(array("root_path" => $dir . '/'));
     $it = new RecursiveDirectoryIterator($dir);
     $nonrecursiveIt = new RecursiveIteratorIterator($it);
     $regexIt = new RegexIterator($nonrecursiveIt, '@\\.dat$@');
     foreach ($regexIt as $file) {
         $this->assertTrue($file->isFile());
         $key = $file->getPathname();
         assert(StrUtil::startsWith($key, $dir));
         // remove $dir from beginning of $key
         $key = substr($key, strlen($dir));
         $key = preg_replace("@\\.dat\$@", "", $key);
         $data = $storage->read($key);
         $this->assertTrue(null !== $data);
     }
 }
 public function login(AIS2ServerConnection $serverConnection)
 {
     $connection = $serverConnection->getHttpConnection();
     $login = $this->username;
     $krbpwd = $this->krbpwd;
     if ($login === null && $krbpwd === null) {
         throw new Exception("S týmto objektom nie je možné sa prihlásiť 2x. " . "Meno a heslo boli vymazané pri prvom prihlásení.");
     }
     // Username a password si nebudeme pamatat dlhsie ako treba
     $this->username = null;
     $this->krbpwd = null;
     // TODO(ppershing): why is there this line? Needed for some cookies?
     $this->isLoggedIn($serverConnection);
     $data = $connection->post(new NullTrace(), self::COSIGN_LOGIN, array('ref' => '', 'login' => $login, 'krbpwd' => $krbpwd));
     if (!preg_match(parent::LOGGED_ALREADY_PATTERN, $data)) {
         if (($reason = StrUtil::match(self::COSIGN_ERROR_PATTERN1, $data)) || ($reason = StrUtil::match(self::COSIGN_ERROR_PATTERN2, $data)) || ($reason = StrUtil::match(self::COSIGN_ERROR_PATTERN3, $data)) || ($reason = StrUtil::match(self::IIKS_ERROR, $data))) {
             throw new LoginException('Nepodarilo sa prihlásiť, dôvod: <b>' . $reason . '</b>');
         }
         throw new LoginException('Nepodarilo sa prihlásiť, dôvod neznámy.');
     }
     return true;
 }
 private function newException($reason, $url)
 {
     return new Exception('<b>Nastala chyba pri requeste.</b><br/>Zdôvodnenie od AISu:' . nl2br(StrUtil::hescape($reason)) . '<br/>Požadovaná url: ' . StrUtil::hescape($url));
 }
Example #9
0
 /**
  * Joins two or more path components.
  * If joining more than two path components, the result is
  * the same as calling two-argument joinPath successively.
  * Moreover, this function is associative, i.e.
  * joinPath('a','b','c') has the same effect as
  * joinPath(joinPath('a', 'b'), 'c') or joinPath('a', joinPath('b', 'c'))
  *
  * Path components of zero length are ignored
  *
  * @param string $a first path component
  * @param string $b second path component
  * @param string ... any other path components to join
  * @returns string all the paths joined using a directory separator
  */
 public static function joinPath($a, $b)
 {
     $args = func_get_args();
     $num_args = count($args);
     $shouldAddDS = true;
     // start with $a, omit trailing directory separator
     if ($a == DIRECTORY_SEPARATOR || $a == '') {
         $shouldAddDS = false;
         $path = $a;
     } else {
         if (StrUtil::endsWith($a, DIRECTORY_SEPARATOR)) {
             $path = substr($a, 0, strlen($a) - 1);
         } else {
             $path = $a;
         }
     }
     // add other components
     for ($i = 1; $i < $num_args; $i++) {
         $part = $args[$i];
         // DIRECTORY_SEPARATOR or empty string is a special case
         if ($part == DIRECTORY_SEPARATOR) {
             continue;
         }
         // first extract range of part without leading or trailing DS
         if (StrUtil::startsWith($part, DIRECTORY_SEPARATOR)) {
             $start = 1;
         } else {
             $start = 0;
         }
         if (StrUtil::endsWith($part, DIRECTORY_SEPARATOR)) {
             $end = strlen($part) - 1;
         } else {
             $end = strlen($part);
         }
         // append a path component
         if ($shouldAddDS) {
             $path .= DIRECTORY_SEPARATOR;
         }
         $shouldAddDS = true;
         $path .= substr($part, $start, $end);
     }
     return $path;
 }
 public function parseIdFromZapisnyListIndexFromResponse($response)
 {
     $data = StrUtil::matchAll(self::APP_LOCATION_PATTERN, $response);
     if ($data === false) {
         throw new ParseException("Location of APP_PATTERN failed.");
     }
     $data = StrUtil::matchAll(self::ID_PATTERN, $data[2]);
     if ($data === false) {
         throw new ParseException("Parsing of ids from zapisnyListIndex failed.");
     }
     return MiscUtil::removeIntegerIndexesFromArray($data);
 }
 public function odhlasZTerminu(Trace $trace, $terminIndex)
 {
     $this->openIfNotAlready($trace);
     // Posleme request ze sa chceme odhlasit.
     $data = $this->executor->doRequest($trace, array('compName' => 'odstranitTerminAction', 'eventClass' => 'avc.ui.event.AVCActionEvent', 'embObj' => array('objName' => 'terminyTable', 'dataView' => array('activeIndex' => $terminIndex, 'selectedIndexes' => $terminIndex))));
     if (!preg_match("@Skutočne chcete odobrať vybraný riadok?@", $data)) {
         throw new Exception("Problém pri odhlasovaní - neočakávaná odozva AISu");
     }
     // Odklikneme konfirmacne okno ze naozaj.
     $data = $this->executor->doRequest($trace, array('events' => false, 'app' => false, 'dlgName' => false, 'changedProperties' => array('confirmResult' => 2)));
     $message = StrUtil::match('@webui\\.messageBox\\("([^"]*)"@', $data);
     if ($message !== false && $message != 'Činnosť úspešne dokončená.') {
         throw new Exception("Z termínu sa (pravdepodobne) nepodarilo odhlásiť." . "Dôvod:<br/><b>" . $message . '</b>');
     }
     if (!preg_match("@dm\\(\\).setActiveDialogName\\(" . "'VSES007_StudentZoznamPrihlaseniNaSkuskuDlg0'\\);@", $data)) {
         throw new Exception("Problém pri odhlasovaní z termínu - neočakávaná odpoveď od AISu");
     }
     return true;
 }
 public function getTableData(Trace $trace, DOMDocument $dom)
 {
     $data = array();
     $trace->tlog("finding tbody element");
     $element = $dom->getElementById('dataTabBody0');
     if ($element == null) {
         throw new ParseException("Can't find table data");
     }
     foreach ($element->childNodes as $aisRow) {
         assert($aisRow->tagName == "tr");
         assert($aisRow->hasAttribute("id"));
         assert($aisRow->hasChildNodes());
         // TODO: asserty prerobit na exceptiony
         $row = array();
         $rowId = $aisRow->getAttribute("id");
         $index = StrUtil::match('@^row_([0-9]+)$@', $rowId);
         if ($index === false) {
             throw new ParseException("Unexpected row id format");
         }
         foreach ($aisRow->childNodes as $ais_td) {
             assert($ais_td->tagName == "td");
             $row[] = $this->getCellContent($ais_td);
         }
         $data[$index] = $row;
     }
     $trace->tlogVariable("data", $data);
     return $data;
 }