@@ -699,6 +699,41 @@ than depending on `poly-php', because that package pulls in a released
699699 (set-buffer-modified-p nil )
700700 (setq buffer-file-name nil )))))
701701
702+ (define-derived-mode php-mode-test--stub-ts-mode prog-mode " PHP/stub-ts"
703+ " Stand-in for `php-ts-mode' in `php-mode-test-mode-remap' .
704+ Using a stub keeps the test independent of whether the PHP tree-sitter
705+ grammar is installed." )
706+
707+ (ert-deftest php-mode-test-mode-remap ()
708+ " `php-mode-maybe' must honor `major-mode-remap-alist' .
709+
710+ Emacs's built-in `php-ts-mode' registers (php-mode . php-ts-mode) in
711+ `treesit-major-mode-remap-alist' so that users can toggle between this
712+ package and the core tree-sitter mode; `treesit-enabled-modes' copies
713+ that entry into `major-mode-remap-alist' when they opt in.
714+
715+ `set-auto-mode' applies the remapping to whatever `auto-mode-alist'
716+ names, so file patterns pointing straight at `php-mode' honored it while
717+ those going through `php-mode-maybe' did not: the same buffer became
718+ `php-mode' for \" .php\" but the remapped mode for \" .stub\" ."
719+ (skip-unless (fboundp 'major-mode-remap ))
720+ (dolist (probe '((((php-mode . php-mode-test--stub-ts-mode))
721+ . php-mode-test--stub-ts-mode)
722+ ; ; Without a remapping the derived mode is used as-is.
723+ (nil . php-mode)))
724+ (let ((major-mode-remap-alist (car probe)))
725+ (with-temp-buffer
726+ ; ; `php-derivation-major-mode' consults `buffer-file-name' .
727+ (setq buffer-file-name (expand-file-name " remap.php" temporary-file-directory))
728+ (unwind-protect
729+ (progn
730+ (insert " <?php\n echo 'hi';\n " )
731+ (php-mode-maybe)
732+ (should (equal (cons (car probe) (cdr probe))
733+ (cons (car probe) major-mode))))
734+ (set-buffer-modified-p nil )
735+ (setq buffer-file-name nil ))))))
736+
702737(ert-deftest php-mode-test-php74 ()
703738 " Test highlighting language constructs added in PHP 7.4."
704739 (with-php-mode-test (" 7.4/arrow-function.php" :faces t ))
0 commit comments