public function testRender() { $view = $this->_createView(); $html = $this->_form->render($view); $document = new \Zend\Dom\Document($html); $this->assertCount(1, \Zend\Dom\Document\Query::execute("//a[@href='/console/preferences/registryvalues/']" . "[text()='\n[Inventarisierte Registry-Werte verwalten]\n']", $document)); }
public function testRender() { $output = $this->_form->render($this->_createView()); $document = new \Zend\Dom\Document($output); $this->assertCount(1, Query::Execute('//input[@type="checkbox"][@name="DeleteInterfaces"]', $document)); $this->assertCount(1, Query::Execute('//input[@type="submit"][@name="yes"]', $document)); $this->assertCount(1, Query::Execute('//input[@type="submit"][@name="no"]', $document)); }
public function testRender() { $view = $this->_createView(); $html = $this->_form->render($view); $document = new \Zend\Dom\Document($html); $this->assertCount(1, \Zend\Dom\Document\Query::execute('//form', $document)); $this->assertContains('document.forms["form_login"]["User"].focus()', $view->placeHolder('BodyOnLoad')); }
public function testSelectOptionsTranslated() { $view = $this->_createView(); $preferences = $this->_form->get('Preferences'); $html = $this->_form->renderFieldset($view, $preferences); $document = new \Zend\Dom\Document($html); $this->assertCount(2, Query::execute('//select[@name="saveFormat"]/option', $document)); $this->assertCount(1, Query::execute('//select[@name="saveFormat"]/option[@value="XML"][text()="XML, unkomprimiert"]', $document)); $this->assertCount(1, Query::execute('//select[@name="saveFormat"]/option[@value="OCS"][text()="XML, zlib-komprimiert"]', $document)); }
public function testRenderFieldset() { $view = $this->_createView(); $html = $this->_form->renderFieldset($view, $this->_form); $document = new \Zend\Dom\Document($html); // Custom rendering of Deploy fieldset - labels are appended instead of prepended $this->assertCount(5, Query::execute('//fieldset//input[@type="checkbox"]/following-sibling::span', $document)); // Assert that other elements are rendered $this->assertCount(1, Query::execute('//input[@name="Name"]', $document)); }
/** * Tests for the __invoke() method */ public function testInvoke() { $helper = $this->_getHelper(); $result = $helper('TestCaption', array('hiddenName' => 'hiddenValue')); $document = new \Zend\Dom\Document($result); $this->assertCount(1, Query::execute('//p[text()="TestCaption"]', $document)); $this->assertCount(1, Query::execute('//form[@action=""][@method="POST"]', $document)); $this->assertCount(1, Query::execute('//input[@type="hidden"][@name="hiddenName"][@value="hiddenValue"]', $document)); $this->assertCount(1, Query::execute('//input[@type="submit"][@name="yes"][@value="Ja"]', $document)); $this->assertCount(1, Query::execute('//input[@type="submit"][@name="no"][@value="Nein"]', $document)); }
public function testRenderFieldsetWithPackages() { $this->_form->setPackages(array('package1', 'package2')); $view = $this->_createView(); $html = $this->_form->renderFieldset($view, $this->_form); $document = new \Zend\Dom\Document($html); $this->assertCount(1, Query::execute('//div[@class="table"]', $document)); $this->assertCount(1, Query::execute('//*[text()="package1"]', $document)); $this->assertCount(1, Query::execute('//input[@type="checkbox"][@name="package1"]', $document)); $this->assertCount(1, Query::execute('//*[text()="package2"]', $document)); $this->assertCount(1, Query::execute('//input[@type="checkbox"][@name="package2"]', $document)); $this->assertCount(1, Query::execute('//input[@type="submit"]', $document)); }
public function execute() { $payload = $this->getContent(); echo "processing >> " . $payload['page_url'] . " >> for id >> " . $payload['page_id'] . "\n"; /* @var \Application\V1\Entity\Pages $pageEntity */ $pageEntity = $this->entityManager->find('Application\\V1\\Entity\\Pages', $payload['page_id']); try { $this->httpClient->setUri($payload['page_url']); $response = $this->httpClient->send(); $document = new Document($response->getBody()); $manager = $this->grabImageQueue->getJobPluginManager(); $jobs = []; $parsedPageUrl = parse_url($this->httpClient->getRequest()->getUriString()); $cnt = 0; /* @var \DOMElement $node */ foreach ($this->documentQuery->execute('//body//img', $document) as $node) { $job = $manager->get('Application\\QueueJob\\GrabImage'); $src = $this->normalizeSchemeAndHost($node->getAttribute('src'), $parsedPageUrl['scheme'], $parsedPageUrl['host']); $ext = strtolower(pathinfo($src, PATHINFO_EXTENSION)); $job->setContent(['image_src' => $src, 'image_ext' => $ext, 'page_id' => $payload['page_id']]); $jobs[] = $job; $cnt++; } if ($cnt < 1) { $pageEntity->setStatus(PageInterface::STATUS_DONE); } else { $pageEntity->setStatus(PageInterface::STATUS_RUNNING); } $pageEntity->setPendingImagesCnt($cnt); $pageEntity->setTotalImagesCnt($cnt); $this->entityManager->flush(); foreach ($jobs as $job) { $this->grabImageQueue->push($job); } echo "Jobs to push >> " . count($jobs) . " count pending images >>" . $cnt . "\n"; } catch (\Exception $e) { echo 'Exception: >> ' . $e->getMessage(); $pageEntity->setErrorMessage($e->getMessage()); if ($pageEntity->getStatusNumeric() == PageInterface::STATUS_RECOVERING) { $pageEntity->setStatus(PageInterface::STATUS_ERROR); $this->entityManager->flush(); return WorkerEvent::JOB_STATUS_FAILURE; } else { $pageEntity->setStatus(PageInterface::STATUS_RECOVERING); $this->entityManager->flush(); throw new ReleasableException(array('priority' => 10, 'delay' => 15)); } } }
/** * Tests for the __invoke() method */ public function testInvoke() { $translate = $this->createMock('Zend\\I18n\\View\\Helper\\Translate'); $translate->method('__invoke')->willReturnCallback(function ($message) { return "_({$message})"; }); $htmlElement = $this->createMock('Library\\View\\Helper\\HtmlElement'); $htmlElement->expects($this->once())->method('__invoke')->with('input', null, array('type' => 'hidden', 'name' => 'hiddenName', 'value' => 'hiddenValue'))->willReturn('<input type="hidden" name="hiddenName" value="hiddenValue">'); $helper = new \Library\View\Helper\FormYesNo($translate, $htmlElement); $result = $helper('TestCaption', array('hiddenName' => 'hiddenValue')); $document = new \Zend\Dom\Document($result); $this->assertCount(1, Query::execute('//p[text()="TestCaption"]', $document)); $this->assertCount(1, Query::execute('//form[@action=""][@method="POST"]', $document)); $this->assertCount(1, Query::execute('//input[@type="hidden"][@name="hiddenName"][@value="hiddenValue"]', $document)); $this->assertCount(1, Query::execute('//input[@type="submit"][@name="yes"][@value="_(Yes)"]', $document)); $this->assertCount(1, Query::execute('//input[@type="submit"][@name="no"][@value="_(No)"]', $document)); }
/** * Get email's list * * @param $email * @param $password * * @return string */ public function getEmailList($email, $password) { $client = new HttpClient(); $client->setAdapter(\Zend\Http\Client\Adapter\Curl::class); $config = $this->setCurlOpt([CURLOPT_CONNECTTIMEOUT => 30, CURLOPT_USERAGENT => (new PhpEnvironment())->getServer('HTTP_USER_AGENT'), CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_CONNECTTIMEOUT => 120, CURLOPT_TIMEOUT => 120]); $client->setOptions($config); $client->setUri('https://accounts.google.com/ServiceLogin'); $data = $client->send(); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// $formFields = $this->getFormFields($data); $formFields['Email'] = $email; $formFields['Passwd'] = $password; unset($formFields['PersistentCookie']); $postString = ''; foreach ($formFields as $key => $value) { $postString .= $key . '=' . urlencode($value) . '&'; } $postString = substr($postString, 0, -1); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// $config = $this->setCurlOpt([CURLOPT_POST => 1, CURLOPT_REFERER => 'https://mail.google.com/', CURLOPT_POSTFIELDS => $postString]); $client->setOptions($config); $client->setUri('https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2'); $client->send(); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// $config = $this->setCurlOpt([CURLOPT_POST => 0, CURLOPT_POSTFIELDS => null]); $client->setOptions($config); $client->setUri('https://mail.google.com/mail/h/jeu23doknfnj/?zy=e&f=1'); $html = $client->send(); $body = $html->getBody(); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// $document = new Document($body); $nodeList = Query::execute('table.th tr td', $document, Query::TYPE_CSS); $result = []; foreach ($nodeList as $node) { $nodeValue = trim(str_replace(' ', '', htmlentities($node->nodeValue))); if (empty($nodeValue)) { continue; } $result[] = $nodeValue; } return array_chunk($result, 3); }
/** * @group ZF-5310 */ public function testCanTransformWithAttributeAndDot() { $test = Query::cssToXpath('a[href="http://example.com"]'); $this->assertEquals("//a[@href='http://example.com']", $test); $test = Query::cssToXpath('a[@href="http://example.com"]'); $this->assertEquals("//a[@href='http://example.com']", $test); }
/** * @expectedException Zend\Dom\Exception\BadMethodCallException */ public function testOffsetUnset() { $this->loadHtml(); $result = Document\Query::execute('input', $this->document, Document\Query::TYPE_CSS); $this->assertEquals(3, $result->count()); unset($result[2]); }
public function testRenderFieldsetWithGroups() { $this->_form->setGroups(array('group1', 'group2')); $this->_form->prepare(); $view = $this->_createView(); $html = $this->_form->renderFieldset($view, $this->_form); $document = new \Zend\Dom\Document($html); $this->assertCount(1, Query::execute('//div', $document)); $this->assertCount(1, Query::execute("//fieldset/legend/a[@href='/console/group/general/?name=group1'][text()='\ngroup1\n']", $document)); $this->assertCount(1, Query::execute('//input[@type="radio"][@name="Groups[group1]"][@value="0"]', $document)); $this->assertCount(1, Query::execute('//input[@type="radio"][@name="Groups[group1]"][@value="1"]', $document)); $this->assertCount(1, Query::execute('//input[@type="radio"][@name="Groups[group1]"][@value="2"]', $document)); $this->assertCount(1, Query::execute("//fieldset/legend/a[@href='/console/group/general/?name=group2'][text()='\ngroup2\n']", $document)); $this->assertCount(1, Query::execute('//input[@type="radio"][@name="Groups[group2]"][@value="0"]', $document)); $this->assertCount(1, Query::execute('//input[@type="radio"][@name="Groups[group2]"][@value="1"]', $document)); $this->assertCount(1, Query::execute('//input[@type="radio"][@name="Groups[group2]"][@value="2"]', $document)); $this->assertCount(1, Query::execute('//input[@type="submit"]', $document)); }
public function testRenderNoExistingValues() { $this->_registryManager = $this->createMock('Model\\Registry\\RegistryManager'); $this->_registryManager->expects($this->once())->method('getValueDefinitions')->willReturn(new \ArrayIterator()); $document = new \Zend\Dom\Document($this->_getForm()->render($this->_createView())); $result = Query::execute("//h2[text()='\nWerte\n']", $document); $this->assertCount(0, $result); $result = Query::execute('//tr', $document); $this->assertCount(0, $result); // Other fieldsets must exist $result = Query::execute('//input[@name="inspect[inspect]"][@type="checkbox"]', $document); $this->assertCount(1, $result); $result = Query::execute('//input[@name="new_value[name]"]', $document); $this->assertCount(1, $result); }
public function testRender() { $this->_form->get('NewGroup')->setMessages(array('message')); $view = $this->_createView(); $html = $this->_form->render($view); $this->assertContains('function selectElements()', $view->headScript()->toString()); $this->assertContains('selectElements()', $view->placeholder('BodyOnLoad')->getValue()); $document = new \Zend\Dom\Document($html); $this->assertCount(1, Query::execute('//legend//*[text()="What to save"]', $document)); $this->assertCount(3, Query::execute('//input[@type="radio"][@name="What"]', $document)); $this->assertCount(1, Query::execute('//legend//*[text()="Where to save"]', $document)); $this->assertCount(2, Query::execute('//input[@type="radio"][@name="Where"]', $document)); $this->assertCount(1, Query::execute('//input[@type="text"][@name="NewGroup"][@class="input-error"]', $document)); $this->assertCount(1, Query::execute('//input[@type="text"][@name="Description"]', $document)); $this->assertCount(1, Query::execute('//select[@name="ExistingGroup"]', $document)); $this->assertCount(1, Query::execute('//input[@type="submit"]', $document)); $this->assertCount(1, Query::execute('//ul[@class="error"]/li[text()="message"]', $document)); }
/** * Get product statuses * * @param Query $query Query * @param Document $document Document * @param integer $productRowSelector Product row selector * * @return array */ protected function _getProductStatuses(Query $query, Document $document, $productRowSelector) { $statuses = []; $result = $query->execute($productRowSelector . ' ' . $this->_cssSelectors['product_page']['in_stock'], $document, Query::TYPE_CSS); $statuses['in_stock'] = boolval($result->count()); $result = $query->execute($productRowSelector . ' ' . $this->_cssSelectors['product_page']['out_stock'], $document, Query::TYPE_CSS); $statuses['out_stock'] = boolval($result->count()); $result = $query->execute($productRowSelector . ' ' . $this->_cssSelectors['product_page']['limited'], $document, Query::TYPE_CSS); $statuses['limited'] = boolval($result->count()); return $statuses; }
/** * Execute a DOM/XPath query * * @param string $path * @param bool $useXpath * @return Document\NodeList */ private function query($path, $useXpath = false) { $response = $this->getResponse(); $document = new Document($response->getContent()); if ($useXpath) { $document->registerXpathNamespaces($this->xpathNamespaces); } $result = Document\Query::execute($path, $document, $useXpath ? Document\Query::TYPE_XPATH : Document\Query::TYPE_CSS); return $result; }
/** * Tests for render() */ public function testRender() { $now = new \DateTime(); $clients = array(array('Id' => 1, 'Name' => 'Test1', 'NetworkInterface.MacAddress' => '00:00:5E:00:53:00', 'Serial' => '12345678', 'AssetTag' => 'abc', 'LastContactDate' => $now), array('Id' => 2, 'Name' => 'Test2', 'NetworkInterface.MacAddress' => '00:00:5E:00:53:00', 'Serial' => '12345678', 'AssetTag' => null, 'LastContactDate' => $now)); $this->_form->setOptions(array('clients' => $clients, 'order' => 'Id', 'direction' => 'asc')); $output = $this->_form->render($this->_createView()); // Test table content $document = new \Zend\Dom\Document($output); $result = Query::execute('//td//a[@href="/console/client/customfields/?id=2"]', $document); $this->assertCount(1, $result); $this->assertEquals('Test2', $result[0]->nodeValue); $result = Query::execute('//td//a[@href="/console/duplicates/allow/?criteria=MacAddress&value=00:00:5E:00:53:00"]', $document); $this->assertCount(2, $result); $this->assertEquals('00:00:5E:00:53:00', $result[0]->nodeValue); $result = Query::execute('//td//a[@href="/console/duplicates/allow/?criteria=Serial&value=12345678"]', $document); $this->assertCount(2, $result); $this->assertEquals('12345678', $result[0]->nodeValue); $result = Query::execute('//td//a[@href="/console/duplicates/allow/?criteria=AssetTag&value=abc"]', $document); $this->assertCount(1, $result); $this->assertEquals('abc', $result[0]->nodeValue); // 1 Empty cell resulting from NULL value $result = Query::execute('//td[not(node())]', $document); $this->assertCount(1, $result); // Test state of the 3 merge option checkboxes (depending on \Model\Config mock) $result = Query::execute('//input[@name="mergeCustomFields"][@checked="checked"]', $document); $this->assertCount(1, $result); $result = Query::execute('//input[@name="mergeGroups"][@checked="checked"]', $document); $this->assertCount(1, $result); // This should be unchecked. Test for presence first, excluding "hidden" // element with same name, then confirm that it's not checked. $result = Query::execute('//input[@type="checkbox"][@name="mergePackages"][not(@checked)]', $document); $this->assertCount(1, $result); }
public function testRenderFieldsetForm() { $this->_form->setClientObject($this->_group); $this->_form->prepare(); $view = $this->_createView(); $html = $this->_form->renderFieldset($view, $this->_form); $document = new \Zend\Dom\Document($html); $this->assertCount(3, Query::execute('//div[@class="table"]/fieldset', $document)); $this->assertCount(1, Query::execute("//fieldset[1]/legend[text()='\nAgent\n']", $document)); $this->assertCount(1, Query::execute("//fieldset[2]/legend[text()='\nDownload\n']", $document)); $this->assertCount(1, Query::execute("//fieldset[3]/legend[text()='\nNetzwerk-Scans\n']", $document)); $this->assertCount(1, Query::execute('//div[@class="table"]/input[@type="submit"]', $document)); }
public function testRender() { $view = $this->_createView(); $document = new \Zend\Dom\Document($this->_form->render($view)); $result = Query::execute('//select[@name="filter"][@onchange="filterChanged();"]', $document); $this->assertCount(1, $result); $result = Query::execute('//input[@name="search"][@type="text"]', $document); $this->assertCount(1, $result); $result = Query::execute('//select[@name="operator"]', $document); $this->assertCount(1, $result); $result = Query::execute('//input[@name="invert"][@type="checkbox"]', $document); $this->assertCount(1, $result); $result = Query::execute('//input[@name="customSearch"][@type="submit"]', $document); $this->assertCount(1, $result); $headScript = $view->headScript()->toString(); $this->assertContains('function filterChanged(', $headScript); $this->assertContains('filterChanged()', $view->placeholder('BodyOnLoad')->getValue()); }
/** * Execute a DOM query * * @param string $path * @return Document\NodeList */ private function query($path) { if (!$this->document) { $this->document = new Document(Response::getBody()); } return Document\Query::execute($path, $this->document, Document\Query::TYPE_CSS); }
/** * Tests for render() */ public function testRender() { $this->_form->get('existing')->get('value_1_name')->setMessages(array('test' => 'Message1')); $this->_form->get('new_value')->get('subkeys')->setMessages(array('test' => 'Message2')); $document = new \Zend\Dom\Document($this->_form->render($this->_createView())); // Test state of inspect checkbox $result = Query::execute('//input[@name="inspect[inspect]"][@checked="checked"]', $document); $this->assertCount(1, $result); // Test table with existing values $result = Query::execute('//tr', $document); $this->assertCount(2, $result); $result = Query::execute('//td//input[@name="existing[value_1_name]"][@value="Test1"]', $document); $this->assertCount(1, $result); $result = Query::execute('//td', $document); $this->assertEquals("\na\\b\\c\n", $result[1]->textContent); $result = Query::execute('//td//a[@href="/console/preferences/deleteregistryvalue/?id=1"]', $document); $this->assertCount(1, $result); // Test elements for new value $result = Query::execute('//input[@name="new_value[name]"]', $document); $this->assertCount(1, $result); $result = Query::execute('//select[@name="new_value[root_key]"]', $document); $this->assertCount(1, $result); $result = Query::execute('//input[@name="new_value[subkeys]"]', $document); $this->assertCount(1, $result); $result = Query::execute('//input[@name="new_value[value]"]', $document); $this->assertCount(1, $result); // Test submit button $result = Query::execute('//input[@type="submit"]', $document); $this->assertCount(1, $result); // Test message rendering $result = Query::execute('//ul[@class="errors"]/li', $document); $this->assertCount(2, $result); $this->assertEquals("Message1", $result[0]->textContent); $this->assertEquals("Message2", $result[1]->textContent); }
public function testRenderFieldset() { $html = $this->_form->renderFieldset($this->_createView(), $this->_form); $document = new \Zend\Dom\Document($html); $this->assertCount(4, Query::execute('//input[@type="text"]', $document)); $this->assertCount(1, Query::execute('//textarea', $document)); $this->assertCount(1, Query::execute('//input[@type="submit"]', $document)); // Check for manual translation $this->assertCount(1, Query::execute('//label/span[text()="Kategorie"]', $document)); }
/** * Perform a CSS selector query * * @param string $query * @param DOMNode $contextNode * @return NodeList */ public function execute($query, DOMNode $contextNode = null) { $xpathQuery = Document\Query::cssToXpath($query); return $this->queryXpath($xpathQuery, $query, $contextNode); }
public function testMenu() { $this->_authService->method('hasIdentity')->willReturn(true); $this->_authService->method('getIdentity')->willReturn('identity'); $this->_view->plugin('navigation')->menu()->setTranslator(null); $menu = \Zend\Navigation\Page\AbstractPage::factory(array('type' => 'uri', 'pages' => array(array('label' => 'main', 'uri' => 'mainUri', 'active' => true, 'pages' => array(array('label' => 'sub', 'uri' => 'subUri', 'active' => true)))))); $html = $this->_view->render('layout', array('menu' => $menu)); $document = new \Zend\Dom\Document($html); $this->assertCount(1, Query::execute('/html/body/div[@id="menu"]/ul[@class="navigation"]/li/a[@href="mainUri"]', $document)); $this->assertCount(1, Query::execute('/html/body/div[@id="menu"]/ul[@class="navigation navigation_sub"]/li/a[@href="subUri"]', $document)); $this->assertCount(1, Query::execute("/html/body/div[@id='menu']/div[@id='logout']/a[@href='/console/login/logout/'][text()='\nAbmelden\n']", $document)); }
public function testEnctypeAttribute() { $html = $this->_form->render($this->_createView()); $document = new \Zend\Dom\Document($html); $this->assertCount(1, \Zend\Dom\Document\Query::execute('//form[@enctype="multipart/form-data"]', $document)); }
public function testRenderFieldsetMessages() { $this->_form->get('Types')->get('name0')->setMessages(array('message_name0')); $this->_form->get('Add')->setMessages(array('message_add')); $html = $this->_form->renderFieldset($this->_createView(), $this->_form); $document = new \Zend\Dom\Document($html); $this->assertCount(1, Query::execute('//input[@name="name0"]/following::ul[1][@class="error"]/li[text()="message_name0"]', $document)); $this->assertCount(1, Query::execute('//input[@name="Add"]/following::ul[1][@class="error"]/li[text()="message_add"]', $document)); $this->assertCount(2, Query::execute('//input[@class="input-error"]', $document)); $this->assertCount(2, Query::execute('//ul', $document)); }
/** * Perform a CSS selector query * * @param string $query * @return NodeList */ public function execute($query) { $xpathQuery = Document\Query::cssToXpath($query); return $this->queryXpath($xpathQuery, $query); }