<commit_before><?php
/**
 * Copyright 2016 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 HostTemplateListPage
{
    private $context;

    /**
     *  Host template list page.
     *
     *  @param $context  Centreon context class.
     *  @param $visit    True to navigate to page.
     */
    public function __construct($context, $visit = TRUE)
    {
        $this->context = $context;
        if ($visit) {
            $this->context->visit('main.php?p=60103');
        }
    }

    /**
     *  Edit a template.
     *
     *  @param $name  Host template name.
     */
    public function editTemplate($name)
    {
        $this->assertFindLink($name)->click();
        return new HostTemplateEditPage($this->context, FALSE);
    }

    /**
     *  Get template properties.
     *
     *  @param $name  Host template name.
     */
    public function getTemplate($name)
    {
        $templates = $this->getTemplates();
        $tmpl = array_search($name, $templates);
        if ($tmpl == FALSE) {
            throw new \Exception('Cannot find host template "' . $name . '".');
        }
        return $tmpl;
    }

    /**
     *  Get the list of templates.
     */
    public function getTemplates()
    {
        $entries = array();
        $elements = $this->context->getSession()->getPage()->findAll('css', '.list_one,.list_two');
        foreach ($elements as $element) {
            $entry = array();
            $entry['name'] = $this->context->assertFindIn($element, 'css', '.ListColLeft')->getText();
            $entry['description'] = $this->context->assertFindIn($element, 'css', '.ListColLeft.resizeTitle')->getText();
            $entry['linked_services'] = $this->context->assertFindIn($element, 'css', '.ListColCenter')->getText();
            $entry['parents'] = $this->context->assertFindIn($element, 'css', '.ListColCenter.resizeTitle')->getText();
            $entry['locked'] = (null === $element->find('css', 'input'));
            $entries[$entry['name']] = $entry;
        }
        return $entries;
    }
}

?>
<commit_msg>Fix getTemplate() method of HostTemplateListPage class.<commit_after><?php
/**
 * Copyright 2016 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 HostTemplateListPage
{
    private $context;

    /**
     *  Host template list page.
     *
     *  @param $context  Centreon context class.
     *  @param $visit    True to navigate to page.
     */
    public function __construct($context, $visit = TRUE)
    {
        $this->context = $context;
        if ($visit) {
            $this->context->visit('main.php?p=60103');
        }
    }

    /**
     *  Edit a template.
     *
     *  @param $name  Host template name.
     */
    public function editTemplate($name)
    {
        $this->assertFindLink($name)->click();
        return new HostTemplateEditPage($this->context, FALSE);
    }

    /**
     *  Get template properties.
     *
     *  @param $name  Host template name.
     */
    public function getTemplate($name)
    {
        $templates = $this->getTemplates();
        if (!array_key_exists($name, $templates)) {
            throw new \Exception('Cannot find host template "' . $name . '".');
        }
        return $templates[$name];
    }

    /**
     *  Get the list of templates.
     */
    public function getTemplates()
    {
        $entries = array();
        $elements = $this->context->getSession()->getPage()->findAll('css', '.list_one,.list_two');
        foreach ($elements as $element) {
            $entry = array();
            $entry['name'] = $this->context->assertFindIn($element, 'css', '.ListColLeft')->getText();
            $entry['description'] = $this->context->assertFindIn($element, 'css', '.ListColLeft.resizeTitle')->getText();
            $entry['linked_services'] = $this->context->assertFindIn($element, 'css', '.ListColCenter')->getText();
            $entry['parents'] = $this->context->assertFindIn($element, 'css', '.ListColCenter.resizeTitle')->getText();
            $entry['locked'] = (null === $element->find('css', 'input'));
            $entries[$entry['name']] = $entry;
        }
        return $entries;
    }
}

?>

{'fraction_non_alphanumeric': 0.14818337454822142, 'fraction_numerical': 0.0049457865702872365, 'mean_word_length': 2.5383580080753703, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, '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': '3204129', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1448, 'n_words': 404}