<commit_before><?php
namespace Bolt\Tests\Controller;

use Bolt\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Bolt\Tests\BoltUnitTest;
use Bolt\Controllers\Extend;
use Bolt\Composer\CommandRunner;
use Bolt\Users;

/**
 * Class to test correct operation of src/Controllers/Extend.
 *
 * @author <NAME> <<EMAIL>>
 **/


class ExtendControllerTest extends BoltUnitTest
{

    
    public function testDefaultRegistries()
    {
        
        $app = $this->getApp();
        $this->assertNotEmpty($app['extend.site']);
        $this->assertNotEmpty($app['extend.repo']);
        $runner = $app['extend.runner'];
        $this->assertInstanceOf('Bolt\Composer\CommandRunner', $runner);
        
    }
    
    public function testMethodsReturnTemplates()
    {
        $app = $this->getApp();
        $app['twig.loader.filesystem']->prependPath(TEST_ROOT."/app/view/twig");
        $this->expectOutputRegex('#Redirecting to /bolt/#');
        $app->run();
        $extend = new Extend();
        $request = Request::create("/");
        $app['request'] = $request;
        $response = $extend->overview($app, $request);
        $this->assertRegExp('#<title>Extend[^<]*</title>#', $response);
        
        
        $response = $extend->installPackage($app, $request);
        $this->assertNotEmpty($response);
        
        
        // This currently checks for a live extension on the extend site. At some point we should mock this
        // But if it fails then replacing the package name will fix the test.
        $request = Request::create("/", "GET", array('package'=>'bolt/theme-2014'));
        $extend = $this->getMock('Bolt\Controllers\Extend', array('installInfo', 'packageInfo', 'check'));
        $extend->expects($this->any())
            ->method('installInfo')
            ->will($this->returnValue(new Response('{"dev": [{"name": "bolt/theme-2014","version": "dev-master"}],"stable": []}')));

        $response = $extend->installInfo($app, $request);
        $this->assertNotEmpty($response);
        
        $request = Request::create("/", "GET", array('package'=>'bolt/theme-2014','version'=>'dev-master'));
        $extend->expects($this->any())
            ->method('packageInfo')
            ->will($this->returnValue(new Response('{"name":"bolt\/theme-2014","version":"unknown","type":"unknown","descrip":""}')));
        
        
        $response = $extend->packageInfo($app, $request);
        $this->assertNotEmpty($response);
        $content = json_decode($response->getContent());
        $this->assertAttributeNotEmpty('name', $content);
        
        $request = Request::create("/");

        $extend->expects($this->any())
            ->method('check')
            ->will($this->returnValue(new Response('{"updates":[],"installs":[]}')));
        
        $response = $extend->check($app, $request);
        $this->assertNotEmpty($response);
    }
    




}<commit_msg>Use new PackageManager over CommandRunner<commit_after><?php
namespace Bolt\Tests\Controller;

use Bolt\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Bolt\Tests\BoltUnitTest;
use Bolt\Controllers\Extend;
use Bolt\Composer\PackageManager;
use Bolt\Users;

/**
 * Class to test correct operation of src/Controllers/Extend.
 *
 * @author <NAME> <<EMAIL>>
 **/


class ExtendControllerTest extends BoltUnitTest
{
    public function testDefaultRegistries()
    {

        $app = $this->getApp();
        $this->assertNotEmpty($app['extend.site']);
        $this->assertNotEmpty($app['extend.repo']);
        $runner = $app['extend.manager'];
        $this->assertInstanceOf('Bolt\Composer\PackageManager', $runner);

    }

    public function testMethodsReturnTemplates()
    {
        $app = $this->getApp();
        $app['twig.loader.filesystem']->prependPath(TEST_ROOT."/app/view/twig");
        $this->expectOutputRegex('#Redirecting to /bolt/#');
        $app->run();
        $extend = new Extend();
        $request = Request::create("/");
        $app['request'] = $request;
        $response = $extend->overview($app, $request);
        $this->assertRegExp('#<title>Extend[^<]*</title>#', $response);


        $response = $extend->installPackage($app, $request);
        $this->assertNotEmpty($response);


        // This currently checks for a live extension on the extend site. At some point we should mock this
        // But if it fails then replacing the package name will fix the test.
        $request = Request::create("/", "GET", array('package'=>'bolt/theme-2014'));
        $extend = $this->getMock('Bolt\Controllers\Extend', array('installInfo', 'packageInfo', 'check'));
        $extend->expects($this->any())
            ->method('installInfo')
            ->will($this->returnValue(new Response('{"dev": [{"name": "bolt/theme-2014","version": "dev-master"}],"stable": []}')));

        $response = $extend->installInfo($app, $request);
        $this->assertNotEmpty($response);

        $request = Request::create("/", "GET", array('package'=>'bolt/theme-2014','version'=>'dev-master'));
        $extend->expects($this->any())
            ->method('packageInfo')
            ->will($this->returnValue(new Response('{"name":"bolt\/theme-2014","version":"unknown","type":"unknown","descrip":""}')));


        $response = $extend->packageInfo($app, $request);
        $this->assertNotEmpty($response);
        $content = json_decode($response->getContent());
        $this->assertAttributeNotEmpty('name', $content);

        $request = Request::create("/");

        $extend->expects($this->any())
            ->method('check')
            ->will($this->returnValue(new Response('{"updates":[],"installs":[]}')));

        $response = $extend->check($app, $request);
        $this->assertNotEmpty($response);
    }

}
{'fraction_non_alphanumeric': 0.18982820207518286, 'fraction_numerical': 0.005443102568464024, 'mean_word_length': 3.1613588110403397, 'pattern_counts': {'":': 20, '<': 17, '<?xml version=': 0, '>': 91, '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': '7647743', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1673, 'n_words': 294}