You are here

class SelectorsHandlerTest in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/behat/mink/tests/Selector/SelectorsHandlerTest.php \Behat\Mink\Tests\Selector\SelectorsHandlerTest

Hierarchy

  • class \Behat\Mink\Tests\Selector\SelectorsHandlerTest extends \Behat\Mink\Tests\Selector\PHPUnit_Framework_TestCase

Expanded class hierarchy of SelectorsHandlerTest

File

vendor/behat/mink/tests/Selector/SelectorsHandlerTest.php, line 7

Namespace

Behat\Mink\Tests\Selector
View source
class SelectorsHandlerTest extends \PHPUnit_Framework_TestCase {
  public function testRegisterSelector() {
    $selector = $this
      ->getMockBuilder('Behat\\Mink\\Selector\\SelectorInterface')
      ->getMock();
    $handler = new SelectorsHandler();
    $this
      ->assertFalse($handler
      ->isSelectorRegistered('custom'));
    $handler
      ->registerSelector('custom', $selector);
    $this
      ->assertTrue($handler
      ->isSelectorRegistered('custom'));
    $this
      ->assertSame($selector, $handler
      ->getSelector('custom'));
  }
  public function testRegisterSelectorThroughConstructor() {
    $selector = $this
      ->getMockBuilder('Behat\\Mink\\Selector\\SelectorInterface')
      ->getMock();
    $handler = new SelectorsHandler(array(
      'custom' => $selector,
    ));
    $this
      ->assertTrue($handler
      ->isSelectorRegistered('custom'));
    $this
      ->assertSame($selector, $handler
      ->getSelector('custom'));
  }
  public function testRegisterDefaultSelectors() {
    $handler = new SelectorsHandler();
    $this
      ->assertTrue($handler
      ->isSelectorRegistered('css'));
    $this
      ->assertTrue($handler
      ->isSelectorRegistered('named_exact'));
    $this
      ->assertTrue($handler
      ->isSelectorRegistered('named_partial'));
  }

  /**
   * @expectedException \InvalidArgumentException
   */
  public function testXpathSelectorThrowsExceptionForArrayLocator() {
    $handler = new SelectorsHandler();
    $handler
      ->selectorToXpath('xpath', array(
      'some_xpath',
    ));
  }
  public function testXpathSelectorIsReturnedAsIs() {
    $handler = new SelectorsHandler();
    $this
      ->assertEquals('some_xpath', $handler
      ->selectorToXpath('xpath', 'some_xpath'));
  }
  public function testSelectorToXpath() {
    $selector = $this
      ->getMockBuilder('Behat\\Mink\\Selector\\SelectorInterface')
      ->getMock();
    $handler = new SelectorsHandler();
    $handler
      ->registerSelector('custom_selector', $selector);
    $selector
      ->expects($this
      ->once())
      ->method('translateToXPath')
      ->with($locator = 'some[locator]')
      ->will($this
      ->returnValue($ret = '[]some[]locator'));
    $this
      ->assertEquals($ret, $handler
      ->selectorToXpath('custom_selector', $locator));
    $this
      ->setExpectedException('InvalidArgumentException');
    $handler
      ->selectorToXpath('undefined', 'asd');
  }

  /**
   * @group legacy
   */
  public function testXpathLiteral() {
    $handler = new SelectorsHandler();
    $this
      ->assertEquals("'some simple string'", $handler
      ->xpathLiteral('some simple string'));
  }

  /**
   * @group legacy
   */
  public function testBcLayer() {
    $selector = $this
      ->getMockBuilder('Behat\\Mink\\Selector\\SelectorInterface')
      ->getMock();
    $handler = new SelectorsHandler();
    $handler
      ->registerSelector('named_partial', $selector);
    $this
      ->assertSame($selector, $handler
      ->getSelector('named'));
  }

}

Members