<commit_before><?php
/**
 * Copyright 2016-2017 Centreon
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace Centreon\Test\Behat;

class CustomViewsPage implements Page
{
    protected $context;

    /**
     *  Navigate to and/or check that we are on the custom views page.
     */
    public function __construct($context, $visit = true)
    {
        // Visit page.
        $this->context = $context;
        if ($visit) {
            $this->context->visit('main.php?p=103');
        }

        // Check that page is valid for this class.
        $mythis = $this;
        $this->context->spin(
            function ($context) use ($mythis) {
                return $mythis->isPageValid();
            },
            'Current page does not match class ' . __CLASS__
        );
    }

    /**
     *  Check that the current page is matching this class.
     *
     * @return True if the current page matches this class.
     */
    public function isPageValid()
    {
        return $this->context->getSession()->getPage()->has('css', '#globalView');
    }

    /**
     *  Show edit bar that is not currently visible or hide edit bar
     *  that is currently visible.
     */
    public function showEditBar($show = true)
    {
        $this->toggleEditBar();
        $this->context->spin(
            function ($context) use ($show) {
                $barVisible = $context->assertFind('css', 'button.addView')->isVisible();
                return $show == $barVisible;
            },
            'Toggle of edit bar did not ' . ($show ? 'show' : 'hide') . ' edit bar.'
        );
    }

    /**
     *  Show edit button status.
     */
    public function isCurrentViewEditable()
    {
        $ariadisabled = $this->context->assertFind(
            'css',
            'button.editView'
        )->getAttribute('aria-disabled');
        return is_null($ariadisabled) || ($ariadisabled == 'false');
    }

    /**
     *  Create a new view.
     *
     * @param $name
     * @param $columns  Column number.
     * @param $public   True for a public view, false otherwise.
     */
    public function createNewView($name, $columns = 1, $public = false)
    {
        // Find number of existing tabs.
        $tabs = count($this->context->getSession()->getPage()->findAll('css', '#tabs .tabs_header li'));

        $this->context->assertFind('css', 'button.addView')->click();
        $this->context->assertFind('css', '#formAddView input[name="name"]')->setValue($name);
        $this->context->assertFind('css',
            '#formAddView input[name="layout[layout]"][value="column_' . $columns . '"]')->click();
        if ($public) {
            $this->context->assertFind('css', '#formAddView input[name="public"]')->check();
        } else {
            $this->context->assertFind('css', '#formAddView input[name="public"]')->uncheck();
        }
        $this->context->assertFind('css', '#formAddView input[name="submit"]')->click();

        // Wait for new tab to appear.
        $tabs += 1;
        $this->context->spin(
            function ($context) use ($tabs) {
                return count($this->context->getSession()->getPage()->findAll(
                        'css',
                        '#tabs .tabs_header li'))
                    >= $tabs;
            }
        );
    }

    /**
     *  Load a view.
     *
     * @param $publicView
     * @param $shareView  Column number.
     */
    public function loadView($publicView = null, $sharedView = null)
    {
        $this->context->spin(
            function ($context) {
                return $this->context->assertFind('css', 'button.addView');
            },
            'no button addView'
        );
        // Open popin.
        $this->context->assertFind('css', 'button.addView')->click();

        $this->context->spin(
            function ($context) {
                return $this->context->assertFind(
                    'css',
                    '#formAddView input[name="create_load[create_load]"][value="load"]'
                );
            }
        );
        $this->context->assertFind('css', '#formAddView input[name="create_load[create_load]"][value="load"]')->click();

        // Set requested view.
        if (!empty($publicView)) {
            return $this->context->selectToSelectTwo('#formAddView select#viewLoad', $publicView);
        }

        if (!empty($sharedView)) {
            return $this->context->selectToSelectTwo('#formAddView select#viewLoadShare', $sharedView);
        }<commit_msg>fix load view<commit_after><?php
/**
 * Copyright 2016-2017 Centreon
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace Centreon\Test\Behat;

class CustomViewsPage implements Page
{
    protected $context;

    /**
     *  Navigate to and/or check that we are on the custom views page.
     */
    public function __construct($context, $visit = true)
    {
        // Visit page.
        $this->context = $context;
        if ($visit) {
            $this->context->visit('main.php?p=103');
        }

        // Check that page is valid for this class.
        $mythis = $this;
        $this->context->spin(
            function ($context) use ($mythis) {
                return $mythis->isPageValid();
            },
            'Current page does not match class ' . __CLASS__
        );
    }

    /**
     *  Check that the current page is matching this class.
     *
     * @return True if the current page matches this class.
     */
    public function isPageValid()
    {
        return $this->context->getSession()->getPage()->has('css', '#globalView');
    }

    /**
     *  Show edit bar that is not currently visible or hide edit bar
     *  that is currently visible.
     */
    public function showEditBar($show = true)
    {
        $this->toggleEditBar();
        $this->context->spin(
            function ($context) use ($show) {
                $barVisible = $context->assertFind('css', 'button.addView')->isVisible();
                return $show == $barVisible;
            },
            'Toggle of edit bar did not ' . ($show ? 'show' : 'hide') . ' edit bar.'
        );
    }

    /**
     *  Show edit button status.
     */
    public function isCurrentViewEditable()
    {
        $ariadisabled = $this->context->assertFind(
            'css',
            'button.editView'
        )->getAttribute('aria-disabled');
        return is_null($ariadisabled) || ($ariadisabled == 'false');
    }

    /**
     *  Create a new view.
     *
     * @param $name
     * @param $columns  Column number.
     * @param $public   True for a public view, false otherwise.
     */
    public function createNewView($name, $columns = 1, $public = false)
    {
        // Find number of existing tabs.
        $tabs = count($this->context->getSession()->getPage()->findAll('css', '#tabs .tabs_header li'));

        $this->context->assertFind('css', 'button.addView')->click();
        $this->context->assertFind('css', '#formAddView input[name="name"]')->setValue($name);
        $this->context->assertFind('css',
            '#formAddView input[name="layout[layout]"][value="column_' . $columns . '"]')->click();
        if ($public) {
            $this->context->assertFind('css', '#formAddView input[name="public"]')->check();
        } else {
            $this->context->assertFind('css', '#formAddView input[name="public"]')->uncheck();
        }
        $this->context->assertFind('css', '#formAddView input[name="submit"]')->click();

        // Wait for new tab to appear.
        $tabs += 1;
        $this->context->spin(
            function ($context) use ($tabs) {
                return count($this->context->getSession()->getPage()->findAll(
                        'css',
                        '#tabs .tabs_header li'))
                    >= $tabs;
            }
        );
    }

    /**
     *  Load a view.
     *
     * @param $publicView
     * @param $shareView  Column number.
     */
    public function loadView($publicView = null, $sharedView = null)
    {
        $this->context->spin(
            function ($context) {
                return $this->context->assertFind('css', 'button.addView')->isVisible();
            },
            'no button addView'
        );
        // Open popin.
        $this->context->assertFind('css', 'button.addView')->click();

        $this->context->spin(
            function ($context) {
                return $this->context->assertFind(
                    'css',
                    '#formAddView input[name="create_load[create_load]"][value="load"]'
                );
            }
        );
        $this->context->assertFind('css', '#formAddView input[name="create_load[create_load]"][value="load"]')->click();

        // Set requested view.
        if (!empty($publicView)) {
            $this->context->selectToSelectTwo('#formAddView select#viewLoad', $publicView);
        }

        if (!empty($sharedView)) {
            $this->context->selectToSelectTwo('#formAddView select#viewLoadShare', $sharedView);
        }
{'fraction_non_alphanumeric': 0.14858279462953755, 'fraction_numerical': 0.0033814022874191943, 'mean_word_length': 2.0658536585365854, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 134, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '494327', 'n_tokens_mistral': 2776, 'n_tokens_neox': 2704, 'n_words': 706}