|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright 2022 Google Inc. |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or |
| 7 | + * modify it under the terms of the GNU General Public License |
| 8 | + * version 2 as published by the Free Software Foundation. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program; if not, write to the Free Software |
| 17 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| 18 | + * MA 02110-1301, USA. |
| 19 | + */ |
| 20 | + |
| 21 | +namespace Drupal\Tests\apigee_api_catalog\Functional; |
| 22 | + |
| 23 | +use Drupal\Core\Url; |
| 24 | +use Drupal\Tests\BrowserTestBase; |
| 25 | + |
| 26 | +/** |
| 27 | + * Tests apidoc breadcrumb. |
| 28 | + * |
| 29 | + * @group apigee_api_catalog |
| 30 | + */ |
| 31 | +class ApiDocsBreadcrumbTest extends BrowserTestBase { |
| 32 | + |
| 33 | + /** |
| 34 | + * {@inheritdoc} |
| 35 | + */ |
| 36 | + protected $defaultTheme = 'classy'; |
| 37 | + |
| 38 | + /** |
| 39 | + * {@inheritdoc} |
| 40 | + */ |
| 41 | + protected static $modules = [ |
| 42 | + 'node', |
| 43 | + 'path_alias', |
| 44 | + 'apigee_api_catalog', |
| 45 | + 'views', |
| 46 | + 'block', |
| 47 | + ]; |
| 48 | + |
| 49 | + /** |
| 50 | + * A test doc. |
| 51 | + * |
| 52 | + * @var \Drupal\node\NodeInterface |
| 53 | + */ |
| 54 | + protected $apidoc; |
| 55 | + |
| 56 | + /** |
| 57 | + * {@inheritdoc} |
| 58 | + */ |
| 59 | + protected function setUp(): void { |
| 60 | + parent::setUp(); |
| 61 | + $this->drupalPlaceBlock('system_breadcrumb_block'); |
| 62 | + $this->drupalPlaceBlock('page_title_block'); |
| 63 | + |
| 64 | + $this->apidoc = $this->container->get('entity_type.manager') |
| 65 | + ->getStorage('node') |
| 66 | + ->create([ |
| 67 | + 'type' => 'apidoc', |
| 68 | + 'title' => 'API 1', |
| 69 | + 'body' => [ |
| 70 | + 'value' => 'Test API 1', |
| 71 | + 'format' => 'basic_html', |
| 72 | + ], |
| 73 | + 'field_apidoc_spec' => NULL, |
| 74 | + ]); |
| 75 | + |
| 76 | + $this->apidoc->save(); |
| 77 | + |
| 78 | + $user = $this->drupalCreateUser(['access content']); |
| 79 | + $this->drupalLogin($user); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * Tests the route subscriber will redirect from smartdoc routes. |
| 84 | + */ |
| 85 | + public function testApiDocBreadcrumb() { |
| 86 | + // Tests the normal response. |
| 87 | + $url = Url::fromRoute('entity.node.canonical', ['node' => $this->apidoc->id()]); |
| 88 | + $this->drupalGet($url); |
| 89 | + |
| 90 | + // Fetch each node title in the current breadcrumb. |
| 91 | + $links = $this->xpath('//nav[@class="breadcrumb"]/ol/li/a'); |
| 92 | + $got_breadcrumb = []; |
| 93 | + foreach ($links as $link) { |
| 94 | + $got_breadcrumb[] = $link->getText(); |
| 95 | + } |
| 96 | + // print_r($got_breadcrumb); |
| 97 | + $this->assertEquals($got_breadcrumb[0], 'Home'); |
| 98 | + $this->assertEquals($got_breadcrumb[1], 'API Catalog'); |
| 99 | + |
| 100 | + } |
| 101 | + |
| 102 | +} |
0 commit comments