/** * @dataProvider selectDeselectDataProvider */ public function testSelect($checked) { $this->webElement->shouldReceive('isSelected')->once()->andReturn($checked); $this->webElement->shouldReceive('getAttribute')->with('value')->andReturn('OK'); $web_element = m::mock(self::WEB_ELEMENT_CLASS); $web_element->shouldReceive('selectOption')->with('OK', true)->times($checked ? 0 : 1); $this->select->shouldReceive('getWrappedElement')->andReturn($web_element); $element = $this->getElement(); $this->assertSame($element, $element->select(true)); }
/** * Selects option if it is not already selected. * * @param boolean $multiple Append this option to current selection. * * @return self * @throws SelectException When no SELECT element association defined. */ public function select($multiple = false) { if (!$this->isSelected()) { if ($this->select === null) { throw new SelectException('No SELECT element association defined', SelectException::TYPE_UNBOUND_OPTION); } $this->select->getWrappedElement()->selectOption($this->getValue(), $multiple); } return $this; }
/** * Create AbstractTypifiedElement from a given NodeElements. * * @param array|NodeElement[] $node_elements Node Elements. * * @return ITypifiedElement * @throws FormException When unable to create typified element. */ public function typify(array $node_elements) { $node_element = $node_elements[0]; $tag_name = $node_element->getTagName(); if ($tag_name == 'input') { $input_type = $node_element->getAttribute('type'); if ($input_type == self::CHECKBOX_INPUT) { return Checkbox::fromNodeElement($node_element, $this->getPageFactory()); } elseif ($input_type == self::RADIO_INPUT) { return RadioGroup::fromNodeElements($node_elements, null, $this->getPageFactory()); } elseif ($input_type == self::FILE_INPUT) { return FileInput::fromNodeElement($node_element, $this->getPageFactory()); } else { /*if ( is_null($input_type) || ($input_type == self::TEXT_INPUT) || ($input_type == self::PASSWORD_INPUT) ) {*/ return TextInput::fromNodeElement($node_element, $this->getPageFactory()); } } elseif ($tag_name == 'select') { return Select::fromNodeElement($node_element, $this->getPageFactory()); } elseif ($tag_name == 'textarea') { return TextInput::fromNodeElement($node_element, $this->getPageFactory()); } $web_element = WebElement::fromNodeElement($node_element, $this->getPageFactory()); throw new FormException('Unable create typified element for ' . (string) $web_element, FormException::TYPE_UNKNOWN_FIELD); }