builder->recreate(); self::assertSame($this->builder->getKernel(), $builder->getKernel()); self::assertSame($this->builder->getConfiguration(), $builder->getConfiguration()); } /** * Tests that the build produced the excepted documents */ public function testBuild(): void { self::assertTrue(is_dir($this->targetFile())); self::assertTrue(file_exists($this->targetFile('index.html'))); self::assertTrue(file_exists($this->targetFile('introduction.html'))); self::assertTrue(file_exists($this->targetFile('subdirective.html'))); self::assertTrue(file_exists($this->targetFile('magic-link.html'))); self::assertTrue(file_exists($this->targetFile('subdir/test.html'))); self::assertTrue(file_exists($this->targetFile('subdir/file.html'))); } public function testCachedMetas(): void { // check that metas were cached self::assertTrue(file_exists($this->targetFile('metas.php'))); $cachedContents = (string) file_get_contents($this->targetFile('metas.php')); /** @var MetaEntry[] $metaEntries */ $metaEntries = unserialize($cachedContents); self::assertArrayHasKey('index', $metaEntries); self::assertSame('Summary', $metaEntries['index']->getTitle()); // look at all the other documents this document depends // on, like :doc: and :ref: self::assertSame([ 'index', 'toc-glob', 'subdir/index', ], array_values(array_unique($metaEntries['introduction']->getDepends()))); // assert the self-refs don't mess up dependencies self::assertSame([ 'subdir/index', 'index', 'subdir/file', ], array_values(array_unique($metaEntries['subdir/index']->getDepends()))); // update meta cache to see that it was used // Summary is the main header in "index.rst" // we reference it in link-to-index.rst // it should cause link-to-index.rst to re-render with the new // title as the link file_put_contents( $this->targetFile('metas.php'), str_replace('Summary', 'Sumario', $cachedContents) ); // also we need to trigger the link-to-index.rst as looking updated sleep(1); $contents = file_get_contents(__DIR__ . '/input/link-to-index.rst'); file_put_contents( __DIR__ . '/input/link-to-index.rst', $contents . ' ' ); // change it back file_put_contents( __DIR__ . '/input/link-to-index.rst', $contents ); // new builder, which will use cached metas $builder = new Builder(); $builder->build($this->sourceFile(), $this->targetFile()); $contents = $this->getFileContents($this->targetFile('link-to-index.html')); self::assertStringContainsString('Sumario', $contents); } /** * Tests the ..url :: directive */ public function testUrl(): void { $contents = $this->getFileContents($this->targetFile('index.html')); self::assertStringContainsString('"magic-link.html', $contents); self::assertStringContainsString('Another page', $contents); } /** * Tests the links */ public function testLinks(): void { $contents = $this->getFileContents($this->targetFile('subdir/test.html')); self::assertStringContainsString('"../to/resource"', $contents); self::assertStringContainsString('"http://absolute/"', $contents); self::assertStringContainsString('"http://google.com"', $contents); self::assertStringContainsString('"http://yahoo.com"', $contents); self::assertSame(2, substr_count($contents, 'http://something.com')); } public function testAnchor(): void { $contents = $this->getFileContents($this->targetFile('subdir/test.html')); self::assertStringContainsString('
This is a test anchor
', $contents); self::assertStringContainsString('', $contents); } /** * Tests that the index toctree worked */ public function testToctree(): void { $contents = $this->getFileContents($this->targetFile('index.html')); self::assertStringContainsString('"introduction.html', $contents); self::assertStringContainsString('Introduction page', $contents); self::assertStringContainsString('"subdirective.html', $contents); self::assertStringContainsString('"subdir/test.html', $contents); self::assertStringContainsString('"subdir/file.html', $contents); } public function testToctreeGlob(): void { $contents = $this->getFileContents($this->targetFile('toc-glob.html')); // links to firstReference to the Summary Reference
', $contents); } /** * Testing references to other documents */ public function testReferences(): void { $contents = $this->getFileContents($this->targetFile('introduction.html')); self::assertStringContainsString('Index, paragraph toc', $contents); self::assertStringContainsString('Index', $contents); self::assertStringContainsString('Summary', $contents); self::assertStringContainsString('Link index absolutely', $contents); self::assertStringContainsString('Test Reference', $contents); self::assertStringContainsString('Camel Case Reference', $contents); $contents = $this->getFileContents($this->targetFile('subdir/test.html')); self::assertStringContainsString('"../index.html"', $contents); self::assertStringContainsString('the subdir same doc reference', $contents); self::assertStringContainsString('Reference absolute to index', $contents); self::assertStringContainsString('Reference absolute to file', $contents); self::assertStringContainsString('Reference relative to file', $contents); $contents = $this->getFileContents($this->targetFile('index.html')); self::assertStringContainsString('Link to the same doc reference', $contents); self::assertStringContainsString('Link to the same doc reference with ticks', $contents); self::assertStringContainsString('Link to Subdirectory', $contents); self::assertStringContainsString('Link to Subdirectory Test', $contents); self::assertStringContainsString('Link to Subdirectory Child', $contents); self::assertStringContainsString('Link to Subdirectory Child Test', $contents); self::assertStringContainsString('Link to Subdirectory Child Level 2', $contents); self::assertStringContainsString('Link to Subdirectory Child Level 2 Test', $contents); self::assertStringContainsString('Link to Subdirectory Child Level 3', $contents); self::assertStringContainsString('Link to Subdirectory Child Level 3 Test', $contents); } public function testSubdirReferences(): void { $contents = $this->getFileContents($this->targetFile('subdir/test.html')); self::assertStringContainsString('This is a test anchor
', $contents); self::assertStringContainsString('This is a test subdir reference with anchor
', $contents); } public function testFileInclude(): void { $contents = $this->getFileContents($this->targetFile('subdir/test.html')); self::assertSame(2, substr_count($contents, 'This file is included')); } /** * Testing wrapping sub directive */ public function testSubDirective(): void { $contents = $this->getFileContents($this->targetFile('subdirective.html')); self::assertSame(2, substr_count($contents, 'This is a simple note!
', $contents); self::assertStringContainsString('see See also
', $contents ); self::assertStringContainsString( 'see Another page
', $contents ); self::assertStringContainsString( 'see test
', $contents ); self::assertStringContainsString( '', $contents ); self::assertStringContainsString( '', $contents ); } public function testHeadings(): void { $contents = $this->getFileContents($this->targetFile('subdir/file.html')); foreach (range(1, 6) as $index) { self::assertStringContainsString( sprintf( '