/** * 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); }); }
/** * 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'); }
/** * 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); }); }
public function testFilterSimpleNoJoin() { $this->markTestSkipped('To be tested'); $this->specify("The simple filter without join does not return the correct results", function () { $fileName = newFileName('assets_', 'js'); $this->prepareDI(true); $assets = new PhTAssetsManager(); $assets->useImplicitOutput(false); $js = $assets->collection('js'); $js->setTargetPath(PATH_CACHE . $fileName); $js->setTargetUri('production/combined.js'); $js->addJs('assets/assets-multiple-01.js', false, false); $actual = $assets->outputJs('js'); $expected = '<script type="text/javascript" ' . 'src="assets/assets-multiple-01.js"></script>' . PHP_EOL; expect($actual)->equals($expected); }); //Enabling join $js->join(true); $this->assertEquals($assets->outputJs('js'), '<script type="text/javascript" src="unit-tests/assets/jquery.js"></script>' . PHP_EOL); //Disabling join $js->join(false); $this->assertEquals($assets->outputJs('js'), '<script type="text/javascript" src="unit-tests/assets/jquery.js"></script>' . PHP_EOL); //Filter - Join $js->join(false); $js->addFilter(new Phalcon\Assets\Filters\None()); $this->assertEquals($assets->outputJs('js'), '<script type="text/javascript" src="/unit-tests/assets/jquery.js"></script>' . PHP_EOL); }
/** * 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(); }