/** * Returns name of the element. * * @param Property $property Property, to inspect. * * @return string */ protected function getElementName(Property $property) { /* @var $annotations ElementNameAnnotation[] */ $annotations = $property->getAnnotationsFromPropertyOrClass('@element-name'); if ($annotations && $annotations[0] instanceof ElementNameAnnotation) { return $annotations[0]->name; } return (string) $property; }
public function testGetAnnotationsFromPropertyOrClassFallback() { $var_annotation = new VarAnnotation(); $var_annotation->type = 'DT'; $expected = 'OK'; $this->annotationManager->shouldReceive('getPropertyAnnotations')->with($this->property, null, '@var')->once()->andReturn(array($var_annotation)); $this->annotationManager->shouldReceive('getPropertyAnnotations')->with($this->property, null, 'A')->once()->andReturn(array()); $this->annotationManager->shouldReceive('getClassAnnotations')->with('DT', 'A')->once()->andReturn('OK'); $this->assertEquals($expected, $this->property->getAnnotationsFromPropertyOrClass('A')); }
/** * @return WebElementProxy * @dataProvider proxyDataProvider */ public function testProxyWebElement($element_class, $proxy_class) { $search_context = m::mock('\\QATools\\QATools\\PageObject\\ISearchContext'); $this->locator->shouldReceive('getSearchContext')->andReturn($search_context); $node_element = $this->createNodeElement(); $this->locator->shouldReceive('findAll')->andReturn(array($node_element)); $this->property->shouldReceive('isSimpleDataType')->andReturn(false); $this->property->shouldReceive('getDataType')->andReturn($element_class); $proxy = $this->decorator->decorate($this->property); $this->assertProxy($proxy, $proxy_class, $element_class); $this->assertEquals($node_element->getXpath(), $proxy->getXpath()); return $proxy; }
/** * Asserts that required annotations are present. * * @param array $annotations Annotations to test. * * @return void * * @throws AnnotationException Thrown if none or wrong annotations given. */ protected function assertAnnotationClass(array $annotations) { if (!$annotations) { $parameters = array((string) $this->property, $this->property->getDataType()); $message = '@find-by must be specified in the property "%s" DocBlock or in class "%s" DocBlock'; throw new AnnotationException(vsprintf($message, $parameters), AnnotationException::TYPE_REQUIRED); } foreach ($annotations as $annotation) { if (!$annotation instanceof FindByAnnotation) { $parameters = array((string) $this->property, $this->property->getDataType()); $message = '@find-by must be specified in the property "%s" DocBlock or in class "%s" DocBlock'; throw new AnnotationException(vsprintf($message, $parameters), AnnotationException::TYPE_REQUIRED); } } }
/** * @return WebElementProxy * @dataProvider proxyDataProvider */ public function testProxyWebElement($element_class, $proxy_class) { $search_context = m::mock('\\QATools\\QATools\\PageObject\\ISearchContext'); $this->locator->shouldReceive('getSearchContext')->andReturn($search_context); $node_elements = array($this->createNodeElement('xpath1'), $this->createNodeElement('xpath2')); $this->locator->shouldReceive('findAll')->andReturn($node_elements); $this->property->shouldReceive('isSimpleDataType')->andReturn(false); $this->property->shouldReceive('getDataType')->andReturn($element_class); $proxy = $this->decorator->decorate($this->property); $this->assertProxy($proxy, $proxy_class, $element_class); if (strpos($proxy_class, 'Collection') !== false) { foreach ($proxy->getObject() as $index => $proxied_element) { $this->assertEquals($node_elements[$index]->getXpath(), $proxied_element->getXpath(), 'The method call is proxied to collection element.'); } } else { $this->assertEquals($node_elements[0]->getXpath(), $proxy->getXpath(), 'The method call is proxied.'); } return $proxy; }
/** * Checks, that given class is BEM Element or it's descendant. * * @param Property $property Property. * * @return boolean */ private function _isBEMElement(Property $property) { return $this->classMatches($property->getDataType(), $this->_elementInterface); }
/** * Returns proxy class, that can be used alongside with element class of a property. * * @param Property $property Property. * * @return string */ protected function getProxyClass(Property $property) { $data_type = $property->getDataType(); if ($data_type) { foreach ($this->elementToProxyMapping as $element_class => $proxy_class) { if ($this->classMatches($data_type, $element_class)) { return $proxy_class; } } } return ''; }