-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support obtaining the configuration of halo.external-url for th…
…emes and plugins (#2714) #### What type of PR is this? /kind improvement /area core /milestone 2.0 #### What this PR does / why we need it: 主题和插件支持获取 `halo.external-url` 配置信息 #### Which issue(s) this PR fixes: Fixes #2711 #### Special notes for your reviewer: how to test it? 1. 在主题中使用`<p th:text="${site.url}"></p>` 可以正确显示 2. 在插件中可以依赖注入 ExternalUrlSupplier /cc @halo-dev/sig-halo #### Does this PR introduce a user-facing change? ```release-note 主题和插件支持获取外部访问地址配置 ```
- Loading branch information
Showing
4 changed files
with
73 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/test/java/run/halo/app/theme/SiteSettingVariablesAcquirerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package run.halo.app.theme; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import reactor.core.publisher.Mono; | ||
import reactor.test.StepVerifier; | ||
import run.halo.app.extension.ConfigMap; | ||
import run.halo.app.infra.ExternalUrlSupplier; | ||
import run.halo.app.infra.SystemConfigurableEnvironmentFetcher; | ||
import run.halo.app.theme.finders.vo.SiteSettingVo; | ||
|
||
/** | ||
* Tests for {@link SiteSettingVariablesAcquirer}. | ||
* | ||
* @author guqing | ||
* @since 2.0.0 | ||
*/ | ||
@ExtendWith(MockitoExtension.class) | ||
public class SiteSettingVariablesAcquirerTest { | ||
@Mock | ||
private ExternalUrlSupplier externalUrlSupplier; | ||
@Mock | ||
private SystemConfigurableEnvironmentFetcher environmentFetcher; | ||
|
||
@InjectMocks | ||
private SiteSettingVariablesAcquirer siteSettingVariablesAcquirer; | ||
|
||
@Test | ||
void acquire() throws URISyntaxException { | ||
ConfigMap configMap = new ConfigMap(); | ||
configMap.setData(Map.of()); | ||
|
||
URI uri = new URI("https://halo.run"); | ||
when(externalUrlSupplier.get()).thenReturn(uri); | ||
when(environmentFetcher.getConfigMap()).thenReturn(Mono.just(configMap)); | ||
|
||
siteSettingVariablesAcquirer.acquire(Mockito.mock(ServerWebExchange.class)) | ||
.as(StepVerifier::create) | ||
.consumeNextWith(result -> { | ||
assertThat(result).containsKey("site"); | ||
assertThat(result.get("site")).isInstanceOf(SiteSettingVo.class); | ||
assertThat((SiteSettingVo) result.get("site")) | ||
.extracting(SiteSettingVo::getUrl) | ||
.isEqualTo(uri); | ||
}) | ||
.verifyComplete(); | ||
} | ||
} |