|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Tests\unit\Magento\FunctionalTestFramework\Test\Handlers; |
| 8 | + |
| 9 | +use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException; |
| 10 | +use Magento\FunctionalTestingFramework\Util\MagentoTestCase; |
| 11 | +use Magento\FunctionalTestingFramework\Util\DocGenerator; |
| 12 | +use tests\unit\Util\ActionGroupObjectBuilder; |
| 13 | + |
| 14 | +class DocGeneratorTest extends MagentoTestCase |
| 15 | +{ |
| 16 | + const DOC_FILENAME = "documentation"; |
| 17 | + |
| 18 | + /** |
| 19 | + * Basic test to check creation of documentation |
| 20 | + * |
| 21 | + * @throws \Exception |
| 22 | + */ |
| 23 | + public function testBasicCreateDocumentation() |
| 24 | + { |
| 25 | + $annotations = [ |
| 26 | + "page" => "somePage", |
| 27 | + "description" => "someDescription" |
| 28 | + ]; |
| 29 | + $actionGroupUnderTest = (new ActionGroupObjectBuilder()) |
| 30 | + ->withAnnotations($annotations) |
| 31 | + ->withFilename("filename") |
| 32 | + ->build(); |
| 33 | + $docGenerator = new DocGenerator(); |
| 34 | + $docGenerator->createDocumentation( |
| 35 | + [$actionGroupUnderTest->getName() => $actionGroupUnderTest], |
| 36 | + DOCS_OUTPUT_DIR, |
| 37 | + true |
| 38 | + ); |
| 39 | + |
| 40 | + $docFile = DOCS_OUTPUT_DIR . DIRECTORY_SEPARATOR . self::DOC_FILENAME . ".md"; |
| 41 | + |
| 42 | + $this->assertTrue(file_exists($docFile)); |
| 43 | + |
| 44 | + $this->assertFileEquals( |
| 45 | + RESOURCE_DIR . DIRECTORY_SEPARATOR . "basicDocumentation.txt", |
| 46 | + $docFile |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Test to check creation of documentation when overwriting previous |
| 52 | + * |
| 53 | + * @throws \Exception |
| 54 | + */ |
| 55 | + public function testCreateDocumentationWithOverwrite() |
| 56 | + { |
| 57 | + $annotations = [ |
| 58 | + "page" => "somePage", |
| 59 | + "description" => "someDescription" |
| 60 | + ]; |
| 61 | + $actionGroupUnderTest = (new ActionGroupObjectBuilder()) |
| 62 | + ->withAnnotations($annotations) |
| 63 | + ->withFilename("filename") |
| 64 | + ->build(); |
| 65 | + $docGenerator = new DocGenerator(); |
| 66 | + $docGenerator->createDocumentation( |
| 67 | + [$actionGroupUnderTest->getName() => $actionGroupUnderTest], |
| 68 | + DOCS_OUTPUT_DIR, |
| 69 | + true |
| 70 | + ); |
| 71 | + |
| 72 | + $annotations = [ |
| 73 | + "page" => "alteredPage", |
| 74 | + "description" => "alteredDescription" |
| 75 | + ]; |
| 76 | + $actionGroupUnderTest = (new ActionGroupObjectBuilder()) |
| 77 | + ->withAnnotations($annotations) |
| 78 | + ->withFilename("filename") |
| 79 | + ->build(); |
| 80 | + $docGenerator = new DocGenerator(); |
| 81 | + $docGenerator->createDocumentation( |
| 82 | + [$actionGroupUnderTest->getName() => $actionGroupUnderTest], |
| 83 | + DOCS_OUTPUT_DIR, |
| 84 | + true |
| 85 | + ); |
| 86 | + |
| 87 | + $docFile = DOCS_OUTPUT_DIR . DIRECTORY_SEPARATOR . self::DOC_FILENAME . ".md"; |
| 88 | + |
| 89 | + $this->assertTrue(file_exists($docFile)); |
| 90 | + |
| 91 | + $this->assertFileEquals( |
| 92 | + RESOURCE_DIR . DIRECTORY_SEPARATOR . "alteredDocumentation.txt", |
| 93 | + $docFile |
| 94 | + ); |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Test for existing documentation without clean |
| 99 | + * |
| 100 | + * @throws \Exception |
| 101 | + */ |
| 102 | + public function testCreateDocumentationNotCleanException() |
| 103 | + { |
| 104 | + $annotations = [ |
| 105 | + "page" => "somePage", |
| 106 | + "description" => "someDescription" |
| 107 | + ]; |
| 108 | + $actionGroupUnderTest = (new ActionGroupObjectBuilder()) |
| 109 | + ->withAnnotations($annotations) |
| 110 | + ->withFilename("filename") |
| 111 | + ->build(); |
| 112 | + $docGenerator = new DocGenerator(); |
| 113 | + $docGenerator->createDocumentation( |
| 114 | + [$actionGroupUnderTest->getName() => $actionGroupUnderTest], |
| 115 | + DOCS_OUTPUT_DIR, |
| 116 | + true |
| 117 | + ); |
| 118 | + |
| 119 | + $docFile = DOCS_OUTPUT_DIR . DIRECTORY_SEPARATOR . self::DOC_FILENAME . ".md"; |
| 120 | + |
| 121 | + $this->expectException(TestFrameworkException::class); |
| 122 | + $this->expectExceptionMessage("$docFile already exists, please add --clean if you want to overwrite it."); |
| 123 | + |
| 124 | + $docGenerator = new DocGenerator(); |
| 125 | + $docGenerator->createDocumentation( |
| 126 | + [$actionGroupUnderTest->getName() => $actionGroupUnderTest], |
| 127 | + DOCS_OUTPUT_DIR, |
| 128 | + false |
| 129 | + ); |
| 130 | + } |
| 131 | +} |
0 commit comments