You are here

class SessionTest in Zircon Profile 8

Same name in this branch
  1. 8 vendor/behat/mink/tests/SessionTest.php \Behat\Mink\Tests\SessionTest
  2. 8 vendor/symfony/http-foundation/Tests/Session/SessionTest.php \Symfony\Component\HttpFoundation\Tests\Session\SessionTest
  3. 8 core/modules/system/src/Tests/Session/SessionTest.php \Drupal\system\Tests\Session\SessionTest
Same name and namespace in other branches
  1. 8.0 vendor/behat/mink/tests/SessionTest.php \Behat\Mink\Tests\SessionTest

Hierarchy

  • class \Behat\Mink\Tests\SessionTest extends \Behat\Mink\Tests\PHPUnit_Framework_TestCase

Expanded class hierarchy of SessionTest

File

vendor/behat/mink/tests/SessionTest.php, line 7

Namespace

Behat\Mink\Tests
View source
class SessionTest extends \PHPUnit_Framework_TestCase {

  /**
   * @var \PHPUnit_Framework_MockObject_MockObject
   */
  private $driver;
  private $selectorsHandler;

  /**
   * Session.
   *
   * @var Session
   */
  private $session;
  protected function setUp() {
    $this->driver = $this
      ->getMockBuilder('Behat\\Mink\\Driver\\DriverInterface')
      ->getMock();
    $this->selectorsHandler = $this
      ->getMockBuilder('Behat\\Mink\\Selector\\SelectorsHandler')
      ->getMock();
    $this->session = new Session($this->driver, $this->selectorsHandler);
  }
  public function testGetDriver() {
    $this
      ->assertSame($this->driver, $this->session
      ->getDriver());
  }
  public function testGetPage() {
    $this
      ->assertInstanceOf('Behat\\Mink\\Element\\DocumentElement', $this->session
      ->getPage());
  }
  public function testGetSelectorsHandler() {
    $this
      ->assertSame($this->selectorsHandler, $this->session
      ->getSelectorsHandler());
  }
  public function testInstantiateWithoutOptionalDeps() {
    $session = new Session($this->driver);
    $this
      ->assertInstanceOf('Behat\\Mink\\Selector\\SelectorsHandler', $session
      ->getSelectorsHandler());
  }
  public function testIsStarted() {
    $this->driver
      ->expects($this
      ->once())
      ->method('isStarted')
      ->will($this
      ->returnValue(true));
    $this
      ->assertTrue($this->session
      ->isStarted());
  }
  public function testStart() {
    $this->driver
      ->expects($this
      ->once())
      ->method('start');
    $this->session
      ->start();
  }
  public function testStop() {
    $this->driver
      ->expects($this
      ->once())
      ->method('stop');
    $this->session
      ->stop();
  }
  public function testRestart() {
    $this->driver
      ->expects($this
      ->at(0))
      ->method('stop');
    $this->driver
      ->expects($this
      ->at(1))
      ->method('start');
    $this->session
      ->restart();
  }
  public function testVisit() {
    $this->driver
      ->expects($this
      ->once())
      ->method('visit')
      ->with($url = 'some_url');
    $this->session
      ->visit($url);
  }
  public function testReset() {
    $this->driver
      ->expects($this
      ->once())
      ->method('reset');
    $this->session
      ->reset();
  }
  public function testSetBasicAuth() {
    $this->driver
      ->expects($this
      ->once())
      ->method('setBasicAuth')
      ->with('user', 'pass');
    $this->session
      ->setBasicAuth('user', 'pass');
  }
  public function testSetRequestHeader() {
    $this->driver
      ->expects($this
      ->once())
      ->method('setRequestHeader')
      ->with('name', 'value');
    $this->session
      ->setRequestHeader('name', 'value');
  }
  public function testGetResponseHeaders() {
    $this->driver
      ->expects($this
      ->once())
      ->method('getResponseHeaders')
      ->will($this
      ->returnValue($ret = array(
      2,
      3,
      4,
    )));
    $this
      ->assertEquals($ret, $this->session
      ->getResponseHeaders());
  }

  /**
   * @dataProvider provideResponseHeader
   */
  public function testGetResponseHeader($expected, $name, array $headers) {
    $this->driver
      ->expects($this
      ->once())
      ->method('getResponseHeaders')
      ->willReturn($headers);
    $this
      ->assertSame($expected, $this->session
      ->getResponseHeader($name));
  }
  public function provideResponseHeader() {
    return array(
      array(
        'test',
        'Mink',
        array(
          'Mink' => 'test',
        ),
      ),
      array(
        'test',
        'mink',
        array(
          'Mink' => 'test',
        ),
      ),
      array(
        'test',
        'Mink',
        array(
          'mink' => 'test',
        ),
      ),
      array(
        'test',
        'Mink',
        array(
          'Mink' => array(
            'test',
            'test2',
          ),
        ),
      ),
      array(
        null,
        'other',
        array(
          'Mink' => 'test',
        ),
      ),
    );
  }
  public function testSetCookie() {
    $this->driver
      ->expects($this
      ->once())
      ->method('setCookie')
      ->with('name', 'value');
    $this->session
      ->setCookie('name', 'value');
  }
  public function testGetCookie() {
    $this->driver
      ->expects($this
      ->once())
      ->method('getCookie')
      ->with('name')
      ->will($this
      ->returnValue('value'));
    $this
      ->assertEquals('value', $this->session
      ->getCookie('name'));
  }
  public function testGetStatusCode() {
    $this->driver
      ->expects($this
      ->once())
      ->method('getStatusCode')
      ->will($this
      ->returnValue($ret = 404));
    $this
      ->assertEquals($ret, $this->session
      ->getStatusCode());
  }
  public function testGetCurrentUrl() {
    $this->driver
      ->expects($this
      ->once())
      ->method('getCurrentUrl')
      ->will($this
      ->returnValue($ret = 'http://some.url'));
    $this
      ->assertEquals($ret, $this->session
      ->getCurrentUrl());
  }
  public function testGetScreenshot() {
    $this->driver
      ->expects($this
      ->once())
      ->method('getScreenshot')
      ->will($this
      ->returnValue('screenshot'));
    $this
      ->assertEquals('screenshot', $this->session
      ->getScreenshot());
  }
  public function testGetWindowNames() {
    $this->driver
      ->expects($this
      ->once())
      ->method('getWindowNames')
      ->will($this
      ->returnValue($names = array(
      'window 1',
      'window 2',
    )));
    $this
      ->assertEquals($names, $this->session
      ->getWindowNames());
  }
  public function testGetWindowName() {
    $this->driver
      ->expects($this
      ->once())
      ->method('getWindowName')
      ->will($this
      ->returnValue('name'));
    $this
      ->assertEquals('name', $this->session
      ->getWindowName());
  }
  public function testReload() {
    $this->driver
      ->expects($this
      ->once())
      ->method('reload');
    $this->session
      ->reload();
  }
  public function testBack() {
    $this->driver
      ->expects($this
      ->once())
      ->method('back');
    $this->session
      ->back();
  }
  public function testForward() {
    $this->driver
      ->expects($this
      ->once())
      ->method('forward');
    $this->session
      ->forward();
  }
  public function testSwitchToWindow() {
    $this->driver
      ->expects($this
      ->once())
      ->method('switchToWindow')
      ->with('test');
    $this->session
      ->switchToWindow('test');
  }
  public function testSwitchToIFrame() {
    $this->driver
      ->expects($this
      ->once())
      ->method('switchToIFrame')
      ->with('test');
    $this->session
      ->switchToIFrame('test');
  }
  public function testExecuteScript() {
    $this->driver
      ->expects($this
      ->once())
      ->method('executeScript')
      ->with($arg = 'JS');
    $this->session
      ->executeScript($arg);
  }
  public function testEvaluateScript() {
    $this->driver
      ->expects($this
      ->once())
      ->method('evaluateScript')
      ->with($arg = 'JS func')
      ->will($this
      ->returnValue($ret = '23'));
    $this
      ->assertEquals($ret, $this->session
      ->evaluateScript($arg));
  }
  public function testWait() {
    $this->driver
      ->expects($this
      ->once())
      ->method('wait')
      ->with(1000, 'function () {}');
    $this->session
      ->wait(1000, 'function () {}');
  }
  public function testResizeWindow() {
    $this->driver
      ->expects($this
      ->once())
      ->method('resizeWindow')
      ->with(800, 600, 'test');
    $this->session
      ->resizeWindow(800, 600, 'test');
  }
  public function testMaximizeWindow() {
    $this->driver
      ->expects($this
      ->once())
      ->method('maximizeWindow')
      ->with('test');
    $this->session
      ->maximizeWindow('test');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SessionTest::$driver private property
SessionTest::$selectorsHandler private property
SessionTest::$session private property Session.
SessionTest::provideResponseHeader public function
SessionTest::setUp protected function
SessionTest::testBack public function
SessionTest::testEvaluateScript public function
SessionTest::testExecuteScript public function
SessionTest::testForward public function
SessionTest::testGetCookie public function
SessionTest::testGetCurrentUrl public function
SessionTest::testGetDriver public function
SessionTest::testGetPage public function
SessionTest::testGetResponseHeader public function @dataProvider provideResponseHeader
SessionTest::testGetResponseHeaders public function
SessionTest::testGetScreenshot public function
SessionTest::testGetSelectorsHandler public function
SessionTest::testGetStatusCode public function
SessionTest::testGetWindowName public function
SessionTest::testGetWindowNames public function
SessionTest::testInstantiateWithoutOptionalDeps public function
SessionTest::testIsStarted public function
SessionTest::testMaximizeWindow public function
SessionTest::testReload public function
SessionTest::testReset public function
SessionTest::testResizeWindow public function
SessionTest::testRestart public function
SessionTest::testSetBasicAuth public function
SessionTest::testSetCookie public function
SessionTest::testSetRequestHeader public function
SessionTest::testStart public function
SessionTest::testStop public function
SessionTest::testSwitchToIFrame public function
SessionTest::testSwitchToWindow public function
SessionTest::testVisit public function
SessionTest::testWait public function