Code Duplication    Length = 66-66 lines in 2 locations

eZ/Publish/Core/MVC/Symfony/Routing/Tests/UrlAliasGeneratorTest.php 2 locations

@@ 214-279 (lines=66) @@
211
    /**
212
     * @dataProvider providerTestDoGenerateWithSiteaccess
213
     */
214
    public function testDoGenerateWithSiteAccessParam(URLAlias $urlAlias, array $parameters, $expected)
215
    {
216
        $siteaccessName = 'foo';
217
        $parameters += ['siteaccess' => $siteaccessName];
218
        $languages = ['esl-ES', 'fre-FR', 'eng-GB'];
219
220
        $saRootLocations = [
221
            'foo' => 2,
222
            'bar' => 100,
223
        ];
224
        $treeRootUrlAlias = [
225
            2 => new URLAlias(['path' => '/']),
226
            100 => new URLAlias(['path' => '/foo/bar']),
227
        ];
228
229
        $this->configResolver
230
            ->expects($this->any())
231
            ->method('getParameter')
232
            ->will(
233
                $this->returnValueMap(
234
                    [
235
                        ['languages', null, 'foo', $languages],
236
                        ['languages', null, 'bar', $languages],
237
                        ['content.tree_root.location_id', null, 'foo', $saRootLocations['foo']],
238
                        ['content.tree_root.location_id', null, 'bar', $saRootLocations['bar']],
239
                    ]
240
                )
241
            );
242
243
        $location = new Location(['id' => 123]);
244
        $this->urlAliasService
245
            ->expects($this->exactly(1))
246
            ->method('listLocationAliases')
247
            ->will(
248
                $this->returnValueMap(
249
                    [
250
                        [$location, false, null, null, $languages, [$urlAlias]],
251
                    ]
252
                )
253
            );
254
255
        $this->locationService
256
            ->expects($this->once())
257
            ->method('loadLocation')
258
            ->will(
259
                $this->returnCallback(
260
                    function ($locationId) {
261
                        return new Location(['id' => $locationId]);
262
                    }
263
                )
264
            );
265
        $this->urlAliasService
266
            ->expects($this->exactly(1))
267
            ->method('reverseLookup')
268
            ->will(
269
                $this->returnCallback(
270
                    function ($location) use ($treeRootUrlAlias) {
271
                        return $treeRootUrlAlias[$location->id];
272
                    }
273
                )
274
            );
275
276
        $this->urlAliasGenerator->setSiteAccess(new SiteAccess('test', 'fake', $this->createMock(SiteAccess\URILexer::class)));
277
278
        $this->assertSame($expected, $this->urlAliasGenerator->doGenerate($location, $parameters));
279
    }
280
281
    public function providerTestDoGenerateWithSiteaccess()
282
    {
@@ 305-370 (lines=66) @@
302
    /**
303
     * @dataProvider providerTestDoGenerateWithFragment
304
     */
305
    public function testDoGenerateWithFragmentParameter(URLAlias $urlAlias, array $parameters, $expected)
306
    {
307
        $siteaccessName = 'foo';
308
        $parameters += ['siteaccess' => $siteaccessName];
309
        $languages = ['esl-ES', 'fre-FR', 'eng-GB'];
310
311
        $saRootLocations = [
312
            'foo' => 2,
313
            'bar' => 100,
314
        ];
315
        $treeRootUrlAlias = [
316
            2 => new URLAlias(['path' => '/']),
317
            100 => new URLAlias(['path' => '/foo/bar']),
318
        ];
319
320
        $this->configResolver
321
            ->expects($this->any())
322
            ->method('getParameter')
323
            ->will(
324
                $this->returnValueMap(
325
                    [
326
                        ['languages', null, 'foo', $languages],
327
                        ['languages', null, 'bar', $languages],
328
                        ['content.tree_root.location_id', null, 'foo', $saRootLocations['foo']],
329
                        ['content.tree_root.location_id', null, 'bar', $saRootLocations['bar']],
330
                    ]
331
                )
332
            );
333
334
        $location = new Location(['id' => 123]);
335
        $this->urlAliasService
336
            ->expects($this->exactly(1))
337
            ->method('listLocationAliases')
338
            ->will(
339
                $this->returnValueMap(
340
                    [
341
                        [$location, false, null, null, $languages, [$urlAlias]],
342
                    ]
343
                )
344
            );
345
346
        $this->locationService
347
            ->expects($this->once())
348
            ->method('loadLocation')
349
            ->will(
350
                $this->returnCallback(
351
                    function ($locationId) {
352
                        return new Location(['id' => $locationId]);
353
                    }
354
                )
355
            );
356
        $this->urlAliasService
357
            ->expects($this->exactly(1))
358
            ->method('reverseLookup')
359
            ->will(
360
                $this->returnCallback(
361
                    function ($location) use ($treeRootUrlAlias) {
362
                        return $treeRootUrlAlias[$location->id];
363
                    }
364
                )
365
            );
366
367
        $this->urlAliasGenerator->setSiteAccess(new SiteAccess('test', 'fake', $this->createMock(SiteAccess\URILexer::class)));
368
369
        $this->assertSame($expected, $this->urlAliasGenerator->doGenerate($location, $parameters));
370
    }
371
372
    public function providerTestDoGenerateWithFragment()
373
    {