<commit_before><?php

/*
 * This file is part of the Behat\Mink.
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

use Behat\Mink\Exception\ElementNotFoundException;

$steps->Given('/^(?:|I )am on (?P<page>.+)$/', function($world, $page) {
    $world->getSession()->visit($world->getPathTo($page));
});

$steps->When('/^(?:|I )go to (?P<page>.+)$/', function($world, $page) {
    $world->getSession()->visit($world->getPathTo($page));
});

$steps->When('/^(?:|I )press "(?P<button>[^"]*)"$/', function($world, $button) {
    $world->getSession()->getPage()->clickButton($button);
});

$steps->When('/^(?:|I )follow "(?P<link>[^"]*)"$/', function($world, $link) {
    $world->getSession()->getPage()->clickLink($link);
});

$steps->When('/^(?:|I )fill in "(?P<field>[^"]*)" with "(?P<value>[^"]*)"$/', function($world, $field, $value) {
    $world->getSession()->getPage()->fillField($field, $value);
});

$steps->When('/^(?:|I )fill in "(?P<value>[^"]*)" for "(?P<field>[^"]*)"$/', function($world, $field, $value) {
    $world->getSession()->getPage()->fillField($field, $value);
});

$steps->When('/^(?:|I )fill in the following:$/', function($world, $fieldsTable) {
    $page = $world->getSession()->getPage();
    foreach ($fieldsTable->getRowsHash() as $field => $value) {
        $page->fillField($field, $value);
    }
});

$steps->When('/^(?:|I )select "(?P<option>[^"]*)" from "(?P<select>[^"]*)"$/', function($world, $select, $option) {
    $world->getSession()->getPage()->selectFieldOption($select, $option);
});

$steps->When('/^(?:|I )check "(?P<option>[^"]*)"$/', function($world, $option) {
    $world->getSession()->getPage()->checkField($option);
});

$steps->When('/^(?:|I )uncheck "(?P<option>[^"]*)"$/', function($world, $option) {
    $world->getSession()->getPage()->uncheckField($option);
});

$steps->When('/^(?:|I )attach the file "(?P<path>[^"]*)" to "(?P<field>[^"]*)"$/', function($world, $field, $path) {
    $world->getSession()->getPage()->attachFileToField($field, $path);
});

$steps->Then('/^(?:|I )should see "(?P<text>[^"]*+)"$/', function($world, $text) {
    assertRegExp('/'.preg_quote($text, '/').'/', $world->getSession()->getPage()->getContent());
});

$steps->Then('/^(?:|I )should not see "(?P<text>[^"]*+)"$/', function($world, $text) {
    assertNotRegExp('/'.preg_quote($text, '/').'/', $world->getSession()->getPage()->getContent());
});

$steps->Then('/^the "(?P<field>[^"]*)" field should contain "(?P<value>[^"]*)"$/', function($world, $field, $value) {
    $node = $world->getSession()->getPage()->findField($field);

    if (null === $node) {
        throw new ElementNotFoundException('field', $field);
    }

    assertContains($value, $node->getValue());
});

$steps->Then('/^the "(?P<field>[^"]*)" field should not contain "(?P<value>[^"]*)"$/', function($world, $field, $value) {
    $node = $world->getSession()->getPage()->findField($field);

    if (null === $field) {
        throw new ElementNotFoundException('field', $field);
    }

    assertNotContains($value, $node->getValue());
});

$steps->Then('/^the "(?P<checkbox>[^"]*)" checkbox should be checked$/', function($world, $checkbox) {
    $field = $world->getSession()->getPage()->findField($checkbox);

    if (null === $field) {
        throw new ElementNotFoundException('field', $checkbox);
    }

    assertTrue($field->isChecked());
});

$steps->Then('/^the "(?P<checkbox>[^"]*)" checkbox should not be checked$/', function($world, $checkbox) {
    $field = $world->getSession()->getPage()->findField($checkbox);

    if (null === $field) {
        throw new ElementNotFoundException('field', $checkbox);
    }

    assertFalse($field->isChecked());
});

$steps->Then('/^(?:|I )should be on (?P<page>.+)$/', function($world, $page) {
    assertEquals(
        parse_url($world->getPathTo($page), PHP_URL_PATH),
        parse_url($world->getSession()->getCurrentUrl(), PHP_URL_PATH)
    );
});

$steps->Then('/^the url should match (?P<pattern>.+)$/', function($world, $pattern) {
    if (preg_match('/^\/.*\/$', $pattern)) {
        assertRegExp($pattern, parse_url($world->getSession()->getCurrentUrl(), PHP_URL_PATH));
    } else {
        assertRegExp(
            '/'.preg_quote($pattern, '/').'/',
            parse_url($world->getSession()->getCurrentUrl(), PHP_URL_PATH)
        );
    }
});

$steps->Then('/^the "(?P<element>[^"]*)" element should contain "(?P<value>[^"]*)"$/', function($world, $element, $value) {
    $node = $world->getSession()->getPage()->find('xpath', $element);

    if (null === $node) {
        throw new ElementNotFoundException('element', $element);
    }

    assertContains($value, preg_replace('/\s+/', ' ', str_replace("\n", '', $node->getText())));
});

$steps->Then('/^(?:|I )should see "(?P<element>[^"]*)" element$/', function($world, $element) {
    $node = $world->getSession()->getPage()->find('xpath', $element);

    if (null === $node) {
        throw new ElementNotFoundException('element', $element);
    }

    assertNotNull($node);
});

$steps->Then('/^(?:|I )should not see "(?P<element>[^"]*)" element$/', function($world, $element) {
    assertNull($world->getSession()->getPage()->find('xpath', $element));
});

$steps->Then('/^the "(?P<element>[^"]*)" element should link to (?P<href>.*)$/', function($world, $element, $href) {<commit_msg>fixed url-should-match step behavior to match only full string<commit_after><?php

/*
 * This file is part of the Behat\Mink.
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

use Behat\Mink\Exception\ElementNotFoundException;

$steps->Given('/^(?:|I )am on (?P<page>.+)$/', function($world, $page) {
    $world->getSession()->visit($world->getPathTo($page));
});

$steps->When('/^(?:|I )go to (?P<page>.+)$/', function($world, $page) {
    $world->getSession()->visit($world->getPathTo($page));
});

$steps->When('/^(?:|I )press "(?P<button>[^"]*)"$/', function($world, $button) {
    $world->getSession()->getPage()->clickButton($button);
});

$steps->When('/^(?:|I )follow "(?P<link>[^"]*)"$/', function($world, $link) {
    $world->getSession()->getPage()->clickLink($link);
});

$steps->When('/^(?:|I )fill in "(?P<field>[^"]*)" with "(?P<value>[^"]*)"$/', function($world, $field, $value) {
    $world->getSession()->getPage()->fillField($field, $value);
});

$steps->When('/^(?:|I )fill in "(?P<value>[^"]*)" for "(?P<field>[^"]*)"$/', function($world, $field, $value) {
    $world->getSession()->getPage()->fillField($field, $value);
});

$steps->When('/^(?:|I )fill in the following:$/', function($world, $fieldsTable) {
    $page = $world->getSession()->getPage();
    foreach ($fieldsTable->getRowsHash() as $field => $value) {
        $page->fillField($field, $value);
    }
});

$steps->When('/^(?:|I )select "(?P<option>[^"]*)" from "(?P<select>[^"]*)"$/', function($world, $select, $option) {
    $world->getSession()->getPage()->selectFieldOption($select, $option);
});

$steps->When('/^(?:|I )check "(?P<option>[^"]*)"$/', function($world, $option) {
    $world->getSession()->getPage()->checkField($option);
});

$steps->When('/^(?:|I )uncheck "(?P<option>[^"]*)"$/', function($world, $option) {
    $world->getSession()->getPage()->uncheckField($option);
});

$steps->When('/^(?:|I )attach the file "(?P<path>[^"]*)" to "(?P<field>[^"]*)"$/', function($world, $field, $path) {
    $world->getSession()->getPage()->attachFileToField($field, $path);
});

$steps->Then('/^(?:|I )should see "(?P<text>[^"]*+)"$/', function($world, $text) {
    assertRegExp('/'.preg_quote($text, '/').'/', $world->getSession()->getPage()->getContent());
});

$steps->Then('/^(?:|I )should not see "(?P<text>[^"]*+)"$/', function($world, $text) {
    assertNotRegExp('/'.preg_quote($text, '/').'/', $world->getSession()->getPage()->getContent());
});

$steps->Then('/^the "(?P<field>[^"]*)" field should contain "(?P<value>[^"]*)"$/', function($world, $field, $value) {
    $node = $world->getSession()->getPage()->findField($field);

    if (null === $node) {
        throw new ElementNotFoundException('field', $field);
    }

    assertContains($value, $node->getValue());
});

$steps->Then('/^the "(?P<field>[^"]*)" field should not contain "(?P<value>[^"]*)"$/', function($world, $field, $value) {
    $node = $world->getSession()->getPage()->findField($field);

    if (null === $field) {
        throw new ElementNotFoundException('field', $field);
    }

    assertNotContains($value, $node->getValue());
});

$steps->Then('/^the "(?P<checkbox>[^"]*)" checkbox should be checked$/', function($world, $checkbox) {
    $field = $world->getSession()->getPage()->findField($checkbox);

    if (null === $field) {
        throw new ElementNotFoundException('field', $checkbox);
    }

    assertTrue($field->isChecked());
});

$steps->Then('/^the "(?P<checkbox>[^"]*)" checkbox should not be checked$/', function($world, $checkbox) {
    $field = $world->getSession()->getPage()->findField($checkbox);

    if (null === $field) {
        throw new ElementNotFoundException('field', $checkbox);
    }

    assertFalse($field->isChecked());
});

$steps->Then('/^(?:|I )should be on (?P<page>.+)$/', function($world, $page) {
    assertEquals(
        parse_url($world->getPathTo($page), PHP_URL_PATH),
        parse_url($world->getSession()->getCurrentUrl(), PHP_URL_PATH)
    );
});

$steps->Then('/^the url should match (?P<pattern>.+)$/', function($world, $pattern) use ($steps) {
    if (preg_match('/^\/.*\/$', $pattern)) {
        assertRegExp($pattern, parse_url($world->getSession()->getCurrentUrl(), PHP_URL_PATH));
    } else {
        $steps->Then("I should be on $pattern");
    }
});

$steps->Then('/^the "(?P<element>[^"]*)" element should contain "(?P<value>[^"]*)"$/', function($world, $element, $value) {
    $node = $world->getSession()->getPage()->find('xpath', $element);

    if (null === $node) {
        throw new ElementNotFoundException('element', $element);
    }

    assertContains($value, preg_replace('/\s+/', ' ', str_replace("\n", '', $node->getText())));
});

$steps->Then('/^(?:|I )should see "(?P<element>[^"]*)" element$/', function($world, $element) {
    $node = $world->getSession()->getPage()->find('xpath', $element);

    if (null === $node) {
        throw new ElementNotFoundException('element', $element);
    }

    assertNotNull($node);
});

$steps->Then('/^(?:|I )should not see "(?P<element>[^"]*)" element$/', function($world, $element) {
    assertNull($world->getSession()->getPage()->find('xpath', $element));
});

$steps->Then('/^the "(?P<element>[^"]*)" element should link to (?P<href>.*)$/', function($world, $element, $href) {
{'fraction_non_alphanumeric': 0.2869942730463699, 'fraction_numerical': 0.0, 'mean_word_length': 4.903489640130862, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 262, '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': '970820', 'n_tokens_mistral': 3724, 'n_tokens_neox': 3605, 'n_words': 643}