|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * Copyright 2022 Google Inc. |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or modify it under |
| 7 | + * the terms of the GNU General Public License version 2 as published by the |
| 8 | + * Free Software Foundation. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
| 11 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 12 | + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
| 13 | + * License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License along |
| 16 | + * with this program; if not, write to the Free Software Foundation, Inc., 51 |
| 17 | + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | + */ |
| 19 | + |
| 20 | +namespace Drupal\Tests\apigee_edge\Kernel; |
| 21 | + |
| 22 | +use Drupal\KernelTests\KernelTestBase; |
| 23 | +use Drupal\Core\Extension\InfoParser; |
| 24 | +use Drupal\Core\Extension\InfoParserInterface; |
| 25 | + |
| 26 | +/** |
| 27 | + * Apigee Useragent tests. |
| 28 | + * |
| 29 | + * @group apigee_edge |
| 30 | + * @group apigee_edge_kernel |
| 31 | + */ |
| 32 | +class UserAgentTest extends KernelTestBase { |
| 33 | + |
| 34 | + /** |
| 35 | + * Apigee Edge module info. |
| 36 | + * |
| 37 | + * @var string |
| 38 | + */ |
| 39 | + protected $edgeModuleInfo; |
| 40 | + |
| 41 | + /** |
| 42 | + * The info parser. |
| 43 | + * |
| 44 | + * @var \Drupal\Core\Extension\InfoParserInterface |
| 45 | + */ |
| 46 | + protected $infoParser; |
| 47 | + |
| 48 | + /** |
| 49 | + * {@inheritdoc} |
| 50 | + */ |
| 51 | + protected static $modules = [ |
| 52 | + 'file', |
| 53 | + 'system', |
| 54 | + ]; |
| 55 | + |
| 56 | + /** |
| 57 | + * {@inheritdoc} |
| 58 | + */ |
| 59 | + protected function setUp() { |
| 60 | + parent::setUp(); |
| 61 | + |
| 62 | + // Install the apigee edge module. |
| 63 | + \Drupal::service('module_installer')->install(['apigee_edge']); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Test the user agent data without monetization module. |
| 68 | + * |
| 69 | + * @throws \Exception |
| 70 | + */ |
| 71 | + public function testUserAgentWithoutMonetization() { |
| 72 | + // apigee_edge module info. |
| 73 | + $infoParser = new InfoParser(); |
| 74 | + $this->edgeModuleInfo = $infoParser->parse(\Drupal::service('module_handler')->getModule('apigee_edge')->getPathname()); |
| 75 | + if (!isset($this->edgeModuleInfo['version'])) { |
| 76 | + $this->edgeModuleInfo['version'] = '2.x-dev'; |
| 77 | + } |
| 78 | + |
| 79 | + $user_agent_parts[] = $this->edgeModuleInfo['name'] . '/' . $this->edgeModuleInfo['version']; |
| 80 | + $user_agent_parts[] = 'Drupal/' . \Drupal::VERSION; |
| 81 | + |
| 82 | + \Drupal::moduleHandler()->invokeAll('apigee_edge_user_agent_string_alter', [&$user_agent_parts]); |
| 83 | + $userAgentPrefix = implode('; ', $user_agent_parts); |
| 84 | + |
| 85 | + $this->assertSame($userAgentPrefix, 'Apigee Edge/2.x-dev;' . ' Drupal/' . \Drupal::VERSION); |
| 86 | + } |
| 87 | + |
| 88 | +} |
0 commit comments