<commit_before><?php
namespace Neos\FluidAdaptor\Tests\Unit\ViewHelpers\Format;

/*
 * This file is part of the Neos.FluidAdaptor package.
 *
 * (c) Contributors of the Neos Project - www.neos.io
 *
 * This package is Open Source Software. For the full copyright and license
 * information, please view the LICENSE file which was distributed with this
 * source code.
 */

require_once(__DIR__ . '/../ViewHelperBaseTestcase.php');

use Neos\FluidAdaptor\Core\Rendering\RenderingContext;
use Neos\FluidAdaptor\ViewHelpers\Format\CaseViewHelper;
use Neos\FluidAdaptor\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;

/**
 * Test for \Neos\FluidAdaptor\ViewHelpers\Format\CaseViewHelper
 */
class CaseViewHelperTest extends ViewHelperBaseTestcase
{
    /**
     * @var \Neos\FluidAdaptor\ViewHelpers\Format\CaseViewHelper
     */
    protected $viewHelper;

    /**
     * @var RenderingContext
     */
    protected $renderingContextMock;

    /**
     * Holds the initial mb_internal_encoding value found on this system in order to restore it after the tests
     * @var string
     */
    protected $originalMbEncodingValue;

    public function setUp()
    {
        parent::setUp();
        $this->renderingContext = $this->getMockBuilder(RenderingContext::class)->disableOriginalConstructor()->getMock();
        $this->viewHelper = new CaseViewHelper();
        $this->viewHelper->setRenderingContext($this->renderingContext);
            //$this->getMockBuilder(\Neos\FluidAdaptor\ViewHelpers\Format\CaseViewHelper::class)->setMethods(array('renderChildren'))->getMock();
        $this->originalMbEncodingValue = mb_internal_encoding();
    }

    /**
     */
    protected function tearDown()
    {
        parent::tearDown();
        mb_internal_encoding($this->originalMbEncodingValue);
    }

    /**
     * @test
     */
    public function viewHelperRendersChildrenIfGivenValueIsNull()
    {
        $testString = 'child was here';
        $this->viewHelper->setRenderChildrenClosure(function () use ($testString) {
            return $testString;
        });

        $result = $this->viewHelper->render();
        $this->assertEquals(strtoupper($testString), $result);
    }

    /**
     *
     */
    public function testStringDataProvider()
    {
        return [
            ['', ''],
            [0, '0'],
            ['foo', 'FOO']
        ];
    }

    /**
     * @dataProvider testStringDataProvider
     * @test
     */
    public function viewHelperDoesNotRenderChildrenIfGivenValueIsNotNull($testString, $expected)
    {
        $result = $this->viewHelper->render($testString);
        $this->assertEquals($expected, $result);
    }

    /**
     * @test
     * @expectedException \Neos\FluidAdaptor\Core\ViewHelper\Exception\InvalidVariableException
     */
    public function viewHelperThrowsExceptionIfIncorrectModeIsGiven()
    {
        $this->viewHelper->render('Foo', 'incorrectMode');
    }

    /**
     * @test
     */
    public function viewHelperRestoresMbInternalEncodingValueAfterInvocation()
    {
        mb_internal_encoding('ASCII');
        $this->viewHelper->render('dummy');<commit_msg>TASK: Remove a "risky test" warning<commit_after><?php
namespace Neos\FluidAdaptor\Tests\Unit\ViewHelpers\Format;

/*
 * This file is part of the Neos.FluidAdaptor package.
 *
 * (c) Contributors of the Neos Project - www.neos.io
 *
 * This package is Open Source Software. For the full copyright and license
 * information, please view the LICENSE file which was distributed with this
 * source code.
 */

require_once(__DIR__ . '/../ViewHelperBaseTestcase.php');

use Neos\FluidAdaptor\Core\Rendering\RenderingContext;
use Neos\FluidAdaptor\ViewHelpers\Format\CaseViewHelper;
use Neos\FluidAdaptor\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;

/**
 * Test for \Neos\FluidAdaptor\ViewHelpers\Format\CaseViewHelper
 */
class CaseViewHelperTest extends ViewHelperBaseTestcase
{
    /**
     * @var \Neos\FluidAdaptor\ViewHelpers\Format\CaseViewHelper
     */
    protected $viewHelper;

    /**
     * @var RenderingContext
     */
    protected $renderingContextMock;

    /**
     * Holds the initial mb_internal_encoding value found on this system in order to restore it after the tests
     * @var string
     */
    protected $originalMbEncodingValue;

    public function setUp()
    {
        parent::setUp();
        $this->renderingContext = $this->getMockBuilder(RenderingContext::class)->disableOriginalConstructor()->getMock();
        $this->viewHelper = new CaseViewHelper();
        $this->viewHelper->setRenderingContext($this->renderingContext);
            //$this->getMockBuilder(\Neos\FluidAdaptor\ViewHelpers\Format\CaseViewHelper::class)->setMethods(array('renderChildren'))->getMock();
        $this->originalMbEncodingValue = mb_internal_encoding();
    }

    /**
     */
    protected function tearDown()
    {
        parent::tearDown();
        mb_internal_encoding($this->originalMbEncodingValue);
    }

    /**
     * @test
     */
    public function viewHelperRendersChildrenIfGivenValueIsNull()
    {
        $testString = 'child was here';
        $this->viewHelper->setRenderChildrenClosure(function () use ($testString) {
            return $testString;
        });

        $result = $this->viewHelper->render();
        $this->assertEquals(strtoupper($testString), $result);
    }

    /**
     *
     */
    public function fixtureStringDataProvider()
    {
        return [
            ['', ''],
            [0, '0'],
            ['foo', 'FOO']
        ];
    }

    /**
     * @dataProvider fixtureStringDataProvider
     * @test
     */
    public function viewHelperDoesNotRenderChildrenIfGivenValueIsNotNull($testString, $expected)
    {
        $result = $this->viewHelper->render($testString);
        $this->assertEquals($expected, $result);
    }

    /**
     * @test
     * @expectedException \Neos\FluidAdaptor\Core\ViewHelper\Exception\InvalidVariableException
     */
    public function viewHelperThrowsExceptionIfIncorrectModeIsGiven()
    {
        $this->viewHelper->render('Foo', 'incorrectMode');
    }

    /**
     * @test
     */
    public function viewHelperRestoresMbInternalEncodingValueAfterInvocation()
    {
        mb_internal_encoding('ASCII');
        $this->viewHelper->render('dummy');
{'fraction_non_alphanumeric': 0.12313314267556402, 'fraction_numerical': 0.0006355258976803305, 'mean_word_length': 2.9741161616161618, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '376468', 'n_tokens_mistral': 1816, 'n_tokens_neox': 1798, 'n_words': 314}