コード例 #1
0
 public function getPanelContent()
 {
     $config = sfYaml::load(sfConfig::get('sf_config_dir') . '/test_generation.yml');
     if (isset($config['default']) && isset($config['default']['formatter'])) {
         $formatter_class = $config['default']['formatter'];
     } else {
         $formatter_class = $this->default_formatter;
     }
     $formatter = new $formatter_class();
     if (!$formatter instanceof swTestFunctionalFormatter) {
         throw new InvalidArgumentException('invalid formatter');
     }
     return '
   <div id="sfDebugPanelFunctionalUnitTest"><div style="float:left">' . "<a href='?_sw_func_reset=1'>Reset</a> - " . (!sfContext::getInstance()->getUser()->getAttribute('sw_func_enabled', false, 'swToolbox') ? "<a href='?_sw_func_enabled=1'>Activate</a>" : "<a href='?_sw_func_enabled=0'>Deactivate</a>") . '<br /><textarea style="width:500px; height: 200px; font-family:courier">' . $formatter->build(swFilterFunctionalTest::getRawPhp()) . '</textarea>
   </div>
   <div style="float:left">
     <h2>References</h2>
     <ul>
       <li><a href="http://www.symfony-project.org/book/1_2/15-Unit-and-Functional-Testing#chapter_15_functional_tests" target="_new">Functional Test</a>
         <ul>
           <li><a href="http://www.symfony-project.org/book/1_2/15-Unit-and-Functional-Testing#chapter_15_sub_browsing_with_the_sftestbrowser_object" target="_new">Browsing with the sfTestBrowser Object</a></li>
           <li><a href="http://www.symfony-project.org/book/1_2/15-Unit-and-Functional-Testing#chapter_15_sub_using_assertions" target="_new">Using Assertions</a></li>
           <li><a href="http://www.symfony-project.org/book/1_2/15-Unit-and-Functional-Testing#chapter_15_sub_using_css_selectors" target="_new">Using CSS Selectors</a></li>
           <li><a href="http://www.symfony-project.org/book/1_2/15-Unit-and-Functional-Testing#chapter_15_sub_testing_for_errors" target="_new">Testing for errors</a></li>
           <li><a href="http://www.symfony-project.org/book/1_2/15-Unit-and-Functional-Testing#chapter_15_sub_working_in_the_test_environment" target="_new">Working in the Test Environment</a></li>          
         </ul>
       </li>
       <li><a href="http://www.symfony-project.org/plugins/swToolboxPlugin" target="_new">swToolboxPlugin (symfony plugin page)</a></li>
     </ul>
   </div>
  </div>
 ';
 }
コード例 #2
0
 public function execute($filterChain)
 {
     $this->fixSfGuard();
     $request = $this->context->getRequest();
     $response = $this->context->getResponse();
     $user = $this->context->getUser();
     $is_first_call = $this->isFirstCall();
     if ($is_first_call) {
         if ($request->hasParameter('_sw_func_reset')) {
             $user->setAttribute('sw_func_code', '', 'swToolbox');
             $filterChain->execute();
             return;
         }
         if ($request->hasParameter('_sw_func_enabled')) {
             if ((int) $request->getParameter('_sw_func_enabled') == 1) {
                 $user->setAttribute('sw_func_enabled', true, 'swToolbox');
                 $user->setAttribute('sw_func_code', '', 'swToolbox');
                 unset($_GET['_sw_func_enabled']);
             }
             if ((int) $request->getParameter('_sw_func_enabled') == 0) {
                 $user->setAttribute('sw_func_enabled', false, 'swToolbox');
                 $user->setAttribute('sw_func_code', null, 'swToolbox');
                 unset($_GET['_sw_func_enabled']);
             }
         }
         if ($user->getAttribute('sw_func_enabled', false, 'swToolbox')) {
             self::$code = $user->getAttribute('sw_func_code', '', 'swToolbox');
         }
     }
     if (!$user->getAttribute('sw_func_enabled', false, 'swToolbox')) {
         $filterChain->execute();
         return;
     }
     $action = $this->context->getActionStack()->getLastEntry();
     $route = $this->context->getRouting()->getCurrentInternalUri();
     $url = $request->getPathInfo();
     if ($is_first_call) {
         if ($from_link = $request->getParameter('_sw_func_link')) {
             unset($_GET['_sw_func_link']);
             $this->raw("\$browser");
             $this->with('response');
             $this->create('contains', $from_link);
             $this->create('click', $from_link, $_GET);
             $this->end();
             $this->raw("  /* " . $this->createPHP('call', $url, 'get', $_GET) . " */ ");
             $this->raw(";\n\n");
             $this->raw("\$browser");
         } else {
             if ($user->getAttribute('sw_func_executing', false, 'swToolbox')) {
                 // behing redirected or an error occur during execution
                 $this->raw(";");
                 $this->raw("\$browser");
                 $this->with('response');
                 $this->create('isRedirected', true);
                 $this->create('isStatusCode', 302);
                 $this->end();
                 $this->create('followRedirect');
                 $this->raw(";\n\n");
                 $this->raw("\$browser");
                 $user->setAttribute('sw_func_executing', false, 'swToolbox');
             } else {
                 if ($request->isMethod('post') || $request->isMethod('put')) {
                     $this->raw("\$browser");
                     $this->create('call', $url, $request->getMethod(), $this->getVarsFromRequest($request));
                     $this->raw("  /* " . $this->createPHP('get', $url) . "\n" . $this->createPHP('click', 'alt or value of submit here', $this->getVarsFromRequest($request)) . " */ ");
                 } else {
                     if ($request->isMethod('delete')) {
                         $this->raw("\$browser");
                         $this->create('call', $url, $request->getMethod(), $this->getVarsFromRequest($request));
                     } else {
                         $this->raw("\$browser");
                         $this->create('call', $url, $request->getMethod(), $_GET);
                     }
                 }
             }
         }
     }
     if (!$is_first_call) {
         $this->raw(";\n\n");
         $this->raw("\$browser");
     }
     $this->with('request');
     if (!$is_first_call || $this->context->getActionStack()->getSize() > 1) {
         $this->create('isForwardedTo', $action->getModuleName(), $action->getActionName());
     } else {
         $this->create('isParameter', 'module', $action->getModuleName());
         $this->create('isParameter', 'action', $action->getActionName());
     }
     $this->end();
     $user->setAttribute('sw_func_code', self::getRawPhp(), 'swToolbox');
     $user->setAttribute('sw_func_executing', true, 'swToolbox');
     $filterChain->execute();
     $user->setAttribute('sw_func_executing', false, 'swToolbox');
     $this->with('response');
     $this->create('isStatusCode', $response->getStatusCode());
     $this->end();
     $this->raw(";\n\n");
     $content = $response->getContent();
     // add link name
     $content = preg_replace_callback(self::LINK_EREG, array($this, 'linkCallback'), $content);
     $response->setContent($content);
     $user->setAttribute('sw_func_code', self::getRawPhp(), 'swToolbox');
 }