<commit_before><?php

namespace Acme\Bundle\TestsBundle\Tests\Selenium;

use Acme\Bundle\TestsBundle\Pages\BAP\Login;
use Acme\Bundle\TestsBundle\Pages\BAP\Users;

class AdvancedSearchTest extends \PHPUnit_Extensions_Selenium2TestCase
{
    const TIME_OUT  = 1000;
    const MAX_AJAX_EXECUTION_TIME = 5000;

    protected function setUp()
    {
        $this->setHost(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_HOST);
        $this->setPort(intval(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PORT));
        $this->setBrowser(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM2_BROWSER);
        $this->setBrowserUrl(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_TESTS_URL);
    }

    protected function tearDown()
    {
        $this->cookie()->clear();
    }

    protected function waitForAjax()
    {
        $this->waitUntil(
            function ($testCase) {
                $status = $testCase->execute(array('script' => 'return jQuery.active == 0', 'args' => array()));
                if ($status) {
                    return true;
                } else {
                    return null;
                }
            },
            self::MAX_AJAX_EXECUTION_TIME
        );

        $this->timeouts()->implicitWait(self::TIME_OUT);
    }

    /**
     * Verify element present
     *
     * @param string $locator
     * @return bool
     */
    public function isElementPresent($locator)
    {
        try {
            $this->byXPath($locator);
            return true;
        } catch (\PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) {
            return false;
        }
    }

    /**
     * Tests that checks advanced search
     *
     * @dataProvider columnTitle
     */
    public function testAdvancedSearch($query, $userField)
    {
        $login = new Login($this);
        $login->setUsername(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_LOGIN)
            ->setPassword(<PASSWORD>TESTSUITE_EXTENSION_SELENIUM_PASS)
            ->submit()
            ->openUsers();
        $users = new Users($this);
        $userData = $users->getRandomEntity();
        //Open advanced search page
        $this->byXPath("//ul[@class='nav nav-tabs']//a[contains(., 'Search')]")->click();
        $this->waitForAjax();
        $this->byXPath("//*[@id='demo_search_tab']//a[contains(., 'Advanced search')]")->click();
        $this->waitForAjax();
        //Fill advanced search input field
        $this->byId('query')->value($query . $userData{$userField});
        $this->byId('sendButton')->click();
        $this->waitForAjax();
        //Chect that result is not null
        $this->assertFalse(
            $this->isElementPresent(
                "//div[@class='container-fluid']//div[@class='search_stats alert alert-info']/h2[contains(., '$query . $userData{$userField}')]"
            ),
            'Search results does not found'
        );
    }

    /**
     * Data provider for advanced search
     *
     * @return array
     */
    public function columnTitle()
    {
        return array(
            'firstName' => array('where firstName ~ ','FIRST NAME'),
//            'salary' => array('where salary = ', 'SALARY'),
        );
    }
}<commit_msg>BAP-570 Refactor Selenium Tests to use PageObject  - CR changes<commit_after><?php

namespace Acme\Bundle\TestsBundle\Tests\Selenium;

use Acme\Bundle\TestsBundle\Pages\BAP\Login;
use Acme\Bundle\TestsBundle\Pages\BAP\Users;

class AdvancedSearchTest extends \PHPUnit_Extensions_Selenium2TestCase
{
    protected function setUp()
    {
        $this->setHost(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_HOST);
        $this->setPort(intval(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PORT));
        $this->setBrowser(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM2_BROWSER);
        $this->setBrowserUrl(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_TESTS_URL);
    }

    protected function tearDown()
    {
        $this->cookie()->clear();
    }

    protected function waitForAjax()
    {
        $this->waitUntil(
            function ($testCase) {
                $status = $testCase->execute(array('script' => 'return jQuery.active == 0', 'args' => array()));
                if ($status) {
                    return true;
                } else {
                    return null;
                }
            },
            intval('MAX_AJAX_EXECUTION_TIME')
        );

        $this->timeouts()->implicitWait(intval('TIME_OUT'));
    }

    /**
     * Verify element present
     *
     * @param string $locator
     * @return bool
     */
    public function isElementPresent($locator)
    {
        try {
            $this->byXPath($locator);
            return true;
        } catch (\PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) {
            return false;
        }
    }

    /**
     * Tests that checks advanced search
     *
     * @dataProvider columnTitle
     */
    public function testAdvancedSearch($query, $userField)
    {
        $login = new Login($this);
        $login->setUsername(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_LOGIN)
            ->setPassword(<PASSWORD>SUITE_EXTENSION_SELEN<PASSWORD>)
            ->submit()
            ->openUsers();
        $users = new Users($this);
        $userData = $users->getRandomEntity();
        //Open advanced search page
        $this->byXPath("//ul[@class='nav nav-tabs']//a[contains(., 'Search')]")->click();
        $this->waitForAjax();
        $this->byXPath("//*[@id='demo_search_tab']//a[contains(., 'Advanced search')]")->click();
        $this->waitForAjax();
        //Fill advanced search input field
        $this->byId('query')->value($query . $userData{$userField});
        $this->byId('sendButton')->click();
        $this->waitForAjax();
        //Check that result is not null
        $this->assertFalse(
            $this->isElementPresent(
                "//div[@class='container-fluid']//div[@class='search_stats alert alert-info']/h2[contains(., '$query . $userData{$userField}')]"
            ),
            'Search results does not found'
        );
    }

    /**
     * Data provider for advanced search
     *
     * @return array
     */
    public function columnTitle()
    {
        return array(
            'firstName' => array('where firstName ~ ','FIRST NAME'),
        );
    }
}
{'fraction_non_alphanumeric': 0.13867909368471798, 'fraction_numerical': 0.003374578177727784, 'mean_word_length': 2.2148760330578514, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 71, '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': '3439898', 'n_tokens_mistral': 1901, 'n_tokens_neox': 1841, 'n_words': 304}