<commit_before><?php

namespace Oro\Bundle\FormBundle\Tests\Behat\Element;

use Behat\Mink\Element\NodeElement;
use Oro\Bundle\TestFrameworkBundle\Behat\Element\Element;

class Select2Entity extends Element
{
    public function setValue($value)
    {
        $this->open();
        /** @var NodeElement[] $inputs */
        $inputs = array_filter(
            $this->getPage()->findAll('css', '.select2-search input'),
            function (NodeElement $element) {
                return $element->isVisible();
            }
        );

        self::assertCount(1, $inputs);
        array_shift($inputs)->setValue($value);

        $results = $this->getSuggestions();

        if (1 < count($results)) {
            foreach ($results as $result) {
                if ($result->getText() == $value) {
                    $result->click();

                    return;
                }
            }

            self::fail(sprintf('Too many results for "%s"', $value));
        }

        self::assertNotCount(0, $results, sprintf('Not found result for "%s"', $value));

        array_shift($results)->click();
        $this->getDriver()->waitForAjax();
    }

    /**
     * @return NodeElement[]<commit_msg>CRM-6236: Account name is not equal to Business Customer name scenario<commit_after><?php

namespace Oro\Bundle\FormBundle\Tests\Behat\Element;

use Behat\Mink\Element\NodeElement;
use Oro\Bundle\TestFrameworkBundle\Behat\Element\Element;

class Select2Entity extends Element
{
    public function setValue($value)
    {
        $this->open();
        /** @var NodeElement[] $inputs */
        $inputs = array_filter(
            $this->getPage()->findAll('css', '.select2-search input'),
            function (NodeElement $element) {
                return $element->isVisible();
            }
        );

        self::assertCount(1, $inputs);
        array_shift($inputs)->setValue($value);

        $results = $this->getSuggestions();

        if (1 < count($results)) {
            foreach ($results as $result) {
                if ($result->getText() == $value) {
                    $result->click();

                    return;
                }
            }

            self::fail(sprintf('Too many results for "%s"', $value));
        }

        self::assertNotCount(0, $results, sprintf('Not found result for "%s"', $value));

        array_shift($results)->click();
        $this->getDriver()->waitForAjax();
    }

    /**
     * {@inheritdoc}
     */
    public function selectOption($option, $multiple = false)
    {
        $this->setValue($option);
    }

    /**
     * @return NodeElement[]
{'fraction_non_alphanumeric': 0.15320121951219512, 'fraction_numerical': 0.005335365853658537, 'mean_word_length': 2.048780487804878, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 26, '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': '3632479', 'n_tokens_mistral': 739, 'n_tokens_neox': 716, 'n_words': 142}