/** * Prepare components (set classes to nodes etc.) * @param ComponentAbstract $component * @param \simple_html_dom_node $node */ protected function beforeHandle(ComponentAbstract $component, \simple_html_dom_node $node) { $this->attachAngularApp(); if ($class = $component->getOption('class')) { if (is_array($class)) { $class = implode(' ', $class); } elseif (is_callable($class)) { $class = $class(); } if (is_string($class)) { $node->setAttribute('class', $class); } } $id = $component->getOption('id'); if (!$id) { $id = $node->getAttribute('id'); } if (!$id) { $id = $this->getId($node->getAttribute('data-component')); } if ($node->getAttribute('data-component') === 'likeGate') { $node->setAttribute('ng-init', 'likeGateEnabled = 1'); $node->setAttribute('ng-show', 'likeGateEnabled'); $header = $node->find('#likeGate-header', 0); $message = $node->find('#likeGate-message', 0); if ($header) { $header->setAttribute('ng-bind', 'likeGateHeader'); } if ($message) { $message->setAttribute('ng-bind', 'likeGateMessage'); } $node->setAttribute('ng-model', 'pageData.' . $id); } }
/** * Возвращает максимальное числовое значение в ячейках строки * @param \simple_html_dom_node $tr * @return float */ private function findTdWithLargestValue(\simple_html_dom_node $tr) { $floatValues = []; foreach ($tr->find('td') as $td) { if (preg_match("/^[\\s]*([\\d.]+)[\\s]*\$/", $td->innertext, $matches)) { $floatValues[] = (double) $matches[1]; } } return max($floatValues); }
/** * Manipulate node * @param DomNode $node * @return mixed */ public function handleNode(DomNode $node) { if (!$this->isLikeGateEnabled()) { //no need to like gate be showed - remove node $node->outertext = ''; } else { $data = $this->getValue(); $header = $node->find('#likeGate-header', 0); $message = $node->find('#likeGate-message', 0); if (isset($data['header'])) { $header->innertext = $data['header']; } if (isset($data['message'])) { $message->innertext = $data['message']; } if (isset($data['enabled'])) { $node->setAttribute('ng-init', "likeGateEnabled = " . $data['enabled']); } $header->setAttribute('ng-init', "likeGateHeader = '" . $header->innertext . "'"); $message->setAttribute('ng-init', "likeGateMessage = '" . $message->innertext . "'"); } }
/** * @param Listing $listing * @param string $name * @param \simple_html_dom_node $domRow */ protected function parseAmenityByType(Listing $listing, $name, $domRow) { foreach ($domRow->find('div ul li') as $domValue) { /** @var \simple_html_dom_node $domValue */ $value = trim($domValue->text()); if (!empty($value)) { $amenity = new ListingAmenity(); $amenity->setName($name)->setValue($value); $listing->addAmenity($amenity); } } }
/** * @deprecated use selectCheckerA * Look for a particular select input and ensure that: * The selection is what is expected and that the selection control * has the correct quantity of choices. If the control passes, return true, else fail. * * @param \simple_html_dom_node $form the form that contains the select * @param string $selectID the html id of the select of interest * @param string $vvName the name of the view var that contains the into to populate the select * @return boolean */ protected function lookForSelect($form, $selectID, $vvName) { $option = $form->find('select#' . $selectID . ' option[selected]', 0); $this->assertNull($option); $option_cnt = count($form->find('select#' . $selectID . ' option')); $record_cnt = $this->viewVariable($vvName)->count(); $this->assertEquals($record_cnt + 1, $option_cnt); return true; }
protected function parse_charset() { global $debugObject; $charset = null; if (function_exists('get_last_retrieve_url_contents_content_type')) { $contentTypeHeader = get_last_retrieve_url_contents_content_type(); $success = preg_match('/charset=(.+)/', $contentTypeHeader, $matches); if ($success) { $charset = $matches[1]; if (is_object($debugObject)) { $debugObject->debugLog(2, 'header content-type found charset of: ' . $charset); } } } if (empty($charset)) { $el = $this->root->find('meta[http-equiv=Content-Type]', 0); if (!empty($el)) { $fullvalue = $el->content; if (is_object($debugObject)) { $debugObject->debugLog(2, 'meta content-type tag found' . $fullvalue); } if (!empty($fullvalue)) { $success = preg_match('/charset=(.+)/', $fullvalue, $matches); if ($success) { $charset = $matches[1]; } else { // If there is a meta tag, and they don't specify the character set, research says that it's typically ISO-8859-1 if (is_object($debugObject)) { $debugObject->debugLog(2, 'meta content-type tag couldn\'t be parsed. using iso-8859 default.'); } $charset = 'ISO-8859-1'; } } } } // If we couldn't find a charset above, then lets try to detect one based on the text we got... if (empty($charset)) { // Have php try to detect the encoding from the text given to us. $charset = mb_detect_encoding($this->root->plaintext . "ascii", $encoding_list = array("UTF-8", "CP1252")); if (is_object($debugObject)) { $debugObject->debugLog(2, 'mb_detect found: ' . $charset); } // and if this doesn't work... then we need to just wrongheadedly assume it's UTF-8 so that we can move on - cause this will usually give us most of what we need... if ($charset === false) { if (is_object($debugObject)) { $debugObject->debugLog(2, 'since mb_detect failed - using default of utf-8'); } $charset = 'UTF-8'; } } // Since CP1252 is a superset, if we get one of it's subsets, we want it instead. if (strtolower($charset) == strtolower('ISO-8859-1') || strtolower($charset) == strtolower('Latin1') || strtolower($charset) == strtolower('Latin-1')) { if (is_object($debugObject)) { $debugObject->debugLog(2, 'replacing ' . $charset . ' with CP1252 as its a superset'); } $charset = 'CP1252'; } if (is_object($debugObject)) { $debugObject->debugLog(1, 'EXIT - ' . $charset); } return $this->_charset = $charset; }
/** * Process a tag. * @param $tag string * @param \simple_html_dom_node $rootNode * @return void */ protected function processTag($tag, \simple_html_dom_node $rootNode) { $closure = static::$tags[$tag]; foreach ((array) $rootNode->find($tag) as $node) { $closure($node, $this); } }
/** * @param \simple_html_dom_node $item * * @return array * [ * 'text' * 'href' * ] */ private function getTd($item) { $data = ['text' => trim(explode(':', trim($item->plaintext))[1])]; $a = $item->find('a'); if (count($a) > 0) { $href = $a[0]->attr['href']; $href = str_replace('http://yourhumandesign.ru', '', $href); $data['href'] = $href; } return $data; }
public function find($selector, $idx = null, $lowercase = false) { if (preg_match("':([\\w\\-]+)(\\((\\d+)\\))?\$'siu", $selector, $m, PREG_OFFSET_CAPTURE)) { $sPseudo = $m[1][0]; $nNumChild = isset($m[3]) ? $m[3][0] : null; $selector = substr($selector, 0, $m[0][1]); } else { $sPseudo = ''; $nNumChild = null; } if (is_null($idx) and !is_null($nNumChild)) { $idx = $nNumChild; } if ($sPseudo == 'parent') { $aElements = parent::find($selector, $idx, $lowercase); $aNodes = array(); if ($aElements) { foreach ($aElements as $el) { $p = $el->parent(); if ($p) { $aNodes[] = $p; } } } } elseif ($sPseudo == 'eq') { $aNodes = parent::find($selector, $idx, $lowercase); } elseif ($sPseudo == 'nth-child') { $aNodes = parent::find($selector, $idx - 1, $lowercase); } elseif ($sPseudo == 'first') { $aNodes = parent::find($selector, 1, $lowercase); } elseif ($sPseudo == 'last') { $aNodes = parent::find($selector, -1, $lowercase); } else { $aNodes = parent::find($selector, $idx, $lowercase); } return new DomFragSet($this->dom, $aNodes); }
/** * @param \simple_html_dom|\simple_html_dom_node $dom * * @return \simple_html_dom_node[]|\simple_html_dom_node|null */ protected function findListNode($dom) { return $dom->find(implode(', ', static::$listTypes), 0); }
/** * At least three views create a table of TplanElements. * (Tplans.edit, Tplans.view, and TplanElements.index) * This table must be tested. Factor that testing into this method. * @param \simple_html_dom_node $html parsed dom that contains the TplanElementsTable * @param \App\Test\Fixture\TplanElementsFixture $tplan_elementsFixture * @return int $aTagsFoundCnt The number of aTagsFound. */ public function tstTplanElementsTable($html, $tplan_elementsFixture) { // 1. Ensure that there is a suitably named table to display the results. $this->table = $html->find('table#TplanElementsTable', 0); $this->assertNotNull($this->table); // 2. Ensure that said table's thead element contains the correct // headings, in the correct order, and nothing else. $this->thead = $this->table->find('thead', 0); $thead_ths = $this->thead->find('tr th'); $this->assertEquals($thead_ths[0]->id, 'col1'); $this->assertEquals($thead_ths[1]->id, 'col2'); $this->assertEquals($thead_ths[2]->id, 'actions'); $column_count = count($thead_ths); $this->assertEquals($column_count, 3); // no other columns // 3. Ensure that the tbody section has the same // quantity of rows as the count of tplan_elements records in the fixture. $this->tbody = $this->table->find('tbody', 0); $tbody_rows = $this->tbody->find('tr'); $this->assertEquals(count($tbody_rows), count($tplan_elementsFixture->records)); // 4. Ensure that the values displayed in each row, match the values from // the fixture. The values should be presented in a particular order // with nothing else thereafter. $iterator = new \MultipleIterator(); $iterator->attachIterator(new \ArrayIterator($tplan_elementsFixture->records)); $iterator->attachIterator(new \ArrayIterator($tbody_rows)); $aTagsFoundCnt = 0; foreach ($iterator as $values) { $fixtureRecord = $values[0]; $this->htmlRow = $values[1]; $htmlColumns = $this->htmlRow->find('td'); // 4.0 col1 $this->assertEquals($fixtureRecord['col1'], $htmlColumns[0]->plaintext); // 4.1 col2 $this->assertEquals($fixtureRecord['col2'], $htmlColumns[1]->plaintext); // 4.2 Now examine the action links $this->td = $htmlColumns[2]; $actionLinks = $this->td->find('a'); $this->assertEquals('TplanElementView', $actionLinks[0]->name); $aTagsFoundCnt++; $this->assertEquals('TplanElementEdit', $actionLinks[1]->name); $aTagsFoundCnt++; $this->assertEquals('TplanElementDelete', $actionLinks[2]->name); $aTagsFoundCnt++; // 4.9 No other columns $this->assertEquals(count($htmlColumns), $column_count); } return $aTagsFoundCnt; }
/** * At least three views create a table of Clazzes. * (Sections.edit, Sections.view, and Clazzes.index) * This table must be tested. Factor that testing into this method. * @param \simple_html_dom_node $html parsed dom that contains the ClazzesTable * @param \App\Model\Table\ClazzesTable $clazzes * @param \App\Test\Fixture\ClazzesFixture $clazzesFixture * @param \App\Model\Table\SectionsTable $sections * @param int $sectionId If $sectionId=null, the test will expect to see all the records from * the fixture. Else the test will only expect to nersee fixture records with the given $sectionId. * @return int $aTagsFoundCnt The number of aTagsFound. */ public function tstClazzesTable($html, $clazzes, $clazzesFixture, $sections, $section_id = null) { // 1. Ensure that there is a suitably named table to display the results. $this->table = $html->find('table#ClazzesTable', 0); $this->assertNotNull($this->table); // 2. Ensure that said table's thead element contains the correct // headings, in the correct order, and nothing else. $this->thead = $this->table->find('thead', 0); $thead_ths = $this->thead->find('tr th'); $this->assertEquals($thead_ths[0]->id, 'event_datetime'); $this->assertEquals($thead_ths[1]->id, 'comments'); $this->assertEquals($thead_ths[2]->id, 'attend'); $this->assertEquals($thead_ths[3]->id, 'participate'); $this->assertEquals($thead_ths[4]->id, 'actions'); $column_count = count($thead_ths); $this->assertEquals($column_count, 5); // no other columns // 3. Ensure that the tbody section has the correct quantity of rows. // This should be done using a very similar query as used by the controller. $this->tbody = $this->table->find('tbody', 0); $this->tbody_rows = $this->tbody->find('tr'); //if(!is_null($sectionId)) //$clazzesFixture->filterBySectionId($sectionId); //$this->assertEquals(count($tbody_rows), count($clazzesFixture->records)); //$connection = ConnectionManager::get('default'); // This query should be essentially the same as the query in SectionsController.view //$query = "select students.sort, students.sid, students.id as student_id, students.giv_name, students.fam_name, students.phonetic_name, cohorts.id, sections.id, clazzes.id //from students //left join cohorts on students.cohort_id = cohorts.id //left join sections on sections.cohort_id = cohorts.id //left join clazzes on clazzes.section_id = sections.id //left join interactions on interactions.clazz_id=clazzes.id and interactions.student_id=students.id and interactions.itype_id=".ItypesController::ATTEND." where clazzes.id=".$clazz_id. //" order by sort"; //$studentsResults = $connection->execute($query)->fetchAll('assoc'); //$s1=count($this->tbody_rows); //$s2=count($studentsResults); //$this->assertEquals($s1,$s2); // Now get the classes associated with this section $query = $clazzes->find()->order(['event_datetime' => 'asc']); if (!is_null($section_id)) { $query->where(['section_id' => $section_id]); } $q = $query->execute()->fetchAll('assoc'); // 4. Ensure that the values displayed in each row, match the values from // the fixture. The values should be presented in a particular order // with nothing else thereafter. $iterator = new \MultipleIterator(); $iterator->attachIterator(new \ArrayIterator($q)); //$iterator->attachIterator(new \ArrayIterator($clazzesFixture->records)); $iterator->attachIterator(new \ArrayIterator($this->tbody_rows)); $aTagsFoundCnt = 0; foreach ($iterator as $values) { $fixtureRecord = $values[0]; $this->htmlRow = $values[1]; $htmlColumns = $this->htmlRow->find('td'); // 8.0 event_datetime $this->assertEquals($fixtureRecord['Clazzes__event_datetime'], $htmlColumns[0]->plaintext); // 8.1 comments $this->assertEquals($fixtureRecord['Clazzes__comments'], $htmlColumns[1]->plaintext); // 8.2 attend // 8.3 participate // 8.4 Now examine the action links $this->td = $htmlColumns[4]; $actionLinks = $this->td->find('a'); $this->assertEquals('ClazzAttend', $actionLinks[0]->name); $aTagsFoundCnt++; $this->assertEquals('ClazzParticipate', $actionLinks[1]->name); $aTagsFoundCnt++; $this->assertEquals('ClazzView', $actionLinks[2]->name); $aTagsFoundCnt++; $this->assertEquals('ClazzEdit', $actionLinks[3]->name); $aTagsFoundCnt++; $this->assertEquals('ClazzDelete', $actionLinks[4]->name); $aTagsFoundCnt++; // 8.9 No other columns $this->assertEquals(count($htmlColumns), $column_count); } return $aTagsFoundCnt; }