Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added kernel test case for Appgroup Team Invitation and EntityControllerCache #960

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

/**
* Copyright 2023 Google Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 2 as published by the
* Free Software Foundation.
*
* 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 General Public
* License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

namespace Drupal\Tests\apigee_edge_teams\Kernel\ApigeeX;

use Apigee\Edge\Api\ApigeeX\Entity\AppGroup;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\apigee_edge\Traits\EntityControllerCacheUtilsTrait;

/**
* Apigee Edge Teams entity controller cache tests.
*
* @group apigee_edge
* @group apigee_edge_kernel
* @group apigee_edge_teams
* @group apigee_edge_teams_kernel
*/
class EntityControllerCacheTest extends KernelTestBase {

use EntityControllerCacheUtilsTrait;

/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
'apigee_edge',
'apigee_edge_teams',
'key',
];

/**
* Tests team entity controller cache.
*/
public function testTeamEntityControllerCache() {
$team_cache = $this->container->get('apigee_edge_teams.controller.cache.team');
/** @var \Drupal\apigee_edge\Entity\Controller\Cache\EntityIdCacheInterface $team_id_cache */
$team_id_cache = $this->container->get('apigee_edge_teams.controller.cache.team_ids');

// Generate team entities with random data.
$teams = [];
for ($i = 0; $i < 3; $i++) {
$id = $this->getRandomUniqueId();
$teams[$id] = new AppGroup([
'name' => $id,
]);
}

$this->saveAllEntitiesAndValidate($teams, $team_cache, $team_id_cache);

/** @var \Apigee\Edge\Api\Management\Entity\AppGroupInterface $team */
foreach ($teams as $team) {
// Load team by name.
$this->assertSame($team, $team_cache->getEntity($team->getName()));
$this->assertContains($team->getName(), $team_id_cache->getIds());

// Pass an invalid entity id to ensure it does not cause any trouble
// anymore.
// @see \Drupal\apigee_edge\Entity\Controller\Cache\EntityCache::removeEntities()
// @see https://www.drupal.org/project/drupal/issues/3017753
$team_cache->removeEntities([$team->getName(), $this->getRandomGenerator()->string()]);
$this->assertNull($team_cache->getEntity($team->getName()));
$this->assertNotContains($team->getName(), $team_id_cache->getIds());
}

$this->assertEmptyCaches($team_cache, $team_id_cache);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

/**
* Copyright 2023 Google Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/

namespace Drupal\Tests\apigee_edge_teams\Kernel\ApigeeX;

use Drupal\apigee_edge_teams\Entity\Team;
use Drupal\apigee_edge_teams\Entity\TeamInvitation;
use Drupal\apigee_edge_teams\Entity\TeamInvitationInterface;
use Drupal\apigee_edge_teams\Entity\TeamRoleInterface;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\apigee_mock_api_client\Traits\ApigeeMockApiClientHelperTrait;

/**
* Tests team_invitation events.
*
* @group apigee_edge
* @group apigee_edge_kernel
* @group apigee_edge_teams
* @group apigee_edge_teams_kernel
*/
class TeamInvitationEventsTest extends KernelTestBase {

use ApigeeMockApiClientHelperTrait {
apigeeTestHelperSetup as baseSetUp;
}

/**
* {@inheritdoc}
*/
protected static $modules = [
'apigee_edge_teams',
'apigee_edge_teams_invitation_test',
'apigee_edge',
'apigee_mock_api_client',
'key',
'options',
'user',
'system',
'views',
];

/**
* The team entity.
*
* @var \Drupal\apigee_edge_teams\Entity\TeamInterface
*/
protected $entity;

/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();

$this->installConfig(['apigee_edge']);
$this->installConfig(['apigee_edge_teams']);
$this->installEntitySchema('user');
$this->installEntitySchema('team_member_role');
$this->installEntitySchema('team_invitation');
$this->installSchema('system', ['sequences']);
$this->installSchema('user', ['users_data']);

$this->baseSetUp();

$this->addApigeexOrganizationMatchedResponse();
}

/**
* Tests team_invitation events for AppGroup org.
*/
public function testEvents() {
$this->entity = $this->createApigeexTeam();
$this->queueAppGroupResponse($this->entity->decorated());

/** @var \Drupal\apigee_edge_teams\Entity\TeamInvitationInterface $team_invitation */
$team_invitation = TeamInvitation::create([
'team' => ['target_id' => $this->entity->id()],
'team_roles' => [TeamRoleInterface::TEAM_MEMBER_ROLE],
'recipient' => '[email protected]',
]);

// Created.
$team_invitation->save();
$this->assertSame("CREATED", $team_invitation->getLabel());
$this->assertTrue($team_invitation->isPending());

// Declined.
$team_invitation->setStatus(TeamInvitationInterface::STATUS_DECLINED)->save();
$this->assertSame("DECLINED", $team_invitation->getLabel());
$this->assertTrue($team_invitation->isDeclined());

// Accepted.
$team_invitation->setStatus(TeamInvitationInterface::STATUS_ACCEPTED)->save();
$this->assertSame("ACCEPTED", $team_invitation->getLabel());
$this->assertTrue($team_invitation->isAccepted());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ protected function createApigeexTeam(): TeamInterface {
]);

$this->queueAppGroupResponse($team->decorated());
$this->stack->queueMockResponse('no_content');
$team->save();

return $team;
Expand Down