<commit_before><?php

namespace PHPOrchestra\ApiBundle\Test\Transformer;

use Phake;
use PHPOrchestra\ApiBundle\Transformer\BlockTransformer;

/**
 * Class BlockTransformerTest
 */
class BlockTransformerTest extends \PHPUnit_Framework_TestCase
{
    protected $displayBlockManager;
    protected $translator;
    protected $blockTransformer;
    protected $blockFacade;
    protected $node;

    /**
     * Set up the test
     */
    public function setUp()
    {
        $this->displayBlockManager = Phake::mock('PHPOrchestra\DisplayBundle\DisplayBlock\DisplayBlockManager');
        $this->translator = Phake::mock('Symfony\Component\Translation\TranslatorInterface');
        $this->node = Phake::mock('PHPOrchestra\ModelBundle\Model\NodeInterface');
        $this->blockFacade = Phake::mock('PHPOrchestra\ApiBundle\Facade\BlockFacade');

        $this->blockTransformer = new BlockTransformer($this->displayBlockManager, $this->translator);
    }

    /**
     * Test getName
     */
    public function testGetName()
    {
        $name = $this->blockTransformer->getName();

        $this->assertSame('block', $name);
    }

    /**
     * Test transform
     *
     * @param string      $component
     * @param array       $attributes
     * @param string      $label
     * @param string|null $nodeId
     * @param int|null    $blockNumber
     *
     * @dataProvider blockTransformProvider
     */
    public function testTransform($component, $attributes, $label, $nodeId = null, $blockNumber = null)
    {
        $html = 'ok';
        $block = Phake::mock('PHPOrchestra\ModelBundle\Model\BlockInterface');
        $response = Phake::mock('Symfony\Component\HttpFoundation\Response');
        $transformer = Phake::mock('PHPOrchestra\ApiBundle\Transformer\TransformerInterface');
        $transformerManager = Phake::mock('PHPOrchestra\ApiBundle\Transformer\TransformerManager');
        $facade = Phake::mock('PHPOrchestra\ApiBundle\Facade\UiModelFacade');

        Phake::when($block)->getComponent()->thenReturn($component);
        Phake::when($this->translator)->trans(Phake::anyParameters())->thenReturn($label);
        Phake::when($block)->getAttributes()->thenReturn($attributes);
        Phake::when($this->displayBlockManager)->show($block)->thenReturn($response);
        Phake::when($response)->getContent()->thenReturn($html);

        $this->blockTransformer->setContext($transformerManager);

        Phake::when($transformerManager)->get('ui_model')->thenReturn($transformer);
        Phake::when($transformer)->transform(Phake::anyParameters())->thenReturn($facade);

        $facadeExcepted = $this->blockTransformer->transform($block, true);

        $this->assertInstanceOf('PHPOrchestra\ApiBundle\Facade\BlockFacade', $facadeExcepted);
        $this->assertSame($component, $facadeExcepted->component);
        $this->assertInstanceOf('PHPOrchestra\ApiBundle\Facade\UiModelFacade', $facadeExcepted->uiModel);
        $this->assertSame($attributes, $facadeExcepted->getAttributes());
    }

    /**
     * @return array
     */
    public function blockTransformProvider()
    {
        return array(
            array('sample', array('title' => 'title one', 'author' => 'me'), 'Sample'),
            array(
                'sample',
                array('title' => 'news', 'author' => 'benj', 'text' => 'hello world'),
                'Sample',
                'fixture_full',
                5
            ),
            array(
                'news',
                array('title' => 'news', 'author' => 'benj', 'text' => 'hello every body'),
                'News',
                'fixture_home',
                3
            ),
            array(
                'menu',
                array(),
                'Menu',
                2
            ),
        );
    }

    /**
     * @param string $nodeId
     * @param array  $result<commit_msg>update test<commit_after><?php

namespace PHPOrchestra\ApiBundle\Test\Transformer;

use Phake;
use PHPOrchestra\ApiBundle\Transformer\BlockTransformer;

/**
 * Class BlockTransformerTest
 */
class BlockTransformerTest extends \PHPUnit_Framework_TestCase
{
    protected $displayBlockManager;
    protected $translator;
    protected $blockTransformer;
    protected $blockFacade;
    protected $node;

    /**
     * Set up the test
     */
    public function setUp()
    {
        $this->displayBlockManager = Phake::mock('PHPOrchestra\DisplayBundle\DisplayBlock\DisplayBlockManager');
        $this->translator = Phake::mock('Symfony\Component\Translation\TranslatorInterface');
        $this->node = Phake::mock('PHPOrchestra\ModelBundle\Model\NodeInterface');
        $this->blockFacade = Phake::mock('PHPOrchestra\ApiBundle\Facade\BlockFacade');

        $this->blockTransformer = new BlockTransformer($this->displayBlockManager, $this->translator);
    }

    /**
     * Test getName
     */
    public function testGetName()
    {
        $name = $this->blockTransformer->getName();

        $this->assertSame('block', $name);
    }

    /**
     * Test transform
     *
     * @param string      $component
     * @param array       $attributes
     * @param string      $label
     * @param string|null $nodeId
     * @param int|null    $blockNumber
     *
     * @dataProvider blockTransformProvider
     */
    public function testTransform($component, $attributes, $label, $nodeId = null, $blockNumber = null)
    {
        $html = 'ok';
        $block = Phake::mock('PHPOrchestra\ModelBundle\Model\BlockInterface');
        $response = Phake::mock('Symfony\Component\HttpFoundation\Response');
        $transformer = Phake::mock('PHPOrchestra\ApiBundle\Transformer\TransformerInterface');
        $transformerManager = Phake::mock('PHPOrchestra\ApiBundle\Transformer\TransformerManager');
        $facade = Phake::mock('PHPOrchestra\ApiBundle\Facade\UiModelFacade');

        Phake::when($block)->getComponent()->thenReturn($component);
        Phake::when($this->translator)->trans(Phake::anyParameters())->thenReturn($label);
        Phake::when($block)->getAttributes()->thenReturn($attributes);
        Phake::when($this->displayBlockManager)->show($block)->thenReturn($response);
        Phake::when($response)->getContent()->thenReturn($html);

        $this->blockTransformer->setContext($transformerManager);

        Phake::when($transformerManager)->get('ui_model')->thenReturn($transformer);
        Phake::when($transformer)->transform(Phake::anyParameters())->thenReturn($facade);

        $facadeExcepted = $this->blockTransformer->transform($block, true);

        $this->assertInstanceOf('PHPOrchestra\ApiBundle\Facade\BlockFacade', $facadeExcepted);
        $this->assertSame($component, $facadeExcepted->component);
        $this->assertInstanceOf('PHPOrchestra\ApiBundle\Facade\UiModelFacade', $facadeExcepted->uiModel);
        $this->assertSame($attributes, $facadeExcepted->getAttributes());
    }

    /**
     * @return array
     */
    public function blockTransformProvider()
    {
        return array(
            array('sample', array('title' => 'title one', 'author' => 'me'), 'Sample'),
            array(
                'sample',
                array('title' => 'news', 'author' => 'benj', 'text' => 'Hello world'),
                'Sample',
                'fixture_full',
                5
            ),
            array(
                'news',
                array('title' => 'news', 'author' => 'benj', 'text' => 'Hello everybody'),
                'News',
                'fixture_home',
                3
            ),
            array(
                'menu',
                array(),
                'Menu',
                2
            ),
        );
    }

    /**
     * @param string $nodeId
     * @param array  $result
{'fraction_non_alphanumeric': 0.14684325575414683, 'fraction_numerical': 0.0007715057220007715, 'mean_word_length': 2.681022243256034, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 93, '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': '5994853', 'n_tokens_mistral': 2163, 'n_tokens_neox': 2130, 'n_words': 319}