/** * Tests new format logs correctly * * @author Nikos Dimopoulos <*****@*****.**> * @since 2012-09-17 */ public function testLoggerFormatterNewFormatFormatsDateCorrectly() { $fileName = newFileName('log', 'log'); $logger = new PhTLoggerAdapterFile($this->logPath . $fileName); $formatter = new PhLoggerFormatterLine('%type%|%date%|%message%'); $logger->setFormatter($formatter); $logger->log('Hello'); $logger->close(); $contents = file($this->logPath . $fileName); $message = explode('|', $contents[0]); cleanFile($this->logPath, $fileName); $date = new \DateTime($message[1]); $expected = date('Y-m-d H'); $actual = $date->format('Y-m-d H'); $this->assertEquals($expected, $actual, 'Date format not set properly'); }
function docs($files, $path, $save) { $category = array(); //array of categories $comps = array(); //array of components $names = array(); //array of named elements $events = array(); //array of events //loop over files foreach ($files as $file) { $fh = fopen($path . $file, 'r'); $open = false; $lastTag = ""; $block = ""; while ($line = fgets($fh)) { if (strstr($line, "/**@") !== false && !$open) { $block = ""; $open = true; } if ($open) { $cleanline = stripslashes(preg_replace("!(/\\*+@?|^\\s*\\*/?\\s?)!", "", $line)); $def = substr($cleanline, 0, 1); if ($def == "#") { //name $name = trim(substr($cleanline, 1)); $block .= $cleanline; } else { if ($def == "@") { //tag preg_match("/\\@([^\\s]*)\\s(.*)/", $cleanline, $matches); $tag = $matches[1]; $value = $matches[2]; switch ($tag) { case SIGN: $block .= "`" . $value . "`\n\n"; break; case EXAMPLE: $block .= "###Example\n"; break; case END: $block .= "\n"; break; case PARAM: $split = preg_split("/\\s+-\\s+/", $value); $block .= "{$split[0]}\n:\t{$split[1]}\n\n"; break; case RETURNS: $block .= "###Returns\n" . "<span class=\"returns\">" . $value . "</span>\n\n"; break; case SEE: $split = preg_split("/\\s*,\\s*/", $value); $block .= "###See Also\n"; foreach ($split as $see) { if (substr($see, 0, 1) === '.') { $link = "#" . cleanFile($see); } else { if (strstr($see, '#') != false) { $parts = explode('#', $see); $link = cleanFile($parts[0]) . ".html#" . cleanFile($parts[1]); } else { $link = cleanFile($see) . ".html"; } } $block .= "- [" . $see . "](" . $link . ")\n"; } break; case CATEGORY: $split = preg_split("/\\s*,\\s*/", $value); foreach ($split as $v) { $v = trim($v); if (!isset($category[$v])) { $category[$v] = array(); } $category[$v][] = $name; } break; case COMP: $split = preg_split("/\\s*,\\s*/", $value); foreach ($split as $v) { $v = trim($v); if (!isset($comps[$v])) { $comps[$v] = array(); } $comps[$v][] = $name; } break; case TRIGGER: if ($lastTag != TRIGGER) { $block .= "###Events\n"; } $split = preg_split("/\\s+-\\s+/", $value); $block .= "{$split[0]}"; if (count($split) >= 3) { $split[2] = trim($split[2]); if (count($split) >= 4) { $split[3] = trim($split[3]); $block .= " [{$split[3]}: {$split[2]}]"; } else { $block .= " [Data: {$split[2]}]"; } } $block .= "\n:\t{$split[1]}\n\n"; break; } $lastTag = $tag; } else { if (trim($cleanline) == "") { $block .= "\n"; } else { $block .= $cleanline; } } } } if (strstr($line, "*/") !== false && $open) { $open = false; $names[$name] = $block; } } fclose($fh); } $head = stripslashes(file_get_contents("header.php")); $foot = stripslashes(file_get_contents("footer.php")); //generate the index $index = "<div id='doc-nav'><ul id='doc-level-one'>"; $found = array(); foreach ($category as $cat => $subs) { $index .= "<li>" . $cat . "<ul>"; foreach ($subs as $sub) { $link = cleanFile($sub) . ".html"; $index .= "<li><a href='{$link}'>" . $sub . "</a></li>"; $found[$sub] = $link; } $index .= "</ul></li>"; } $index .= "</ul></div>"; file_put_contents($save . "index.html", $head . $index . $foot); foreach ($found as $sub => $link) { $content = $index . "<div id='doc-content'>"; if (isset($comps[$sub])) { $content .= Markdown($names[$sub]); //loop over each part of the component $parts = $comps[$sub]; //add the contents $content .= "<div class='doc-contents'><ul>"; foreach ($parts as $part) { $content .= "<li><a href='#" . cleanFile($part) . "'>{$part}</a></li>"; } $content .= "</ul></div>"; //add the content foreach ($parts as $part) { $content .= "<div class='doc-block' id='" . cleanFile($part) . "'><a href='#doc-nav' class='doc-top'>Back to top</a>"; $html = Markdown($names[$part]); $html = preg_replace("!<(/)?h2>!", "<\$1h3>", $html); $html = preg_replace("!<(/)?h1>!", "<\$1h2>", $html); $content .= $html; $content .= "</div>"; } } else { $content .= Markdown($names[$sub]); } $content .= "</div>"; file_put_contents($save . $link, $head . $content . $foot); } }
/** * Tests serializing the ACL * * @author Nikolaos Dimopoulos <*****@*****.**> * @since 2014-10-04 */ public function testAclSerialize() { $this->specify('Acl serialization/unserialization does not return a correct object back', function () { $filename = newFileName('acl', 'log'); $acl = new PhTAclMem(); $aclRole = new PhTAclRole('Administrators', 'Super User access'); $aclResource = new PhTAclResource('Customers', 'Customer management'); $acl->addRole($aclRole); $acl->addResource($aclResource, ['search', 'destroy']); $acl->allow('Administrators', 'Customers', 'search'); $acl->deny('Administrators', 'Customers', 'destroy'); $contents = serialize($acl); file_put_contents(PATH_CACHE . $filename, $contents); $acl = null; $contents = file_get_contents(PATH_CACHE . $filename); cleanFile(PATH_CACHE, $filename); $acl = unserialize($contents); $actual = $acl instanceof \Phalcon\Acl\Adapter\Memory; expect($actual)->true(); $actual = $acl->isRole('Administrators'); expect($actual)->true(); $actual = $acl->isResource('Customers'); expect($actual)->true(); $expected = PhAcl::ALLOW; $actual = $acl->isAllowed('Administrators', 'Customers', 'search'); expect($actual)->equals($expected); $expected = PhAcl::DENY; $actual = $acl->isAllowed('Administrators', 'Customers', 'destroy'); expect($actual)->equals($expected); }); }
/** * Tests none filter * * @issue 1198 * @author Nikolaos Dimopoulos <*****@*****.**> * @since 2014-10-10 */ public function testAssetsFilterChainCustomFilterWithCssmin() { $this->markTestSkipped('To be tested'); $this->specify("The chaining a custom filter with cssmin does not return the correct results", function () { $fileName = newFileName('assets_', 'css'); $this->prepareDI(); $assets = new PhTAssetsManager(); $assets->useImplicitOutput(false); $css = $assets->collection('css'); $css->setTargetPath(PATH_CACHE . $fileName); $css->addCss(PATH_DATA . '/assets/1198.css'); $css->addFilter(new Helper\UppercaseFilter()); $css->addFilter(new Helper\TrimFilter()); $css->join(true); $assets->outputCss('css'); $expected = 'A{TEXT-DECORATION:NONE;}B{FONT-WEIGHT:BOLD;}'; $actual = file_get_contents(PATH_CACHE . $fileName); cleanFile(PATH_CACHE, $fileName); expect($actual)->equals($expected); }); }
/** * Runs logging test * * @author Nikos Dimopoulos <*****@*****.**> * @since 2012-09-17 * * @param $function */ protected function logging($function) { $fileName = newFileName('log', 'log'); $logger = new PhTLoggerAdapterFile($this->logPath . $fileName); $logger->{$function}('Hello'); $logger->close(); $contents = file($this->logPath . $fileName); cleanFile($this->logPath, $fileName); $position = strpos($contents[0], '[' . strtoupper($function) . ']'); $actual = $position !== false; expect($actual)->true(); $position = strpos($contents[0], 'Hello'); $actual = $position !== false; expect($actual)->true(); }
/** * Tests the begin/rollback * * @author Nikolaos Dimopoulos <*****@*****.**> * @since 2014-09-13 */ public function testLoggerAdapterFileRollback() { $this->specify("Logging does not contain correct number of messages before rollback", function () { $fileName = newFileName('log', 'log'); $logger = new PhTLoggerAdapterFile($this->logPath . $fileName); $logger->log('Hello'); $logger->close(); $contents = file($this->logPath . $fileName); cleanFile($this->logPath, $fileName); $expected = 1; $actual = count($contents); expect($actual)->equals($expected); }); $this->specify("Logging does not contain correct number of messages after rollback", function () { $fileName = newFileName('log', 'log'); $logger = new PhTLoggerAdapterFile($this->logPath . $fileName); $logger->log('Hello'); $logger->begin(); $logger->log('Message 1'); $logger->log('Message 2'); $logger->log('Message 3'); $logger->rollback(); $logger->close(); $contents = file($this->logPath . $fileName); cleanFile($this->logPath, $fileName); $expected = 1; $actual = count($contents); expect($actual)->equals($expected); }); }