1+ ! ! Test for GitHub Pages image path resolution - Issue #205
2+ ! !
3+ ! ! Given-When-Then Documentation:
4+ ! !
5+ ! ! GIVEN:
6+ ! ! - Documentation markdown files reference images with relative paths like "../../media/examples/basic_plots/simple_plot.png"
7+ ! ! - FORD generates HTML files in subdirectories like "build/doc/page/example/"
8+ ! ! - Media files need to be accessible at the correct relative paths for deployed GitHub Pages
9+ ! !
10+ ! ! WHEN:
11+ ! ! - Documentation build process runs
12+ ! ! - FORD processes markdown files and generates HTML
13+ ! ! - Media files are copied to build directory
14+ ! !
15+ ! ! THEN:
16+ ! ! - Media files should be accessible at the expected relative paths from generated HTML
17+ ! ! - Image links in generated HTML should resolve correctly
18+ ! ! - Both local builds and GitHub Pages deployment should work
19+ ! !
20+ ! ! TEST SCENARIOS:
21+ ! ! 1. Media file staging validation (pre-FORD copy requirement)
22+ ! ! 2. Relative path resolution from generated HTML directories
23+ ! ! 3. Documentation build process integration test
24+ ! ! 4. Image accessibility validation for GitHub Pages structure
25+ ! !
26+ program test_github_pages_image_paths_issue_205
27+ use fortplot_security, only: get_test_output_path
28+ implicit none
29+
30+ call test_media_file_staging_validation()
31+ call test_relative_path_resolution_from_html()
32+ call test_documentation_build_process_integration()
33+ call test_image_accessibility_validation()
34+
35+ contains
36+
37+ subroutine test_media_file_staging_validation ()
38+ ! ! Given-When-Then: Test that media files are staged correctly before FORD runs
39+ ! !
40+ ! ! GIVEN: Media files exist in source and output locations
41+ ! ! WHEN: Documentation build process prepares files for FORD
42+ ! ! THEN: Media files should be accessible at paths expected by markdown relative references
43+
44+ logical :: source_media_exists, staged_media_exists
45+ character (len= :), allocatable :: source_path, expected_staged_path
46+
47+ print * , " === Testing Media File Staging Validation ==="
48+
49+ ! Given: Check source media files exist
50+ source_path = " doc/media/examples/basic_plots/simple_plot.png"
51+ inquire (file= source_path, exist= source_media_exists)
52+
53+ if (.not. source_media_exists) then
54+ print * , " WARNING: Source media file not found: " , source_path
55+ print * , " This test requires media files to be generated first"
56+ endif
57+
58+ ! When: Check if media files are staged where FORD-generated HTML expects them
59+ ! For HTML at build/doc/page/example/*.html, the path ../../media/examples/* should resolve to build/doc/media/examples/*
60+ expected_staged_path = " build/doc/media/examples/basic_plots/simple_plot.png"
61+ inquire (file= expected_staged_path, exist= staged_media_exists)
62+
63+ ! Then: Media files should be staged correctly
64+ if (source_media_exists .and. .not. staged_media_exists) then
65+ print * , " FAIL: Media files not staged correctly for GitHub Pages"
66+ print * , " Expected: " , expected_staged_path
67+ print * , " This indicates media files are copied AFTER FORD runs (current broken behavior)"
68+ call exit(1 ) ! This should fail until fix is implemented
69+ elseif (staged_media_exists) then
70+ print * , " PASS: Media files staged correctly at: " , expected_staged_path
71+ else
72+ print * , " SKIP: No source media files to test staging"
73+ endif
74+
75+ print * , " === Media File Staging Validation Complete ==="
76+ end subroutine test_media_file_staging_validation
77+
78+ subroutine test_relative_path_resolution_from_html ()
79+ ! ! Given-When-Then: Test that relative paths resolve correctly from generated HTML locations
80+ ! !
81+ ! ! GIVEN: FORD generates HTML files in nested directory structures
82+ ! ! WHEN: Markdown uses relative paths like "../../media/examples/"
83+ ! ! THEN: These paths should resolve correctly from the generated HTML location
84+
85+ logical :: html_dir_exists, target_media_exists
86+ character (len= :), allocatable :: html_dir, relative_path_target
87+
88+ print * , " === Testing Relative Path Resolution ==="
89+
90+ ! Given: Check if FORD generates HTML in the expected location
91+ html_dir = " build/doc/page/example"
92+ inquire (file= trim (html_dir)// ' /.' , exist= html_dir_exists)
93+
94+ if (.not. html_dir_exists) then
95+ print * , " INFO: HTML directory not found: " , html_dir
96+ print * , " This test requires documentation to be built first"
97+ endif
98+
99+ ! When: Relative path from HTML should resolve to media location
100+ ! From build/doc/page/example/*.html, ../../media/examples/* should resolve to build/doc/media/examples/*
101+ relative_path_target = " build/doc/media/examples"
102+ inquire (file= trim (relative_path_target)// ' /.' , exist= target_media_exists)
103+
104+ ! Then: Target directory should exist for relative paths to work
105+ if (html_dir_exists .and. .not. target_media_exists) then
106+ print * , " FAIL: Relative path target directory does not exist"
107+ print * , " HTML dir exists: " , html_dir
108+ print * , " Expected target: " , relative_path_target
109+ print * , " Relative paths in generated HTML will be broken"
110+ elseif (target_media_exists) then
111+ print * , " PASS: Relative path target directory exists: " , relative_path_target
112+ else
113+ print * , " SKIP: Documentation not built, cannot test relative path resolution"
114+ endif
115+
116+ print * , " === Relative Path Resolution Test Complete ==="
117+ end subroutine test_relative_path_resolution_from_html
118+
119+ subroutine test_documentation_build_process_integration ()
120+ ! ! Given-When-Then: Test the complete documentation build process
121+ ! !
122+ ! ! GIVEN: Source documentation and media files exist
123+ ! ! WHEN: Documentation build process runs (make doc)
124+ ! ! THEN: Generated HTML should have working image references
125+
126+ logical :: makefile_exists, readme_exists
127+
128+ print * , " === Testing Documentation Build Process Integration ==="
129+
130+ ! Given: Check build environment prerequisites
131+ inquire (file= " Makefile" , exist= makefile_exists)
132+ inquire (file= " README.md" , exist= readme_exists)
133+
134+ if (.not. makefile_exists .or. .not. readme_exists) then
135+ print * , " FAIL: Missing build prerequisites"
136+ print * , " Makefile exists: " , makefile_exists
137+ print * , " README.md exists: " , readme_exists
138+ call exit(1 )
139+ endif
140+
141+ ! When: Documentation build process should work
142+ ! This is validated by checking that the staging happens correctly
143+ print * , " INFO: Documentation build integration requires:"
144+ print * , " 1. Media files copied to build/doc/media/examples/ BEFORE FORD runs"
145+ print * , " 2. FORD processes markdown files with working relative paths"
146+ print * , " 3. Generated HTML can access images via ../../media/examples/ paths"
147+
148+ ! Then: The build process structure should support GitHub Pages deployment
149+ print * , " VALIDATION: Current build process analysis:"
150+ print * , " - Makefile copies media AFTER FORD (lines 95-108): BROKEN"
151+ print * , " - GitHub Actions copies media AFTER FORD (lines 83-85): BROKEN"
152+ print * , " - Need to copy media BEFORE FORD for relative paths to work"
153+
154+ print * , " === Documentation Build Process Integration Test Complete ==="
155+ end subroutine test_documentation_build_process_integration
156+
157+ subroutine test_image_accessibility_validation ()
158+ ! ! Given-When-Then: Test that images are accessible for GitHub Pages deployment
159+ ! !
160+ ! ! GIVEN: Documentation is built with media files
161+ ! ! WHEN: Deployed to GitHub Pages at lazy-fortran.github.io/fortplot/
162+ ! ! THEN: Image links should work correctly in the deployed environment
163+
164+ logical :: build_doc_exists, media_examples_exists
165+ character (len= :), allocatable :: github_pages_media_path
166+
167+ print * , " === Testing Image Accessibility for GitHub Pages ==="
168+
169+ ! Given: Check if documentation build directory exists
170+ inquire (file= " build/doc/." , exist= build_doc_exists)
171+
172+ if (.not. build_doc_exists) then
173+ print * , " INFO: build/doc directory not found, cannot test accessibility"
174+ print * , " Run 'make doc' first to generate documentation"
175+ return
176+ endif
177+
178+ ! When: Check if media files are in the correct location for GitHub Pages
179+ github_pages_media_path = " build/doc/media/examples"
180+ inquire (file= trim (github_pages_media_path)// ' /.' , exist= media_examples_exists)
181+
182+ ! Then: Media files should be accessible at the expected GitHub Pages URLs
183+ if (.not. media_examples_exists) then
184+ print * , " FAIL: Media files not accessible for GitHub Pages deployment"
185+ print * , " Expected at: " , github_pages_media_path
186+ print * , " This will cause broken images in deployed documentation"
187+ print * , " Current broken URL pattern: https://lazy-fortran.github.io/fortplot/page/example/basic_plots.html"
188+ print * , " Tries to access: ../../media/examples/basic_plots/simple_plot.png"
189+ print * , " Should resolve to: https://lazy-fortran.github.io/fortplot/media/examples/basic_plots/simple_plot.png"
190+ else
191+ print * , " PASS: Media files accessible for GitHub Pages at: " , github_pages_media_path
192+ endif
193+
194+ ! Additional validation for specific example files
195+ call validate_specific_image_files()
196+
197+ print * , " === Image Accessibility Validation Complete ==="
198+ end subroutine test_image_accessibility_validation
199+
200+ subroutine validate_specific_image_files ()
201+ ! ! Validate specific image files mentioned in the issue
202+ logical :: basic_plots_png_exists, basic_plots_pdf_exists
203+ character (len= :), allocatable :: png_path, pdf_path
204+
205+ print * , " --- Validating Specific Files ---"
206+
207+ ! Check for basic_plots example files (mentioned in issue)
208+ png_path = " build/doc/media/examples/basic_plots/simple_plot.png"
209+ pdf_path = " build/doc/media/examples/basic_plots/simple_plot.pdf"
210+
211+ inquire (file= png_path, exist= basic_plots_png_exists)
212+ inquire (file= pdf_path, exist= basic_plots_pdf_exists)
213+
214+ if (basic_plots_png_exists) then
215+ print * , " PASS: basic_plots PNG accessible: " , png_path
216+ else
217+ print * , " FAIL: basic_plots PNG not accessible: " , png_path
218+ endif
219+
220+ if (basic_plots_pdf_exists) then
221+ print * , " PASS: basic_plots PDF accessible: " , pdf_path
222+ else
223+ print * , " FAIL: basic_plots PDF not accessible: " , pdf_path
224+ endif
225+
226+ ! Validate that these files would be accessible via GitHub Pages URLs
227+ if (basic_plots_png_exists .and. basic_plots_pdf_exists) then
228+ print * , " SUCCESS: Files should be accessible at GitHub Pages URLs:"
229+ print * , " PNG: https://lazy-fortran.github.io/fortplot/media/examples/basic_plots/simple_plot.png"
230+ print * , " PDF: https://lazy-fortran.github.io/fortplot/media/examples/basic_plots/simple_plot.pdf"
231+ endif
232+ end subroutine validate_specific_image_files
233+
234+ end program test_github_pages_image_paths_issue_205
0 commit comments