-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Appgroup testcase for Team view builder (#955)
- Loading branch information
1 parent
b23cfb5
commit 08945a0
Showing
3 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
modules/apigee_edge_teams/tests/src/Kernel/ApigeeX/Entity/TeamViewBuilderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?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\Entity; | ||
|
||
use Drupal\KernelTests\KernelTestBase; | ||
use Drupal\Tests\apigee_edge\Kernel\ApigeeEdgeKernelTestTrait; | ||
use Drupal\Tests\apigee_mock_api_client\Traits\ApigeeMockApiClientHelperTrait; | ||
|
||
/** | ||
* Tests the Team view builder. | ||
* | ||
* @group apigee_edge | ||
* @group apigee_edge_kernel | ||
* @group apigee_edge_teams | ||
* @group apigee_edge_teams_kernel | ||
*/ | ||
class TeamViewBuilderTest extends KernelTestBase { | ||
|
||
use ApigeeMockApiClientHelperTrait, ApigeeEdgeKernelTestTrait; | ||
|
||
/** | ||
* Indicates this test class is mock API client ready. | ||
* | ||
* @var bool | ||
*/ | ||
protected static $mock_api_client_ready = TRUE; | ||
|
||
/** | ||
* The entity type to test. | ||
*/ | ||
const ENTITY_TYPE = 'team'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static $modules = [ | ||
'system', | ||
'apigee_edge', | ||
'apigee_edge_teams', | ||
'apigee_mock_api_client', | ||
'key', | ||
'user', | ||
'options' | ||
]; | ||
|
||
/** | ||
* The team entity. | ||
* | ||
* @var \Drupal\apigee_edge_teams\Entity\TeamInterface | ||
*/ | ||
protected $entity; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @throws \Exception | ||
*/ | ||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->installConfig(['apigee_edge']); | ||
$this->installConfig(['apigee_edge_teams']); | ||
$this->installEntitySchema('user'); | ||
$this->installEntitySchema('team_member_role'); | ||
$this->installSchema('system', ['sequences']); | ||
$this->installSchema('user', ['users_data']); | ||
|
||
$this->apigeeTestHelperSetup(); | ||
$this->addApigeexOrganizationMatchedResponse(); | ||
$this->entity = $this->createApigeexTeam(); | ||
} | ||
|
||
/** | ||
* Tests the cache max-age for the view builder. | ||
*/ | ||
public function testViewCacheExpiration() { | ||
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */ | ||
$entity_type_manager = $this->container->get('entity_type.manager'); | ||
$build = $entity_type_manager->getViewBuilder(static::ENTITY_TYPE)->view($this->entity); | ||
|
||
static::assertEquals(900, $build['#cache']['max-age']); | ||
|
||
// Update the cache setting. | ||
$this->config('apigee_edge_teams.team_settings') | ||
->set('cache_expiration', 0) | ||
->save(); | ||
|
||
$build = $entity_type_manager->getViewBuilder(static::ENTITY_TYPE)->view($this->entity); | ||
static::assertEquals(0, $build['#cache']['max-age']); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
tests/modules/apigee_mock_api_client/tests/response-templates/appgroup.json.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{# | ||
/** | ||
* @file | ||
* AppGroup | ||
* | ||
* Usage: | ||
* @code {% include 'team.json.twig' %} @endcode | ||
* | ||
* Variables: | ||
* - appgroup: The team (appgroup). | ||
* - org_name: The org name. | ||
*/ | ||
#} | ||
{ | ||
"apps": [], | ||
"name": "{{ appgroup.name|default('foo') }}", | ||
"displayName": "{{ appgroup.displayName }}", | ||
"organization": "{{ org_name }}", | ||
"status": "active", | ||
"attributes": [], | ||
"createdAt": 1506959878351, | ||
"createdBy" : "user@example.com", | ||
"lastModifiedAt": 1506959878351, | ||
"lastModifiedBy" : "user@example.com" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters