<commit_before><?php
/**
 * @author <NAME>, <<EMAIL>>
 */
namespace Drupal\TqExtension\Context;

// Contexts.
use Behat\Behat\Context\SnippetAcceptingContext;
use Drupal\DrupalExtension\Context as DrupalContexts;

// Exceptions.
use Behat\Behat\Context\Exception\ContextNotFoundException;

// Helpers.
use WebDriver\Session;
use Drupal\Driver\DrushDriver;
use Behat\Mink\Element\NodeElement;
use Behat\Mink\Driver\Selenium2Driver;
use Behat\Behat\Hook\Scope\StepScope;
use Behat\Behat\Context\Environment\InitializedContextEnvironment;
use Drupal\TqExtension\Utils as TqUtils;

/**
 * @see RawTqContext::__call()
 *
 * @method User\UserContext getUserContext()
 * @method Form\FormContext getFormContext()
 * @method Email\EmailContext getEmailContext()
 * @method Drush\DrushContext getDrushContext()
 * @method Wysiwyg\WysiwygContext getWysiwygContext()
 * @method Redirect\RedirectContext getRedirectContext()
 * @method TqContext getTqContext()
 * @method DrupalContexts\MinkContext getMinkContext()
 * @method DrupalContexts\DrupalContext getDrupalContext()
 * @method DrupalContexts\MessageContext getMessageContext()
 * @method \Drupal\Component\Utility\Random getRandom()
 */
class RawTqContext extends RawPageContext implements TqContextInterface
{
    use TqUtils\Interaction;

    /**
     * Parameters of TqExtension.
     *
     * @var array
     */
    private $parameters = [];
    /**
     * @var string
     */
    protected static $pageUrl = '';

    /**
     * @param string $method
     * @param array $arguments
     *
     * @throws \Exception
     * @throws ContextNotFoundException
     *   When context class cannot be loaded.
     *
     * @return SnippetAcceptingContext
     */
    public function __call($method, array $arguments)
    {
        $environment = $this->getEnvironment();
        // @example
        // The "getFormContext" method is not declared and his name will be split by capital
        // letters, creating an array with three items: "get", "Form" and "Context".
        list(, $base, $context) = preg_split('/(?=[A-Z])/', $method);

        foreach ([
            [$this->getTqParameter('context_namespace'), $base],
            ['Drupal', 'DrupalExtension', 'Context'],
        ] as $class) {
            $class[] = "$base$context";
            $class = implode('\\', $class);

            if ($environment->hasContextClass($class)) {
                return $environment->getContext($class);
            }
        }

        throw new \Exception(sprintf('Method %s does not exist', $method));
    }

    /**
     * @param array $variables
     *   An associative array where key is a variable name and a value - value.
     */
    public static function setDrupalVariables(array $variables)
    {
        foreach ($variables as $name => $value) {
            variable_set($name, $value);
        }
    }

    /**
     * Get selector by name.
     *
     * @param string $name
     *   Selector name from the configuration file.
     *
     * @return string
     *   CSS selector.
     *
     * @throws \Exception
     *   If selector does not exits.
     */
    public function getDrupalSelector($name)
    {
        $selectors = $this->getDrupalParameter('selectors');

        if (!isset($selectors[$name])) {
            throw new \Exception(sprintf('No such selector configured: %s', $name));
        }

        return $selectors[$name];
    }


    /**
     * @param string $site
     *   Drupal site folder.
     *
     * @return string
     *   URL to files directory.
     */
    public function getFilesUrl($site = 'default')
    {
        return $this->locatePath("sites/$site/files");
    }

    /**
     * @param string $text
     *   JS code for processing.
     *
     * @return self
     */
    protected function processJavaScript(&$text)
    {
        $text = str_replace(['$'], ['jQuery'], $text);

        return $this;
    }

    /**
     * @return InitializedContextEnvironment
     */
    public function getEnvironment()<commit_msg>IMPROVEMENT: wrap the getDrupalText() method in t() to ensure that we will get translated textual selectors<commit_after><?php
/**
 * @author <NAME>, <<EMAIL>>
 */
namespace Drupal\TqExtension\Context;

// Contexts.
use Behat\Behat\Context\SnippetAcceptingContext;
use Drupal\DrupalExtension\Context as DrupalContexts;

// Exceptions.
use Behat\Behat\Context\Exception\ContextNotFoundException;

// Helpers.
use WebDriver\Session;
use Drupal\Driver\DrushDriver;
use Behat\Mink\Element\NodeElement;
use Behat\Mink\Driver\Selenium2Driver;
use Behat\Behat\Hook\Scope\StepScope;
use Behat\Behat\Context\Environment\InitializedContextEnvironment;
use Drupal\TqExtension\Utils as TqUtils;

/**
 * @see RawTqContext::__call()
 *
 * @method User\UserContext getUserContext()
 * @method Form\FormContext getFormContext()
 * @method Email\EmailContext getEmailContext()
 * @method Drush\DrushContext getDrushContext()
 * @method Wysiwyg\WysiwygContext getWysiwygContext()
 * @method Redirect\RedirectContext getRedirectContext()
 * @method TqContext getTqContext()
 * @method DrupalContexts\MinkContext getMinkContext()
 * @method DrupalContexts\DrupalContext getDrupalContext()
 * @method DrupalContexts\MessageContext getMessageContext()
 * @method \Drupal\Component\Utility\Random getRandom()
 */
class RawTqContext extends RawPageContext implements TqContextInterface
{
    use TqUtils\Interaction;

    /**
     * Parameters of TqExtension.
     *
     * @var array
     */
    private $parameters = [];
    /**
     * @var string
     */
    protected static $pageUrl = '';

    /**
     * @param string $method
     * @param array $arguments
     *
     * @throws \Exception
     * @throws ContextNotFoundException
     *   When context class cannot be loaded.
     *
     * @return SnippetAcceptingContext
     */
    public function __call($method, array $arguments)
    {
        $environment = $this->getEnvironment();
        // @example
        // The "getFormContext" method is not declared and his name will be split by capital
        // letters, creating an array with three items: "get", "Form" and "Context".
        list(, $base, $context) = preg_split('/(?=[A-Z])/', $method);

        foreach ([
            [$this->getTqParameter('context_namespace'), $base],
            ['Drupal', 'DrupalExtension', 'Context'],
        ] as $class) {
            $class[] = "$base$context";
            $class = implode('\\', $class);

            if ($environment->hasContextClass($class)) {
                return $environment->getContext($class);
            }
        }

        throw new \Exception(sprintf('Method %s does not exist', $method));
    }

    /**
     * @param array $variables
     *   An associative array where key is a variable name and a value - value.
     */
    public static function setDrupalVariables(array $variables)
    {
        foreach ($variables as $name => $value) {
            variable_set($name, $value);
        }
    }

    /**
     * Get selector by name.
     *
     * @param string $name
     *   Selector name from the configuration file.
     *
     * @return string
     *   CSS selector.
     *
     * @throws \Exception
     *   If selector does not exits.
     */
    public function getDrupalSelector($name)
    {
        $selectors = $this->getDrupalParameter('selectors');

        if (!isset($selectors[$name])) {
            throw new \Exception(sprintf('No such selector configured: %s', $name));
        }

        return $selectors[$name];
    }

    /**
     * {@inheritdoc}
     */
    public function getDrupalText($name)
    {
        // Make text selectors translatable.
        return t(parent::getDrupalText($name));
    }

    /**
     * @param string $site
     *   Drupal site folder.
     *
     * @return string
     *   URL to files directory.
     */
    public function getFilesUrl($site = 'default')
    {
        return $this->locatePath("sites/$site/files");
    }

    /**
     * @param string $text
     *   JS code for processing.
     *
     * @return self
     */
    protected function processJavaScript(&$text)
    {
        $text = str_replace(['$'], ['jQuery'], $text);

        return $this;
    }

    /**
     * @return InitializedContextEnvironment
     */
    public function getEnvironment()
{'fraction_non_alphanumeric': 0.12522620340209917, 'fraction_numerical': 0.00024128362890577873, 'mean_word_length': 2.5809935205183585, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, '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': '4484946', 'n_tokens_mistral': 2381, 'n_tokens_neox': 2367, 'n_words': 584}