<commit_before><?php

namespace Oro\Bundle\WorkflowBundle\Tests\Unit\Configuration\Handler;

use Oro\Bundle\WorkflowBundle\Configuration\Handler\StepHandler;
use Oro\Bundle\WorkflowBundle\Configuration\WorkflowConfiguration;

class StepHandlerTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var StepHandler
     */
    protected $handler;

    protected function setUp()
    {
        $this->handler = new StepHandler();
    }

    /**
     * @param array $expected
     * @param array $input
     * @dataProvider handleDataProvider
     */
    public function testHandle(array $expected, array $input)
    {
        $this->assertEquals($expected, $this->handler->handle($input));
    }

    /**
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     *
     * @return array
     */
    public function handleDataProvider()
    {
        return array(
            'simple configuration' => array(
                'expected' => array(
                    'start_step' => 'first_step',
                    WorkflowConfiguration::NODE_STEPS => array(
                        array(
                            'name' => 'first_step',
                            'label' => 'First Step',
                            'order' => 10,
                            'is_final' => true,
                            'allowed_transitions' => array(),
                        ),
                    ),
                    WorkflowConfiguration::NODE_TRANSITIONS => array(
                        array(
                            'name' => 'start_transition',
                            'is_start' => true,
                        ),
                    ),
                ),
                'input' => array(
                    'start_step' => 'first_step',
                    WorkflowConfiguration::NODE_STEPS => array(
                        array(
                            'name' => 'step:starting_point',
                            'order' => -1,
                            '_is_start' => true,
                            'is_final' => false,
                            'allowed_transitions' => array('start_transition'),
                        ),
                        array(
                            'name' => 'first_step',
                            'label' => 'First Step',
                            'order' => 10,
                            '_is_start' => false,
                            'is_final' => true,
                        ),
                    ),
                    WorkflowConfiguration::NODE_TRANSITIONS => array(
                        array(
                            'name' => 'start_transition'
                        ),
                    ),
                ),
            ),
            'full configuration' => array(
                'expected' => array(
                    'start_step' => null,
                    WorkflowConfiguration::NODE_STEPS => array(
                        array(
                            'name' => 'first_step',
                            'label' => 'First Step',
                            'order' => 10,
                            'is_final' => false,
                            'entity_acl' => array('attribute' => array('delete' => false)),
                            'allowed_transitions' => array('regular_transition'),
                        ),
                        array(
                            'name' => 'second_step',
                            'label' => 'second_step',
                            'order' => 20,
                            'is_final' => true,
                            'allowed_transitions' => array(),
                        ),
                    ),
                    WorkflowConfiguration::NODE_TRANSITIONS => array(
                        array(
                            'name' => 'start_transition',
                            'is_start' => true,
                        ),
                        array(
                            'name' => 'regular_transition',
                            'is_start' => false,
                        ),
                    ),
                ),
                'input' => array(
                    'start_step' => 'unknown_step',
                    WorkflowConfiguration::NODE_STEPS => array(
                        array(
                            'name' => 'step:starting_point',
                            'order' => -1,
                            '_is_start' => true,
                            'is_final' => false,
                            'allowed_transitions' => array('start_transition'),
                        ),
                        array(
                            'name' => 'first_step',
                            'label' => 'First Step',
                            'order' => 10,
                            '_is_start' => false,
                            'is_final' => false,
                            'entity_acl' => array('attribute' => array('delete' => false)),
                            'allowed_transitions' => array('regular_transition', 'unknown_transition'),
                            'unknown_first' => 'first_value',
                            'unknown_second' => 'second_value',
                        ),
                        array(
                            'name' => 'second_step',
                            'order' => 20,
                            '_is_start' => false,
                            'is_final' => true,
                        ),
                    ),
                    WorkflowConfiguration::NODE_TRANSITIONS => array(
                        array(
                            'name' => 'start_transition',
                            'is_start' => true,
                        ),<commit_msg>BAP-8293: Save position of workflow step<commit_after><?php

namespace Oro\Bundle\WorkflowBundle\Tests\Unit\Configuration\Handler;

use Oro\Bundle\WorkflowBundle\Configuration\Handler\StepHandler;
use Oro\Bundle\WorkflowBundle\Configuration\WorkflowConfiguration;

class StepHandlerTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var StepHandler
     */
    protected $handler;

    protected function setUp()
    {
        $this->handler = new StepHandler();
    }

    /**
     * @param array $expected
     * @param array $input
     * @dataProvider handleDataProvider
     */
    public function testHandle(array $expected, array $input)
    {
        $this->assertEquals($expected, $this->handler->handle($input));
    }

    /**
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     *
     * @return array
     */
    public function handleDataProvider()
    {
        return array(
            'simple configuration' => array(
                'expected' => array(
                    'start_step' => 'first_step',
                    WorkflowConfiguration::NODE_STEPS => array(
                        array(
                            'name' => 'first_step',
                            'label' => 'First Step',
                            'order' => 10,
                            'is_final' => true,
                            'allowed_transitions' => array(),
                        ),
                    ),
                    WorkflowConfiguration::NODE_TRANSITIONS => array(
                        array(
                            'name' => 'start_transition',
                            'is_start' => true,
                        ),
                    ),
                ),
                'input' => array(
                    'start_step' => 'first_step',
                    WorkflowConfiguration::NODE_STEPS => array(
                        array(
                            'name' => 'step:starting_point',
                            'order' => -1,
                            '_is_start' => true,
                            'is_final' => false,
                            'allowed_transitions' => array('start_transition'),
                        ),
                        array(
                            'name' => 'first_step',
                            'label' => 'First Step',
                            'order' => 10,
                            '_is_start' => false,
                            'is_final' => true,
                        ),
                    ),
                    WorkflowConfiguration::NODE_TRANSITIONS => array(
                        array(
                            'name' => 'start_transition'
                        ),
                    ),
                ),
            ),
            'full configuration' => array(
                'expected' => array(
                    'start_step' => null,
                    WorkflowConfiguration::NODE_STEPS => array(
                        array(
                            'name' => 'first_step',
                            'label' => 'First Step',
                            'order' => 10,
                            'is_final' => false,
                            'entity_acl' => array('attribute' => array('delete' => false)),
                            'allowed_transitions' => array('regular_transition'),
                            'position' => [1,100],
                        ),
                        array(
                            'name' => 'second_step',
                            'label' => 'second_step',
                            'order' => 20,
                            'is_final' => true,
                            'allowed_transitions' => array(),
                        ),
                    ),
                    WorkflowConfiguration::NODE_TRANSITIONS => array(
                        array(
                            'name' => 'start_transition',
                            'is_start' => true,
                        ),
                        array(
                            'name' => 'regular_transition',
                            'is_start' => false,
                        ),
                    ),
                ),
                'input' => array(
                    'start_step' => 'unknown_step',
                    WorkflowConfiguration::NODE_STEPS => array(
                        array(
                            'name' => 'step:starting_point',
                            'order' => -1,
                            '_is_start' => true,
                            'is_final' => false,
                            'allowed_transitions' => array('start_transition'),
                        ),
                        array(
                            'name' => 'first_step',
                            'label' => 'First Step',
                            'order' => 10,
                            '_is_start' => false,
                            'is_final' => false,
                            'entity_acl' => array('attribute' => array('delete' => false)),
                            'allowed_transitions' => array('regular_transition', 'unknown_transition'),
                            'unknown_first' => 'first_value',
                            'unknown_second' => 'second_value',
                            'position' => [1, 100]
                        ),
                        array(
                            'name' => 'second_step',
                            'order' => 20,
                            '_is_start' => false,
                            'is_final' => true,
                        ),
                    ),
                    WorkflowConfiguration::NODE_TRANSITIONS => array(
                        array(
                            'name' => 'start_transition',
                            'is_start' => true,
                        ),
{'fraction_non_alphanumeric': 0.10600736995458052, 'fraction_numerical': 0.0034278858514011482, 'mean_word_length': 0.8482736775419703, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 163, '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': '2408500', 'n_tokens_mistral': 2613, 'n_tokens_neox': 2478, 'n_words': 432}