Beispiel #1
0
 /** @return FormsCollection */
 public function getForms()
 {
     $forms = new FormsCollection();
     foreach ($this->getCrawler()->filterXPath('//form') as $node) {
         if ($form = $this->elementToForm($node)) {
             $forms->add($form);
         }
     }
     return $forms;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('Patience...');
     try {
         $starttime = time();
         $client = new Client();
         $violations = 0;
         $testedForms = new FormsCollection();
         $profile = new Profile($client);
         $profile->loadFile($this->resolvePath($input->getArgument('profile')));
         $profile->executePreScript();
         $pages = $profile->spider();
         foreach ($pages as $page) {
             $output->writeLn('<info>' . $page->getUri() . '</info>');
             foreach ($page->getForms() as $form) {
                 $output->writeln(self::INDENT . self::LEAF . $form->getHtml());
                 if ($testedForms->contains($form)) {
                     $output->writeln(self::INDENT . self::INDENT . self::LEAF . 'Already tested');
                     continue;
                 }
                 foreach ($profile->getRules() as $rule) {
                     if (!$rule->isValid($form)) {
                         $output->writeln(self::INDENT . self::INDENT . self::LEAF . "<error>" . $rule->getMessage() . "</error>");
                         ++$violations;
                     }
                 }
                 $testedForms->add($form);
             }
             $output->writeln('');
         }
         $output->writeln(sprintf('Duration: %s seconds', time() - $starttime));
         $output->writeln(sprintf('Found %s unique forms on %s pages', count($testedForms), count($pages)));
         if ($violations) {
             $output->writeln("<error>{$violations} violations found.</error>");
             return self::EXIT_FAIL;
         } else {
             $output->writeln('<info>Done.</info>');
             return self::EXIT_SUCCESS;
         }
     } catch (ConnectException $e) {
         $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
     }
 }