Code Duplication    Length = 55-55 lines in 2 locations

eZ/Publish/Core/REST/Server/Tests/Security/RestSessionBasedAuthenticatorTest.php 2 locations

@@ 368-422 (lines=55) @@
365
        $this->assertSame($authenticatedToken, $this->authenticator->authenticate($request));
366
    }
367
368
    public function testAuthenticate()
369
    {
370
        $username = 'foo_user';
371
        $password = 'publish';
372
373
        $existingToken = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
374
        $existingToken
375
            ->expects($this->once())
376
            ->method('getUsername')
377
            ->will($this->returnValue(__METHOD__));
378
379
        $request = new Request();
380
        $request->attributes->set('username', $username);
381
        $request->attributes->set('password', $password);
382
383
        $usernamePasswordToken = new UsernamePasswordToken($username, $password, self::PROVIDER_KEY);
384
        $authenticatedToken = $this
385
            ->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken')
386
            ->disableOriginalConstructor()
387
            ->getMock();
388
        $this->authenticationManager
389
            ->expects($this->once())
390
            ->method('authenticate')
391
            ->with($this->equalTo($usernamePasswordToken))
392
            ->will($this->returnValue($authenticatedToken));
393
394
        $this->eventDispatcher
395
            ->expects($this->once())
396
            ->method('dispatch')
397
            ->with(
398
                SecurityEvents::INTERACTIVE_LOGIN,
399
                $this->equalTo(new InteractiveLoginEvent($request, $authenticatedToken))
400
            );
401
402
        $this->tokenStorage
403
            ->expects($this->at(0))
404
            ->method('getToken')
405
            ->will($this->returnValue($existingToken));
406
        $this->tokenStorage
407
            ->expects($this->at(1))
408
            ->method('setToken')
409
            ->with($authenticatedToken);
410
        $this->tokenStorage
411
            ->expects($this->at(2))
412
            ->method('getToken')
413
            ->will($this->returnValue($authenticatedToken));
414
415
        $authenticatedUser = $this->createUser(456);
416
        $authenticatedToken
417
            ->expects($this->once())
418
            ->method('getUser')
419
            ->will($this->returnValue($authenticatedUser));
420
421
        $this->assertSame($authenticatedToken, $this->authenticator->authenticate($request));
422
    }
423
424
    public function testAuthenticatePreviousUserNonEz()
425
    {
@@ 488-542 (lines=55) @@
485
        $this->assertSame($authenticatedToken, $this->authenticator->authenticate($request));
486
    }
487
488
    public function testAuthenticatePreviousTokenNotUsernamePassword()
489
    {
490
        $username = 'foo_user';
491
        $password = 'publish';
492
493
        $existingToken = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
494
        $existingToken
495
            ->expects($this->once())
496
            ->method('getUsername')
497
            ->will($this->returnValue(__METHOD__));
498
499
        $request = new Request();
500
        $request->attributes->set('username', $username);
501
        $request->attributes->set('password', $password);
502
503
        $usernamePasswordToken = new UsernamePasswordToken($username, $password, self::PROVIDER_KEY);
504
        $authenticatedToken = $this
505
            ->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken')
506
            ->disableOriginalConstructor()
507
            ->getMock();
508
        $this->authenticationManager
509
            ->expects($this->once())
510
            ->method('authenticate')
511
            ->with($this->equalTo($usernamePasswordToken))
512
            ->will($this->returnValue($authenticatedToken));
513
514
        $this->eventDispatcher
515
            ->expects($this->once())
516
            ->method('dispatch')
517
            ->with(
518
                SecurityEvents::INTERACTIVE_LOGIN,
519
                $this->equalTo(new InteractiveLoginEvent($request, $authenticatedToken))
520
            );
521
522
        $this->tokenStorage
523
            ->expects($this->at(0))
524
            ->method('getToken')
525
            ->will($this->returnValue($existingToken));
526
        $this->tokenStorage
527
            ->expects($this->at(1))
528
            ->method('setToken')
529
            ->with($authenticatedToken);
530
        $this->tokenStorage
531
            ->expects($this->at(2))
532
            ->method('getToken')
533
            ->will($this->returnValue($authenticatedToken));
534
535
        $authenticatedUser = $this->createUser(456);
536
        $authenticatedToken
537
            ->expects($this->once())
538
            ->method('getUser')
539
            ->will($this->returnValue($authenticatedUser));
540
541
        $this->assertSame($authenticatedToken, $this->authenticator->authenticate($request));
542
    }
543
544
    public function testLogout()
545
    {