<commit_before><?php

namespace SimplyTestable\ApiBundle\Tests\Controller;

class TaskControllerTest extends BaseControllerJsonTestCase {
   
    public function testCompleteAction() {        
        $this->resetSystemState();
        
        $this->createWorker('http://hydrogen.worker.simplytestable.com');
        
        $canonicalUrl = 'http://example.com/';       
        $job_id = $this->getJobIdFromUrl($this->createJob($canonicalUrl)->getTargetUrl());
        
        $this->prepareJob($canonicalUrl, $job_id);

        $taskIds = json_decode($this->getJobController('taskIdsAction')->taskIdsAction($canonicalUrl, $job_id)->getContent());        

        $result = $this->runConsole('simplytestable:task:assign', array(
            $taskIds[0] =>  true,
            $this->getFixturesDataPath(__FUNCTION__) . '/HttpResponses' => true
        ));
        
        $job = json_decode($this->fetchJob($canonicalUrl, $job_id)->getContent());
        
        $this->assertEquals(0, $result);
        $this->assertEquals('in-progress', $job->state);
        
        $response = $this->getTaskController('completeAction', array(
            'end_date_time' => '2012-03-08 17:03:00',
            'output' => '[]',
            'contentType' => 'application/json',
            'state' => 'completed',
            'errorCount' => 0,
            'warningCount' => 0
        ))->completeAction('http://hydrogen.worker.simplytestable.com', 1);
        
        $this->assertEquals(200, $response->getStatusCode());
    }
    
    
    public function testCompleteActionInMaintenanceReadOnlyModeReturns503() {        
        $this->resetSystemState();
        
        $this->createWorker('http://hydrogen.worker.simplytestable.com');
        
        $canonicalUrl = 'http://example.com/';       
        $job_id = $this->getJobIdFromUrl($this->createJob($canonicalUrl)->getTargetUrl());
        
        $this->prepareJob($canonicalUrl, $job_id);

        $taskIds = json_decode($this->getJobController('taskIdsAction')->taskIdsAction($canonicalUrl, $job_id)->getContent());        

        $result = $this->runConsole('simplytestable:task:assign', array(
            $taskIds[0] =>  true,
            $this->getFixturesDataPath(__FUNCTION__) . '/HttpResponses' => true
        ));
        
        $job = json_decode($this->fetchJob($canonicalUrl, $job_id)->getContent());
        
        $this->assertEquals(0, $result);
        $this->assertEquals('in-progress', $job->state);
        
        $this->assertEquals(0, $this->runConsole('simplytestable:maintenance:enable-read-only'));
        
        $response = $this->getTaskController('completeAction', array(
            'end_date_time' => '2012-03-08 17:03:00',<commit_msg>TaskControllerTest only rebuild db when relevant<commit_after><?php

namespace SimplyTestable\ApiBundle\Tests\Controller;

class TaskControllerTest extends BaseControllerJsonTestCase {
    
    public static function setUpBeforeClass() {
        self::setupDatabaseIfNotExists();
    }       
   
    public function testCompleteAction() {        
        $this->removeAllJobs();
        
        $this->createWorker('http://hydrogen.worker.simplytestable.com');
        
        $canonicalUrl = 'http://example.com/';       
        $job_id = $this->getJobIdFromUrl($this->createJob($canonicalUrl)->getTargetUrl());
        
        $this->prepareJob($canonicalUrl, $job_id);

        $taskIds = json_decode($this->getJobController('taskIdsAction')->taskIdsAction($canonicalUrl, $job_id)->getContent());        

        $result = $this->runConsole('simplytestable:task:assign', array(
            $taskIds[0] =>  true,
            $this->getFixturesDataPath(__FUNCTION__) . '/HttpResponses' => true
        ));
        
        $job = json_decode($this->fetchJob($canonicalUrl, $job_id)->getContent());
        
        $this->assertEquals(0, $result);
        $this->assertEquals('in-progress', $job->state);
        
        $response = $this->getTaskController('completeAction', array(
            'end_date_time' => '2012-03-08 17:03:00',
            'output' => '[]',
            'contentType' => 'application/json',
            'state' => 'completed',
            'errorCount' => 0,
            'warningCount' => 0
        ))->completeAction('http://hydrogen.worker.simplytestable.com', 1);
        
        $this->assertEquals(200, $response->getStatusCode());
    }
    
    
    public function testCompleteActionInMaintenanceReadOnlyModeReturns503() {        
        $this->removeAllJobs();
        
        $this->createWorker('http://hydrogen.worker.simplytestable.com');
        
        $canonicalUrl = 'http://example.com/';       
        $job_id = $this->getJobIdFromUrl($this->createJob($canonicalUrl)->getTargetUrl());
        
        $this->prepareJob($canonicalUrl, $job_id);

        $taskIds = json_decode($this->getJobController('taskIdsAction')->taskIdsAction($canonicalUrl, $job_id)->getContent());        

        $result = $this->runConsole('simplytestable:task:assign', array(
            $taskIds[0] =>  true,
            $this->getFixturesDataPath(__FUNCTION__) . '/HttpResponses' => true
        ));
        
        $job = json_decode($this->fetchJob($canonicalUrl, $job_id)->getContent());
        
        $this->assertEquals(0, $result);
        $this->assertEquals('in-progress', $job->state);
        
        $this->assertEquals(0, $this->runConsole('simplytestable:maintenance:enable-read-only'));
        
        $response = $this->getTaskController('completeAction', array(
            'end_date_time' => '2012-03-08 17:03:00',
{'fraction_non_alphanumeric': 0.15766969535008016, 'fraction_numerical': 0.014965259219668627, 'mean_word_length': 2.61960025789813, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 103, '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': '1891106', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1572, 'n_words': 193}