Skip to content

Commit 49df7c8

Browse files
committed
test: enhance copy command tests with dynamic file discovery
1 parent aa6e8a5 commit 49df7c8

1 file changed

Lines changed: 152 additions & 70 deletions

File tree

.github/workflows/magento-compatibility.yml

Lines changed: 152 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -150,46 +150,87 @@ jobs:
150150
- name: Test Copy Command Functionality
151151
working-directory: magento2
152152
run: |
153-
echo "Test 1: Copy frontend template to frontend theme (dry-run):"
154-
bin/magento mageforge:theme:copy-from-vendor \
155-
vendor/magento/module-theme/view/frontend/templates/page/copyright.phtml \
156-
Magento/luma \
157-
--dry-run
158-
echo "✓ Frontend to frontend mapping works"
159-
echo ""
160-
161-
echo "Test 2: Copy base template to frontend theme (dry-run):"
162-
bin/magento mageforge:theme:copy-from-vendor \
163-
vendor/magento/module-theme/view/base/templates/root.phtml \
164-
Magento/blank \
165-
--dry-run
166-
echo "✓ Base to frontend mapping works"
153+
echo "Finding available test files..."
154+
155+
# Find a frontend template file from any core module
156+
FRONTEND_FILE=$(find vendor/magento/module-*/view/frontend/templates -type f -name "*.phtml" 2>/dev/null | head -1)
157+
if [ -z "$FRONTEND_FILE" ]; then
158+
echo "No frontend template files found, trying layout files..."
159+
FRONTEND_FILE=$(find vendor/magento/module-*/view/frontend/layout -type f -name "*.xml" 2>/dev/null | head -1)
160+
fi
161+
162+
# Find a base template file
163+
BASE_FILE=$(find vendor/magento/module-*/view/base/templates -type f -name "*.phtml" 2>/dev/null | head -1)
164+
if [ -z "$BASE_FILE" ]; then
165+
echo "No base template files found, trying web files..."
166+
BASE_FILE=$(find vendor/magento/module-*/view/base/web -type f \( -name "*.js" -o -name "*.css" \) 2>/dev/null | head -1)
167+
fi
168+
169+
# Find an etc file for negative test
170+
ETC_FILE=$(find vendor/magento/module-catalog/etc -type f -name "*.xml" 2>/dev/null | head -1)
171+
172+
echo "Test files found:"
173+
echo "Frontend: $FRONTEND_FILE"
174+
echo "Base: $BASE_FILE"
175+
echo "Etc: $ETC_FILE"
167176
echo ""
168-
169-
echo "Test 3: Verify non-view file is rejected:"
170-
if bin/magento mageforge:theme:copy-from-vendor \
171-
vendor/magento/module-catalog/etc/di.xml \
172-
Magento/luma \
173-
--dry-run 2>&1 | grep -q "not under a view"; then
174-
echo "✓ Non-view file correctly rejected"
177+
178+
if [ -n "$FRONTEND_FILE" ]; then
179+
echo "Test 1: Copy frontend file to frontend theme (dry-run):"
180+
bin/magento mageforge:theme:copy-from-vendor \
181+
"$FRONTEND_FILE" \
182+
Magento/luma \
183+
--dry-run
184+
echo "✓ Frontend to frontend mapping works"
185+
echo ""
175186
else
176-
echo "✗ Non-view file validation failed"
177-
exit 1
187+
echo "Warning: No frontend file found for testing"
178188
fi
179-
echo ""
180-
181-
echo "Test 4: Verify cross-area mapping is rejected (frontend -> adminhtml):"
182-
if bin/magento mageforge:theme:copy-from-vendor \
183-
vendor/magento/module-theme/view/frontend/templates/page/copyright.phtml \
184-
Magento/backend \
185-
--dry-run 2>&1 | grep -q "Cannot map file from area"; then
186-
echo "✓ Cross-area mapping correctly rejected"
189+
190+
if [ -n "$BASE_FILE" ]; then
191+
echo "Test 2: Copy base file to frontend theme (dry-run):"
192+
bin/magento mageforge:theme:copy-from-vendor \
193+
"$BASE_FILE" \
194+
Magento/blank \
195+
--dry-run
196+
echo "✓ Base to frontend mapping works"
197+
echo ""
187198
else
188-
echo "✗ Cross-area validation failed"
189-
exit 1
199+
echo "Warning: No base file found for testing"
190200
fi
191-
echo ""
192-
201+
202+
if [ -n "$ETC_FILE" ]; then
203+
echo "Test 3: Verify non-view file is rejected:"
204+
if bin/magento mageforge:theme:copy-from-vendor \
205+
"$ETC_FILE" \
206+
Magento/luma \
207+
--dry-run 2>&1 | grep -q "not under a view"; then
208+
echo "✓ Non-view file correctly rejected"
209+
else
210+
echo "✗ Non-view file validation failed"
211+
exit 1
212+
fi
213+
echo ""
214+
else
215+
echo "Warning: No etc file found for negative testing"
216+
fi
217+
218+
if [ -n "$FRONTEND_FILE" ]; then
219+
echo "Test 4: Verify cross-area mapping is rejected (frontend -> adminhtml):"
220+
if bin/magento mageforge:theme:copy-from-vendor \
221+
"$FRONTEND_FILE" \
222+
Magento/backend \
223+
--dry-run 2>&1 | grep -q "Cannot map file from area"; then
224+
echo "✓ Cross-area mapping correctly rejected"
225+
else
226+
echo "✗ Cross-area validation failed"
227+
exit 1
228+
fi
229+
echo ""
230+
else
231+
echo "Warning: No frontend file found for cross-area testing"
232+
fi
233+
193234
echo "✓ All copy command tests passed!"
194235
195236
- name: Test Summary
@@ -328,46 +369,87 @@ jobs:
328369
- name: Test Copy Command Functionality
329370
working-directory: magento2
330371
run: |
331-
echo "Test 1: Copy frontend template to frontend theme (dry-run):"
332-
bin/magento mageforge:theme:copy-from-vendor \
333-
vendor/magento/module-theme/view/frontend/templates/page/copyright.phtml \
334-
Magento/luma \
335-
--dry-run
336-
echo "✓ Frontend to frontend mapping works"
337-
echo ""
338-
339-
echo "Test 2: Copy base template to frontend theme (dry-run):"
340-
bin/magento mageforge:theme:copy-from-vendor \
341-
vendor/magento/module-theme/view/base/templates/root.phtml \
342-
Magento/blank \
343-
--dry-run
344-
echo "✓ Base to frontend mapping works"
372+
echo "Finding available test files..."
373+
374+
# Find a frontend template file from any core module
375+
FRONTEND_FILE=$(find vendor/magento/module-*/view/frontend/templates -type f -name "*.phtml" 2>/dev/null | head -1)
376+
if [ -z "$FRONTEND_FILE" ]; then
377+
echo "No frontend template files found, trying layout files..."
378+
FRONTEND_FILE=$(find vendor/magento/module-*/view/frontend/layout -type f -name "*.xml" 2>/dev/null | head -1)
379+
fi
380+
381+
# Find a base template file
382+
BASE_FILE=$(find vendor/magento/module-*/view/base/templates -type f -name "*.phtml" 2>/dev/null | head -1)
383+
if [ -z "$BASE_FILE" ]; then
384+
echo "No base template files found, trying web files..."
385+
BASE_FILE=$(find vendor/magento/module-*/view/base/web -type f \( -name "*.js" -o -name "*.css" \) 2>/dev/null | head -1)
386+
fi
387+
388+
# Find an etc file for negative test
389+
ETC_FILE=$(find vendor/magento/module-catalog/etc -type f -name "*.xml" 2>/dev/null | head -1)
390+
391+
echo "Test files found:"
392+
echo "Frontend: $FRONTEND_FILE"
393+
echo "Base: $BASE_FILE"
394+
echo "Etc: $ETC_FILE"
345395
echo ""
346-
347-
echo "Test 3: Verify non-view file is rejected:"
348-
if bin/magento mageforge:theme:copy-from-vendor \
349-
vendor/magento/module-catalog/etc/di.xml \
350-
Magento/luma \
351-
--dry-run 2>&1 | grep -q "not under a view"; then
352-
echo "✓ Non-view file correctly rejected"
396+
397+
if [ -n "$FRONTEND_FILE" ]; then
398+
echo "Test 1: Copy frontend file to frontend theme (dry-run):"
399+
bin/magento mageforge:theme:copy-from-vendor \
400+
"$FRONTEND_FILE" \
401+
Magento/luma \
402+
--dry-run
403+
echo "✓ Frontend to frontend mapping works"
404+
echo ""
353405
else
354-
echo "✗ Non-view file validation failed"
355-
exit 1
406+
echo "Warning: No frontend file found for testing"
356407
fi
357-
echo ""
358-
359-
echo "Test 4: Verify cross-area mapping is rejected (frontend -> adminhtml):"
360-
if bin/magento mageforge:theme:copy-from-vendor \
361-
vendor/magento/module-theme/view/frontend/templates/page/copyright.phtml \
362-
Magento/backend \
363-
--dry-run 2>&1 | grep -q "Cannot map file from area"; then
364-
echo "✓ Cross-area mapping correctly rejected"
408+
409+
if [ -n "$BASE_FILE" ]; then
410+
echo "Test 2: Copy base file to frontend theme (dry-run):"
411+
bin/magento mageforge:theme:copy-from-vendor \
412+
"$BASE_FILE" \
413+
Magento/blank \
414+
--dry-run
415+
echo "✓ Base to frontend mapping works"
416+
echo ""
365417
else
366-
echo "✗ Cross-area validation failed"
367-
exit 1
418+
echo "Warning: No base file found for testing"
368419
fi
369-
echo ""
370-
420+
421+
if [ -n "$ETC_FILE" ]; then
422+
echo "Test 3: Verify non-view file is rejected:"
423+
if bin/magento mageforge:theme:copy-from-vendor \
424+
"$ETC_FILE" \
425+
Magento/luma \
426+
--dry-run 2>&1 | grep -q "not under a view"; then
427+
echo "✓ Non-view file correctly rejected"
428+
else
429+
echo "✗ Non-view file validation failed"
430+
exit 1
431+
fi
432+
echo ""
433+
else
434+
echo "Warning: No etc file found for negative testing"
435+
fi
436+
437+
if [ -n "$FRONTEND_FILE" ]; then
438+
echo "Test 4: Verify cross-area mapping is rejected (frontend -> adminhtml):"
439+
if bin/magento mageforge:theme:copy-from-vendor \
440+
"$FRONTEND_FILE" \
441+
Magento/backend \
442+
--dry-run 2>&1 | grep -q "Cannot map file from area"; then
443+
echo "✓ Cross-area mapping correctly rejected"
444+
else
445+
echo "✗ Cross-area validation failed"
446+
exit 1
447+
fi
448+
echo ""
449+
else
450+
echo "Warning: No frontend file found for cross-area testing"
451+
fi
452+
371453
echo "✓ All copy command tests passed!"
372454
373455
- name: Test Summary

0 commit comments

Comments
 (0)