<commit_before><?php

namespace SimplyTestable\WebClientBundle\Controller;

use SimplyTestable\WebClientBundle\Entity\Test\Test;
use SimplyTestable\WebClientBundle\Entity\Task\Task;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use SimplyTestable\WebClientBundle\Exception\UserServiceException;
use SimplyTestable\WebClientBundle\Model\RemoteTest\RemoteTest;

class TestProgressController extends TestViewController
{       
    /**
     *
     * @var \SimplyTestable\WebClientBundle\Services\TestOptions\Adapter\Request
     */
    private $testOptionsAdapter = null;    
    
    
    private $testFinishedStates = array(
        'cancelled',
        'completed',
        'failed-no-sitemap',
        'rejected'
    );   
    
    private $testStateLabelMap = array(
        'new' => 'New, waiting to start',
        'queued' => 'Queued, waiting for first test to begin',
        'preparing' => 'Finding URLs to test: looking for sitemap or news feed',
        'crawling' => 'Finding URLs to test',
        'failed-no-sitemap' => 'Finding URLs to test: preparing to crawl'
    );
    
    private $testStateIconMap = array(
        'new' => 'icon-off',
        'queued' => 'icon-off',
        'queued-for-assignment' => 'icon-off',
        'preparing' => 'icon-search',
        'crawling' => 'icon-search',        
        'failed-no-sitemap' => 'icon-search',         
        'in-progress' => 'icon-play-circle'        
    );
    
    public function indexAction($website, $test_id) {                        
        $this->getTestService()->getRemoteTestService()->setUser($this->getUser());
        
        if ($this->isUsingOldIE()) {
            return $this->forward('SimplyTestableWebClientBundle:App:outdatedBrowser');
        }
        
        $testRetrievalOutcome = $this->getTestRetrievalOutcome($website, $test_id);
        if ($testRetrievalOutcome->hasResponse()) {            
            return $testRetrievalOutcome->getResponse();
        }
        
        $test = $testRetrievalOutcome->getTest();
        $isOwner = $this->getTestService()->getRemoteTestService()->owns();
        $isPublicUserTest = $test->getUser() == $this->getUserService()->getPublicUser()->getUsername();
        
        if (in_array($test->getState(), $this->testFinishedStates)) {            
            if ($test->getState() !== 'failed-no-sitemap') {
                return $this->redirect($this->getResultsUrl($website, $test_id));                
            }
            
            if ($this->getUserService()->isPublicUser($this->getUser()) && $isOwner) {
                return $this->redirect($this->getResultsUrl($website, $test_id));
            }
        }       
        
        if ($test->getWebsite() != $website) {
            return $this->redirect($this->generateUrl('app_test_redirector', array(
                'website' => $test->getWebsite(),
                'test_id' => $test_id
            ), true));            
        }      
        
        $remoteTest = $this->getTestService()->getRemoteTestService()->get();        
         
        if ($test->getState() == 'failed-no-sitemap' && isset($remoteTest->crawl)) {
            $test->setState('crawling');
        }
        <commit_msg>Forward to re-test action when viewing failed-no-sitemap job as signed in user<commit_after><?php

namespace SimplyTestable\WebClientBundle\Controller;

use SimplyTestable\WebClientBundle\Entity\Test\Test;
use SimplyTestable\WebClientBundle\Entity\Task\Task;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use SimplyTestable\WebClientBundle\Exception\UserServiceException;
use SimplyTestable\WebClientBundle\Model\RemoteTest\RemoteTest;

class TestProgressController extends TestViewController
{       
    /**
     *
     * @var \SimplyTestable\WebClientBundle\Services\TestOptions\Adapter\Request
     */
    private $testOptionsAdapter = null;    
    
    
    private $testFinishedStates = array(
        'cancelled',
        'completed',
        'failed-no-sitemap',
        'rejected'
    );   
    
    private $testStateLabelMap = array(
        'new' => 'New, waiting to start',
        'queued' => 'Queued, waiting for first test to begin',
        'preparing' => 'Finding URLs to test: looking for sitemap or news feed',
        'crawling' => 'Finding URLs to test',
        'failed-no-sitemap' => 'Finding URLs to test: preparing to crawl'
    );
    
    private $testStateIconMap = array(
        'new' => 'icon-off',
        'queued' => 'icon-off',
        'queued-for-assignment' => 'icon-off',
        'preparing' => 'icon-search',
        'crawling' => 'icon-search',        
        'failed-no-sitemap' => 'icon-search',         
        'in-progress' => 'icon-play-circle'        
    );
    
    public function indexAction($website, $test_id) {                        
        $this->getTestService()->getRemoteTestService()->setUser($this->getUser());
        
        if ($this->isUsingOldIE()) {
            return $this->forward('SimplyTestableWebClientBundle:App:outdatedBrowser');
        }
        
        $testRetrievalOutcome = $this->getTestRetrievalOutcome($website, $test_id);
        if ($testRetrievalOutcome->hasResponse()) {            
            return $testRetrievalOutcome->getResponse();
        }
        
        $test = $testRetrievalOutcome->getTest();
        $isOwner = $this->getTestService()->getRemoteTestService()->owns();
        $isPublicUserTest = $test->getUser() == $this->getUserService()->getPublicUser()->getUsername();
        
        if (in_array($test->getState(), $this->testFinishedStates)) {            
            if ($test->getState() !== 'failed-no-sitemap') {
                return $this->redirect($this->getResultsUrl($website, $test_id));                
            }
            
            if ($this->getUserService()->isPublicUser($this->getUser()) && $isOwner) {
                return $this->redirect($this->getResultsUrl($website, $test_id));
            }
        }       
        
        if ($test->getWebsite() != $website) {
            return $this->redirect($this->generateUrl('app_test_redirector', array(
                'website' => $test->getWebsite(),
                'test_id' => $test_id
            ), true));            
        }      
        
        $remoteTest = $this->getTestService()->getRemoteTestService()->get();        
        
        if ($test->getState() == 'failed-no-sitemap' && is_null($remoteTest->getCrawl())) {
            return $this->forward('SimplyTestableWebClientBundle:Test:retest', array(
                'website' => $website,
                'test_id' => $test_id
            ));
        }
        
{'fraction_non_alphanumeric': 0.1418869038830651, 'fraction_numerical': 0.0, 'mean_word_length': 2.2303290414878396, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 107, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6001812', 'n_tokens_mistral': 1944, 'n_tokens_neox': 1892, 'n_words': 305}