IndexTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\SwaggerWebapi\Block\Swagger;
  7. /**
  8. * @magentoAppArea frontend
  9. */
  10. class IndexTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Swagger\Block\Index
  14. */
  15. private $block;
  16. protected function setUp()
  17. {
  18. \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\App\State::class)
  19. ->setAreaCode('frontend');
  20. $this->block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  21. \Magento\Framework\View\LayoutInterface::class
  22. )->createBlock(
  23. \Magento\Swagger\Block\Index::class,
  24. '',
  25. [
  26. 'data' => [
  27. 'schema_types' => [
  28. 'rest' => \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  29. \Magento\SwaggerWebapi\Model\SchemaType\Rest::class
  30. )
  31. ],
  32. 'default_schema_type_code' => 'rest'
  33. ]
  34. ]
  35. );
  36. }
  37. /**
  38. * Test that the Swagger UI outputs rest as the default when there is no type parameter supplied via URL.
  39. */
  40. public function testDefaultSchemaUrlOutput()
  41. {
  42. $this->assertStringEndsWith('/rest/all/schema?services=all', $this->block->getSchemaUrl());
  43. }
  44. /**
  45. * Test that Swagger UI outputs the supplied store code when it is specified.
  46. */
  47. public function testSchemaUrlOutputWithStore()
  48. {
  49. $this->block->getRequest()->setParams([
  50. 'store' => 'custom',
  51. ]);
  52. $this->assertStringEndsWith('/rest/custom/schema?services=all', $this->block->getSchemaUrl());
  53. }
  54. }