<commit_before><?php

/**
 * Copyright (C) 2016-2020 <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * @author <NAME> <https://benjamin.heisig.name/>
 * @copyright Copyright (C) 2016-2020 <NAME>
 * @license http://www.gnu.org/licenses/agpl-3.0 GNU Affero General Public License (AGPL)
 * @link https://github.com/bheisig/i-doit-api-client-php
 */

declare(strict_types=1);

namespace bheisig\idoitapi\Issues;

use \Exception;
use bheisig\idoitapi\BaseTest;
use bheisig\idoitapi\CMDBCategory;
use bheisig\idoitapi\Constants\Category;
use bheisig\idoitapi\Constants\ObjectType;

/**
 * @group issues
 * @group API-150
 * @see https://i-doit.atlassian.net/browse/API-150
 */
class API150Test extends BaseTest {

    /**
     * @throws Exception on error
     */
    public function testQuickPurgeExistingMember() {
        /**
         * Create test data:
         */

        $person = $this->createPerson();
        $this->isID($person['id']);

        $personGroupID = $this->useCMDBObject()->create(
            ObjectType::PERSON_GROUP,
            $this->generateRandomString()
        );
        $this->isID($personGroupID);
        /*print_r (['data' => [$person['id']]]);*/
        $entryID = $this->useCMDBCategory()->save(
            $personGroupID,
            Category::CATS__PERSON_GROUP_MEMBERS,
            [
                'connected_object' => [$person['id']]
            ]
        );
        $this->isID($entryID);
        /**
         * Verify test data:
         */

        $entries = $this->useCMDBCategory()->read(
            $personGroupID,
            Category::CATS__PERSON_GROUP_MEMBERS
        );

        $this->assertIsArray($entries);
        $this->assertCount(1, $entries);
        $this->isCategoryEntry($entries[0]);
        $this->assertSame($entryID, (int) $entries[0]['id']);
        $this->assertSame($personGroupID, (int) $entries[0]['objID']);
        $this->assertArrayHasKey('connected_object', $entries[0]);
        $this->assertIsArray($entries[0]['connected_object']);
        $this->isAssignedObject($entries[0]['connected_object']);
        $this->assertSame($person['id'], (int) $entries[0]['connected_object']['id']);

        /**<commit_msg>Single value browser changed into multi value browser<commit_after><?php

/**
 * Copyright (C) 2016-2020 <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * @author <NAME> <https://benjamin.heisig.name/>
 * @copyright Copyright (C) 2016-2020 <NAME>
 * @license http://www.gnu.org/licenses/agpl-3.0 GNU Affero General Public License (AGPL)
 * @link https://github.com/bheisig/i-doit-api-client-php
 */

declare(strict_types=1);

namespace bheisig\idoitapi\Issues;

use \Exception;
use bheisig\idoitapi\BaseTest;
use bheisig\idoitapi\CMDBCategory;
use bheisig\idoitapi\Constants\Category;
use bheisig\idoitapi\Constants\ObjectType;

/**
 * @group issues
 * @group API-150
 * @see https://i-doit.atlassian.net/browse/API-150
 */
class API150Test extends BaseTest {

    /**
     * @throws Exception on error
     */
    public function testQuickPurgeExistingMember() {
        /**
         * Create test data:
         */

        $person = $this->createPerson();
        $this->isID($person['id']);

        $personGroupID = $this->useCMDBObject()->create(
            ObjectType::PERSON_GROUP,
            $this->generateRandomString()
        );
        $this->isID($personGroupID);

        $entryID = $this->useCMDBCategory()->save(
            $personGroupID,
            Category::CATS__PERSON_GROUP_MEMBERS,
            [
                'connected_object' => [$person['id']]
            ]
        );
        $this->isID($entryID);
        /**
         * Verify test data:
         */

        $entries = $this->useCMDBCategory()->read(
            $personGroupID,
            Category::CATS__PERSON_GROUP_MEMBERS
        );

        $this->assertIsArray($entries);
        $this->assertCount(1, $entries);
        $this->isCategoryEntry($entries[0]);
        $this->assertSame($entryID, (int) $entries[0]['id']);
        $this->assertSame($personGroupID, (int) $entries[0]['objID']);
        $this->assertArrayHasKey('connected_object', $entries[0]);
        $this->assertIsArray($entries[0]['connected_object']);
        $this->isAssignedObject($entries[0]['connected_object']);
        $this->assertSame($person['id'], (int) $entries[0]['connected_object']['id']);

        /**
{'fraction_non_alphanumeric': 0.14153955303299043, 'fraction_numerical': 0.01312522170982618, 'mean_word_length': 2.907830907830908, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 56, 'https://': 6, 'lorem ipsum': 0, 'www.': 4, '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': '1360178', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1660, 'n_words': 404}