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

use Bolt\Provider\NutServiceProvider;
use Bolt\Tests\BoltUnitTest;

/**
 * Class to test src/BaseExtension.
 *
 * @author <NAME> <<EMAIL>>
 *
 * @runTestsInSeparateProcesses
 */
class BaseExtensionTest extends BoltUnitTest
{
    public function setup()
    {
        $this->php = \PHPUnit_Extension_FunctionMocker::start($this, 'Bolt')
            ->mockFunction('file_exists')
            ->mockFunction('is_readable')
            ->mockFunction('is_dir')
            ->mockFunction('copy')
            ->mockFunction('file_get_contents')
            ->getMock();

        $this->php2 = \PHPUnit_Extension_FunctionMocker::start($this, 'Bolt\Tests\Extensions\Mock')
            ->mockFunction('file_get_contents')
            ->getMock();
    }

    public function tearDown()
    {
        \PHPUnit_Extension_FunctionMocker::tearDown();
        @unlink(TEST_ROOT . '/app/cache/config_cache.php');
    }

    public function testSetup()
    {
        $app = $this->getApp();
        $ext = $this->getMockForAbstractClass('Bolt\BaseExtension', array($app));
        $this->assertNotEmpty($ext->getBasePath());
        $this->assertNotEmpty($ext->getBaseUrl());
        $this->assertEquals('mockobject', $ext->getMachineName());
    }

    public function testComposerLoading()
    {
        $app = $this->makeApp();
        $app['resources']->setPath('extensions', __DIR__."/resources");
        $app->initialize();
        $this->assertTrue($app['extensions']->isEnabled('testlocal'));
        $config = $app['extensions.testlocal']->getExtensionConfig();
        $this->assertNotEmpty($config);
    }

    public function testGetBasePath()
    {
        $app = $this->makeApp();
        $ext = $this->getMockForAbstractClass('Bolt\BaseExtension', array($app));
        $this->assertNotEmpty(strpos($ext->getBasePath()->string(), 'MockObject'));
    }

    public function testGetBaseUrl()
    {
        $app = $this->makeApp();
        $ext = $this->getMockForAbstractClass('Bolt\BaseExtension', array($app));
        $this->assertEquals(0, strpos($ext->getBaseUrl(), '/extensions'));
    }

    public function testGetComposerNameDefault()
    {
        $app = $this->makeApp();
        $ext = $this->getMockForAbstractClass('Bolt\BaseExtension', array($app));
        $this->assertNull($ext->getComposerName());
    }

    public function testGetComposerName()
    {
        $app = $this->makeApp();
        $ext = $this->getMockForAbstractClass('Bolt\BaseExtension', array($app));
        $this->assertNull($ext->getComposerName());
        $ext->setComposerConfiguration(array('name' => 'valuefrommock'));

        $this->assertEquals('valuefrommock', $ext->getComposerName());
    }

    public function testGetMachineName()
    {
        $app = $this->makeApp();
        $ext = $this->getMockForAbstractClass('Bolt\BaseExtension', array($app));

        // Machine name calculated from the Class name in this case MockObject
        $this->assertEquals('mockobject', $ext->getMachineName());
        $ext->setComposerConfiguration(array('name' => 'valuefrommock'));
        $this->assertEquals('valuefrommock', $ext->getMachineName());
    }

    public function testSetComposerConfiguration()
    {
        $app = $this->makeApp();
        $ext = $this->getMockForAbstractClass('Bolt\BaseExtension', array($app));
        $this->setExpectedException(get_class(new \PHPUnit_Framework_Error('', 0, '', 1)));
        $ext->setComposerConfiguration('stringsinvalid');
    }

    public function testGetExtensionConfig()
    {<commit_msg>Allow skipping testSetComposerConfiguration() for PHP 7<commit_after><?php
namespace Bolt\Tests\Extensions;

use Bolt\Provider\NutServiceProvider;
use Bolt\Tests\BoltUnitTest;

/**
 * Class to test src/BaseExtension.
 *
 * @author <NAME> <<EMAIL>>
 *
 * @runTestsInSeparateProcesses
 */
class BaseExtensionTest extends BoltUnitTest
{
    public function setup()
    {
        $this->php = \PHPUnit_Extension_FunctionMocker::start($this, 'Bolt')
            ->mockFunction('file_exists')
            ->mockFunction('is_readable')
            ->mockFunction('is_dir')
            ->mockFunction('copy')
            ->mockFunction('file_get_contents')
            ->getMock();

        $this->php2 = \PHPUnit_Extension_FunctionMocker::start($this, 'Bolt\Tests\Extensions\Mock')
            ->mockFunction('file_get_contents')
            ->getMock();
    }

    public function tearDown()
    {
        \PHPUnit_Extension_FunctionMocker::tearDown();
        @unlink(TEST_ROOT . '/app/cache/config_cache.php');
    }

    public function testSetup()
    {
        $app = $this->getApp();
        $ext = $this->getMockForAbstractClass('Bolt\BaseExtension', array($app));
        $this->assertNotEmpty($ext->getBasePath());
        $this->assertNotEmpty($ext->getBaseUrl());
        $this->assertEquals('mockobject', $ext->getMachineName());
    }

    public function testComposerLoading()
    {
        $app = $this->makeApp();
        $app['resources']->setPath('extensions', __DIR__."/resources");
        $app->initialize();
        $this->assertTrue($app['extensions']->isEnabled('testlocal'));
        $config = $app['extensions.testlocal']->getExtensionConfig();
        $this->assertNotEmpty($config);
    }

    public function testGetBasePath()
    {
        $app = $this->makeApp();
        $ext = $this->getMockForAbstractClass('Bolt\BaseExtension', array($app));
        $this->assertNotEmpty(strpos($ext->getBasePath()->string(), 'MockObject'));
    }

    public function testGetBaseUrl()
    {
        $app = $this->makeApp();
        $ext = $this->getMockForAbstractClass('Bolt\BaseExtension', array($app));
        $this->assertEquals(0, strpos($ext->getBaseUrl(), '/extensions'));
    }

    public function testGetComposerNameDefault()
    {
        $app = $this->makeApp();
        $ext = $this->getMockForAbstractClass('Bolt\BaseExtension', array($app));
        $this->assertNull($ext->getComposerName());
    }

    public function testGetComposerName()
    {
        $app = $this->makeApp();
        $ext = $this->getMockForAbstractClass('Bolt\BaseExtension', array($app));
        $this->assertNull($ext->getComposerName());
        $ext->setComposerConfiguration(array('name' => 'valuefrommock'));

        $this->assertEquals('valuefrommock', $ext->getComposerName());
    }

    public function testGetMachineName()
    {
        $app = $this->makeApp();
        $ext = $this->getMockForAbstractClass('Bolt\BaseExtension', array($app));

        // Machine name calculated from the Class name in this case MockObject
        $this->assertEquals('mockobject', $ext->getMachineName());
        $ext->setComposerConfiguration(array('name' => 'valuefrommock'));
        $this->assertEquals('valuefrommock', $ext->getMachineName());
    }

    public function testSetComposerConfiguration()
    {
        if (version_compare(PHP_VERSION, '7', '>=')) {
            $this->markTestSkipped('Revist this test when exception handling stablises.');
        }
        $app = $this->makeApp();
        $ext = $this->getMockForAbstractClass('Bolt\BaseExtension', array($app));
        $this->setExpectedException(get_class(new \PHPUnit_Framework_Error('', 0, '', 1)));
        $ext->setComposerConfiguration('stringsinvalid');
    }

    public function testGetExtensionConfig()
    {
{'fraction_non_alphanumeric': 0.16387009472259811, 'fraction_numerical': 0.0013531799729364006, 'mean_word_length': 3.2306811677160847, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 127, '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': '367042', 'n_tokens_mistral': 2141, 'n_tokens_neox': 2106, 'n_words': 315}