/** * execute tests */ public function test($action, $context) { echo "action:{$action}" . PHP_EOL; $request = $context->getRequest(); $action = us($action); // Tidy $tidy = $context->getComponent('tidy@:html:repair:tidy'); $config = new Charcoal_Config(); $config->set('encoding', 'utf8'); $tidy->configure($config); switch ($action) { case "parse_string": $html1 = <<<HTMLDATA1 <html> <head> <title>My Title</name> </head> <BODY> <h1>Test Header</hh1> <form>Google</textarea> <textarea>http://google.com/</textarea></form> </company> HTMLDATA1; $tidy->parseString($html1); show_with_children($tidy->root()); return TRUE; } return FALSE; }
/** * execute tests */ public function test($action, $context) { $action = us($action); // create token generator object $generator = $context->createObject('simple', 'token_generator'); switch ($action) { case "simple_default": // create token generator object $token = $generator->generateToken(); $this->assertEquals(strlen($token), 40); $this->assertEquals(preg_match("/[^0-9a-zA-Z]+/", $token), false); echo "default token: {$token}"; break; case "simple_sha1": $config = new Charcoal_Config($this->getSandbox()->getEnvironment()); $config->set(s('algorithm'), 'sha1'); $generator->configure($config); $token = $generator->generateToken(); $this->assertEquals(strlen($token), 40); $this->assertEquals(preg_match("/[^0-9a-zA-Z]+/", $token), false); echo "sha1 token: {$token}"; break; case "simple_md5": $config = new Charcoal_Config($this->getSandbox()->getEnvironment()); $config->set(s('algorithm'), 'md5'); $generator->configure($config); $token = $generator->generateToken(); $this->assertEquals(strlen($token), 32); $this->assertEquals(preg_match("/[^0-9a-zA-Z]+/", $token), false); echo "md5 token: {$token}"; break; } }
/** * execute tests */ public function test($action, $context) { $action = us($action); $sequence = new Charcoal_SequenceHolder(new Charcoal_Sequence(), new Charcoal_Sequence()); // form token component $form_token = $context->getComponent('form_token@:charcoal:form'); $config = new Charcoal_Config($this->getSandbox()->getEnvironment()); $config->set('token_key', 'foo'); $form_token->configure($config); switch ($action) { case "form_token1": $token = $form_token->generate($sequence); echo "token: {$token}" . PHP_EOL; $this->assertNotNull($token); $this->assertNotEmpty($token); break; case "form_token2": // save my ticket into sequence $token_list = $sequence->get('token_key'); $token_list[] = 'my-ticket'; $sequence->set('foo', $token_list); // validation token will success $form_token->validate($sequence, 'my-ticket'); break; case "form_token3": // save my ticket into sequence $token_list = $sequence->get('token_key'); $token_list[] = 'my-ticket'; $sequence->set('foo', $token_list); // validation token will fail $this->setExpectedException('Charcoal_FormTokenValidationException'); $form_token->validate($sequence, 'another-ticket'); break; } }
/** * execute tests */ public function test($action, $context) { $request = $context->getRequest(); $action = us($action); // SimplePie $simplepie = $context->getComponent('simplepie@:rss:simplepie'); $config = new Charcoal_Config($this->getSandbox()->getEnvironment()); $config->set('enable_cahche', true); $config->set('cache_dir', CHARCOAL_CACHE_DIR . '/simplepie'); $config->set('duration', 1800); $simplepie->configure($config); switch ($action) { // Send mail case "get_feed": //$feed = $simplepie->getFeed( 'http://charcoalphp.org/test/rss/index.xml' ); $feed = $simplepie->getFeed('http://1000mg.jp/feed'); ad($feed); return TRUE; } return FALSE; }
/** * execute tests */ public function test($action, $context) { $request = $context->getRequest(); $action = us($action); // Qdmail $qdmail = $context->getComponent('qdmail@:qdmail'); $config = new Charcoal_Config($this->getSandbox()->getEnvironment()); $config->set('qdsmtp.host', 'localhost'); $config->set('qdsmtp.port', '25'); $config->set('qdsmtp.from', '*****@*****.**'); $config->set('qdsmtp.protocol', 'SMTP'); $config->set('qdsmtp.user', ''); $config->set('qdsmtp.pass', ''); $qdmail->configure($config); switch ($action) { // Send mail case "send_mail": $to = $request->get("to"); $from = "*****@*****.**"; $subject = "test"; $body = "test!!!"; echo "to:" . $to . eol(); $qdmail->sendMail($from, $to, $subject, $body); break; } }