Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f65800e

Browse files
committed
add + adjust tests
1 parent 9e72dcd commit f65800e

File tree

1 file changed

+11
-42
lines changed

1 file changed

+11
-42
lines changed

core-bundle/tests/Twig/Loader/ContaoFilesystemLoaderTest.php

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -131,49 +131,18 @@ public function testPersistsAndRecallsPaths(): void
131131

132132
public function testGetCacheKey(): void
133133
{
134-
$loader = $this->getContaoFilesystemLoader();
134+
$loader = $this->getContaoFilesystemLoader(null, new TemplateLocator('/', [], []));
135135

136136
$path = Path::canonicalize(__DIR__.'/../../Fixtures/Twig/paths/1');
137137

138-
$loader->addPath($path);
138+
$loader->addPath($path, 'Contao', true);
139139

140140
$this->assertSame(
141-
"$path/1.html.twig_d75171",
142-
$loader->getCacheKey('@Contao/1.html.twig')
141+
Path::join($path, '1.html.twig'),
142+
Path::normalize($loader->getCacheKey('@Contao/1.html.twig'))
143143
);
144144
}
145145

146-
public function testCacheKeyChangesWhenHierarchyChanges(): void
147-
{
148-
$filesystem = new Filesystem();
149-
$tempDir = $this->getTempDir();
150-
151-
$addFile = static function (string $filename) use ($tempDir, $filesystem): void {
152-
$filesystem->copy(
153-
__DIR__.'/../../Fixtures/Twig/paths/1/1.html.twig',
154-
Path::join($tempDir, $filename)
155-
);
156-
};
157-
158-
$loader = $this->getContaoFilesystemLoader(null, new TemplateLocator('', [], []));
159-
$loader->addPath($tempDir, 'Contao_Test', true);
160-
$addFile('1.html.twig');
161-
162-
$cacheKey = $loader->getCacheKey('@Contao_Test/1.html.twig');
163-
164-
// Hierarchy should have been built automatically: expect no change
165-
$loader->buildHierarchy();
166-
$this->assertSame($cacheKey, $loader->getCacheKey('@Contao_Test/1.html.twig'));
167-
168-
// Add a template in the tracked path and refresh: expect change
169-
$addFile('2.html.twig');
170-
$loader->buildHierarchy();
171-
172-
$this->assertNotSame($cacheKey, $loader->getCacheKey('@Contao_Test/1.html.twig'));
173-
174-
$filesystem->remove($tempDir);
175-
}
176-
177146
public function testGetCacheKeyDelegatesToThemeTemplate(): void
178147
{
179148
$basePath = Path::canonicalize(__DIR__.'/../../Fixtures/Twig/inheritance');
@@ -184,8 +153,8 @@ public function testGetCacheKeyDelegatesToThemeTemplate(): void
184153
$loader->addPath(Path::join($basePath, 'templates/my/theme'), 'Contao_Theme_my_theme');
185154

186155
$this->assertSame(
187-
Path::join($basePath, 'templates/text.html.twig_d75171'),
188-
$loader->getCacheKey('@Contao/text.html.twig')
156+
Path::join($basePath, 'templates/text.html.twig'),
157+
Path::normalize($loader->getCacheKey('@Contao/text.html.twig'))
189158
);
190159

191160
// Reset and switch context
@@ -197,8 +166,8 @@ public function testGetCacheKeyDelegatesToThemeTemplate(): void
197166
$GLOBALS['objPage'] = $page;
198167

199168
$this->assertSame(
200-
Path::join($basePath, 'templates/my/theme/text.html.twig_d75171'),
201-
$loader->getCacheKey('@Contao/text.html.twig')
169+
Path::join($basePath, 'templates/my/theme/text.html.twig'),
170+
Path::normalize($loader->getCacheKey('@Contao/text.html.twig'))
202171
);
203172

204173
unset($GLOBALS['objPage']);
@@ -215,7 +184,7 @@ public function testGetSourceContext(): void
215184
$source = $loader->getSourceContext('@Contao/1.html.twig');
216185

217186
$this->assertSame('@Contao/1.html.twig', $source->getName());
218-
$this->assertSame(Path::join($path, '1.html.twig'), $source->getPath());
187+
$this->assertSame(Path::join($path, '1.html.twig'), Path::normalize($source->getPath()));
219188
}
220189

221190
public function testGetSourceContextDelegatesToThemeTemplate(): void
@@ -230,7 +199,7 @@ public function testGetSourceContextDelegatesToThemeTemplate(): void
230199
$source = $loader->getSourceContext('@Contao/text.html.twig');
231200

232201
$this->assertSame('@Contao/text.html.twig', $source->getName());
233-
$this->assertSame(Path::join($basePath, 'templates/text.html.twig'), $source->getPath());
202+
$this->assertSame(Path::join($basePath, 'templates/text.html.twig'), Path::normalize($source->getPath()));
234203

235204
// Reset and switch context
236205
$loader->reset();
@@ -243,7 +212,7 @@ public function testGetSourceContextDelegatesToThemeTemplate(): void
243212
$source = $loader->getSourceContext('@Contao/text.html.twig');
244213

245214
$this->assertSame('@Contao_Theme_my_theme/text.html.twig', $source->getName());
246-
$this->assertSame(Path::join($basePath, 'templates/my/theme/text.html.twig'), $source->getPath());
215+
$this->assertSame(Path::join($basePath, 'templates/my/theme/text.html.twig'), Path::normalize($source->getPath()));
247216

248217
unset($GLOBALS['objPage']);
249218
}

0 commit comments

Comments
 (0)