<commit_before><?php

namespace webignition\HttpRedirectLoopDetector;

class HttpRedirectLoopDetectorTest extends \PHPUnit_Framework_TestCase {
    
    public function testHasDirectRedirectLoop() {
        $httpClient = new \Guzzle\Http\Client();
        $mockPlugin = new \Guzzle\Plugin\Mock\MockPlugin();
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/'));
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/'));
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/'));
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/'));
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/'));        
        $httpClient->addSubscriber($mockPlugin);
        
        $detector = new \webignition\HttpRedirectLoopDetector\HttpRedirectLoopDetector();
        $detector->setHttpClient($httpClient);
        $detector->setUrl('http://example.com/');
        $this->assertTrue($detector->test());
    }
    
    public function testHasIndirectRedirectLoop() {
        $httpClient = new \Guzzle\Http\Client();
        $mockPlugin = new \Guzzle\Plugin\Mock\MockPlugin();
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/2/'));
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/'));
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/2/'));
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/'));
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/2/'));        
        $httpClient->addSubscriber($mockPlugin);
        
        $detector = new \webignition\HttpRedirectLoopDetector\HttpRedirectLoopDetector();
        $detector->setHttpClient($httpClient);
        $detector->setUrl('http://example.com/');
        $this->assertTrue($detector->test());
    }    
    
}<commit_msg>Add tests for no redirect loop<commit_after><?php

namespace webignition\HttpRedirectLoopDetector;

class HttpRedirectLoopDetectorTest extends \PHPUnit_Framework_TestCase {
    
    public function testHasDirectRedirectLoop() {
        $httpClient = new \Guzzle\Http\Client();
        $mockPlugin = new \Guzzle\Plugin\Mock\MockPlugin();
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/'));
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/'));
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/'));
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/'));
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/'));        
        $httpClient->addSubscriber($mockPlugin);
        
        $detector = new \webignition\HttpRedirectLoopDetector\HttpRedirectLoopDetector();
        $detector->setHttpClient($httpClient);
        $detector->setUrl('http://example.com/');
        $this->assertTrue($detector->test());
    }
    
    public function testHasIndirectRedirectLoop() {
        $httpClient = new \Guzzle\Http\Client();
        $mockPlugin = new \Guzzle\Plugin\Mock\MockPlugin();
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/2/'));
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/'));
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/2/'));
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/'));
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/2/'));        
        $httpClient->addSubscriber($mockPlugin);
        
        $detector = new \webignition\HttpRedirectLoopDetector\HttpRedirectLoopDetector();
        $detector->setHttpClient($httpClient);
        $detector->setUrl('http://example.com/');
        $this->assertTrue($detector->test());
    } 
    
    public function testHasNoDirectRedirectLoop() {
        $httpClient = new \Guzzle\Http\Client();
        $mockPlugin = new \Guzzle\Plugin\Mock\MockPlugin();
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 200 Ok'));     
        $httpClient->addSubscriber($mockPlugin);
        
        $detector = new \webignition\HttpRedirectLoopDetector\HttpRedirectLoopDetector();
        $detector->setHttpClient($httpClient);
        $detector->setUrl('http://example.com/');
        $this->assertFalse($detector->test());        
    }
    
    public function testHasNoIndirectRedirectLoop() {
        $httpClient = new \Guzzle\Http\Client();
        $mockPlugin = new \Guzzle\Plugin\Mock\MockPlugin();
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301'."\n".'Location: http://example.com/2/'));
        $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 200'));
        $httpClient->addSubscriber($mockPlugin);
        
        $detector = new \webignition\HttpRedirectLoopDetector\HttpRedirectLoopDetector();
        $detector->setHttpClient($httpClient);
        $detector->setUrl('http://example.com/');
        $this->assertFalse($detector->test());        
    }    
    
}
{'fraction_non_alphanumeric': 0.18184780837542774, 'fraction_numerical': 0.019879419912009123, 'mean_word_length': 3.457516339869281, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 56, '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': '2656076', 'n_tokens_mistral': 1942, 'n_tokens_neox': 1820, 'n_words': 183}