foo <ul class="radio_list"><li><input name="foo" type="radio" value="foo" id="foo_foo" checked="checked" /> <label for="foo_foo">bar</label></li> <li><input name="foo" type="radio" value="bar" id="foo_bar" /> <label for="foo_bar">foo</label></li></ul> bar <ul class="radio_list"><li><input name="foo" type="radio" value="foobar" id="foo_foobar" /> <label for="foo_foobar">barfoo</label></li></ul> EOF; $t->is($w->render('foo', 'foo'), fix_linebreaks($output), '->render() has support for groups'); try { $w = new sfWidgetFormSelectRadio(); $t->fail('__construct() throws an RuntimeException if you don\'t pass a choices option'); } catch (RuntimeException $e) { $t->pass('__construct() throws an RuntimeException if you don\'t pass a choices option'); } // choices as a callable $t->diag('choices as a callable'); function choice_callable() { return array(1, 2, 3); } $w = new sfWidgetFormSelectRadio(array('choices' => new sfCallable('choice_callable'))); $dom->loadHTML($w->render('foo')); $css = new sfDomCssSelector($dom); $t->is(count($css->matchAll('input[type="radio"]')->getNodes()), 3, '->render() accepts a sfCallable as a choices option'); // __clone() $t->diag('__clone()'); $w = new sfWidgetFormSelectRadio(array('choices' => new sfCallable(array($w, 'foo')))); $w1 = clone $w; $callable = $w1->getOption('choices')->getCallable(); $t->is(spl_object_hash($callable[0]), spl_object_hash($w1), '__clone() changes the choices is a callable and the object is an instance of the current object'); $w = new sfWidgetFormSelectRadio(array('choices' => new sfCallable(array($a = new stdClass(), 'foo')))); $w1 = clone $w; $callable = $w1->getOption('choices')->getCallable(); $t->is(spl_object_hash($callable[0]), spl_object_hash($a), '__clone() changes nothing if the choices is a callable and the object is not an instance of the current object');
require_once dirname(__FILE__) . '/../../../bootstrap/unit.php'; $t = new lime_test(6, new lime_output_color()); $dom = new DomDocument('1.0', 'utf-8'); $dom->validateOnParse = true; // ->configure() $t->diag('->configure()'); try { new sfWidgetFormI18nSelectLanguage(array('culture' => 'en', 'languages' => array('xx'))); $t->fail('->configure() throws an InvalidArgumentException if a language does not exist'); } catch (InvalidArgumentException $e) { $t->pass('->configure() throws an InvalidArgumentException if a language does not exist'); } $v = new sfWidgetFormI18nSelectLanguage(array('culture' => 'en', 'languages' => array('fr', 'en'))); $t->is(array_keys($v->getOption('choices')), array('en', 'fr'), '->configure() can restrict the number of languages with the languages option'); // ->render() $t->diag('->render()'); $w = new sfWidgetFormI18nSelectLanguage(array('culture' => 'fr')); $dom->loadHTML($w->render('language', 'en')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#language option[value="en"]')->getValue(), 'anglais', '->render() renders all languages as option tags'); $t->is(count($css->matchAll('#language option[value="en"][selected="selected"]')->getNodes()), 1, '->render() renders all languages as option tags'); // add_empty $t->diag('add_empty'); $w = new sfWidgetFormI18nSelectLanguage(array('culture' => 'fr', 'add_empty' => true)); $dom->loadHTML($w->render('language', 'FR')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#language option[value=""]')->getValue(), '', '->render() renders an empty option if add_empty is true'); $w = new sfWidgetFormI18nSelectLanguage(array('culture' => 'fr', 'add_empty' => 'foo')); $dom->loadHTML($w->render('language', 'FR')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#language option[value=""]')->getValue(), 'foo', '->render() renders an empty option if add_empty is true');
$css = new sfDomCssSelector($dom); $t->is(count($css->matchAll('#foo_hour option')->getNodes()), 5, '__construct() can change the default array used for hours'); $t->is(count($css->matchAll('#foo_minute option')->getNodes()), 3, '__construct() can change the default array used for minutes'); $t->is(count($css->matchAll('#foo_second option')->getNodes()), 4, '__construct() can change the default array used for seconds'); // with_seconds option $t->diag('with_seconds option'); $w->setOption('with_seconds', false); $dom->loadHTML($w->render('foo', '12:30:35')); $css = new sfDomCssSelector($dom); $t->is(count($css->matchAll('#foo_second option')->getNodes()), 0, '__construct() can enable or disable the seconds select box with the with_seconds option'); $w->setOption('format_without_seconds', '%hour%#%minute%'); $dom->loadHTML($w->render('foo', '12:30:35')); $css = new sfDomCssSelector($dom); $t->like($css->matchSingle('#foo_hour')->getNode()->nextSibling->nodeValue, '/^#/', '__construct() can change the default format'); $t->ok(!count($css->matchSingle('#foo_second')->getNodes()), '__construct() can change the default format'); // attributes $t->diag('attributes'); $w->setOption('with_seconds', true); $dom->loadHTML($w->render('foo', '12:30:35', array('disabled' => 'disabled'))); $t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 3, '->render() takes the attributes into account for all the three embedded widgets'); $w->setAttribute('disabled', 'disabled'); $dom->loadHTML($w->render('foo', '12:30:35')); $t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 3, '->render() takes the attributes into account for all the three embedded widgets'); // id_format $t->diag('id_format'); $w->setOption('with_seconds', true); $w->setIdFormat('id_%s'); $dom->loadHTML($w->render('foo')); $t->is(count($css->matchAll('#id_foo_hour')), 1, '->render() uses id_format for hour'); $t->is(count($css->matchAll('#id_foo_minute')), 1, '->render() uses id_format for minute'); $t->is(count($css->matchAll('#id_foo_second')), 1, '->render() uses id_format for second');
<?php /* * This file is part of the symfony package. * (c) Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once __DIR__ . '/../../../bootstrap/unit.php'; $t = new lime_test(4); $dom = new DomDocument('1.0', 'utf-8'); $dom->validateOnParse = true; // ->render() $t->diag('->render()'); $w = new sfWidgetFormI18nChoiceTimezone(); $dom->loadHTML($w->render('timezone', 'Europe/Paris')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#timezone option[value="Europe/Paris"]')->getValue(), 'Europe/Paris', '->render() renders all timezones as option tags'); $t->is(count($css->matchAll('#timezone option[value="Europe/Paris"][selected="selected"]')->getNodes()), 1, '->render() renders all timezones as option tags'); // add_empty $t->diag('add_empty'); $w = new sfWidgetFormI18nChoiceTimezone(array('culture' => 'fr', 'add_empty' => true)); $dom->loadHTML($w->render('language', 'FR')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#language option[value=""]')->getValue(), '', '->render() renders an empty option if add_empty is true'); $w = new sfWidgetFormI18nChoiceTimezone(array('culture' => 'fr', 'add_empty' => 'foo')); $dom->loadHTML($w->render('language', 'FR')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#language option[value=""]')->getValue(), 'foo', '->render() renders an empty option if add_empty is true');
require_once dirname(__FILE__) . '/../../../bootstrap/unit.php'; $t = new lime_test(6); $dom = new DomDocument('1.0', 'utf-8'); $dom->validateOnParse = true; // ->configure() $t->diag('->configure()'); try { new sfWidgetFormI18nSelectCurrency(array('culture' => 'en', 'currencies' => array('xx'))); $t->fail('->configure() throws an InvalidArgumentException if a currency does not exist'); } catch (InvalidArgumentException $e) { $t->pass('->configure() throws an InvalidArgumentException if a currency does not exist'); } $v = new sfWidgetFormI18nSelectCurrency(array('culture' => 'en', 'currencies' => array('EUR', 'USD'))); $t->is(array_keys($v->getOption('choices')), array('EUR', 'USD'), '->configure() can restrict the number of currencies with the currencies option'); // ->render() $t->diag('->render()'); $w = new sfWidgetFormI18nSelectCurrency(array('culture' => 'fr')); $dom->loadHTML($w->render('currency', 'EUR')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#currency option[value="EUR"]')->getValue(), 'euro', '->render() renders all currencies as option tags'); $t->is(count($css->matchAll('#currency option[value="EUR"][selected="selected"]')->getNodes()), 1, '->render() renders all currencies as option tags'); // add_empty $t->diag('add_empty'); $w = new sfWidgetFormI18nSelectCurrency(array('culture' => 'fr', 'add_empty' => true)); $dom->loadHTML($w->render('currency', 'EUR')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#currency option[value=""]')->getValue(), '', '->render() renders an empty option if add_empty is true'); $w = new sfWidgetFormI18nSelectCurrency(array('culture' => 'fr', 'add_empty' => 'foo')); $dom->loadHTML($w->render('currency', 'EUR')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#currency option[value=""]')->getValue(), 'foo', '->render() renders an empty option if add_empty is true');
$dom->loadHTML($w->render('foo', $year . '-10-15')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#foo_day')->getNode()->nextSibling->nodeValue, '#', '__construct() can change the default date format'); $t->like($css->matchSingle('#foo_month')->getNode()->nextSibling->nodeValue, '/^#/', '__construct() can change the default date format'); $w->setOption('format', '%day%/%month%/%year%'); $dom->loadHTML($w->render('foo', $year . '-10-15')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('select')->getNode()->getAttribute('name'), 'foo[day]', '__construct() can change the default date format'); // days / months / years options $t->diag('days / months / years options'); $w->setOption('years', array(1998 => 1998, 1999 => 1999, 2000 => 2000, 2001 => 2001)); $w->setOption('months', array(1 => 1, 2 => 2, 3 => 3)); $w->setOption('days', array(1 => 1, 2 => 2)); $dom->loadHTML($w->render('foo', $year . '-10-15')); $css = new sfDomCssSelector($dom); $t->is(count($css->matchAll('#foo_year option')->getNodes()), 5, '__construct() can change the default array used for years'); $t->is(count($css->matchAll('#foo_month option')->getNodes()), 4, '__construct() can change the default array used for months'); $t->is(count($css->matchAll('#foo_day option')->getNodes()), 3, '__construct() can change the default array used for days'); // attributes $t->diag('attributes'); $dom->loadHTML($w->render('foo', $year . '-10-15', array('disabled' => 'disabled'))); $t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 3, '->render() takes the attributes into account for all the three embedded widgets'); $w->setAttribute('disabled', 'disabled'); $dom->loadHTML($w->render('foo', $year . '-10-15')); $t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 3, '->render() takes the attributes into account for all the three embedded widgets'); // id_format $t->diag('id_format'); $w->setIdFormat('id_%s'); $dom->loadHTML($w->render('foo')); $t->is(count($css->matchAll('#id_foo_day')), 1, '->render() uses the id_format'); $t->is(count($css->matchAll('#id_foo_month')), 1, '->render() uses the id_format');
$t->diag('choices as a callable'); function choice_callable() { return array(1, 2, 3); } $w = new sfWidgetFormSelect(array('choices' => new sfCallable('choice_callable'))); $dom->loadHTML($w->render('foo')); $css = new sfDomCssSelector($dom); $t->is(count($css->matchAll('#foo option')->getNodes()), 3, '->render() accepts a sfCallable as a choices option'); // attributes $t->diag('attributes'); $w = new sfWidgetFormSelect(array('choices' => array(0, 1, 2))); $dom->loadHTML($w->render('foo', null, array('disabled' => 'disabled'))); $css = new sfDomCssSelector($dom); $t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 1, '->render() does not pass the select HTML attributes to the option tag'); $t->is(count($css->matchAll('option[disabled="disabled"]')->getNodes()), 0, '->render() does not pass the select HTML attributes to the option tag'); $w = new sfWidgetFormSelect(array('choices' => array(0, 1, 2)), array('disabled' => 'disabled')); $dom->loadHTML($w->render('foo')); $css = new sfDomCssSelector($dom); $t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 1, '->render() does not pass the select HTML attributes to the option tag'); $t->is(count($css->matchAll('option[disabled="disabled"]')->getNodes()), 0, '->render() does not pass the select HTML attributes to the option tag'); // __clone() $t->diag('__clone()'); $w = new sfWidgetFormSelect(array('choices' => new sfCallable(array($w, 'foo')))); $w1 = clone $w; $callable = $w1->getOption('choices')->getCallable(); $t->is(spl_object_hash($callable[0]), spl_object_hash($w1), '__clone() changes the choices is a callable and the object is an instance of the current object'); $w = new sfWidgetFormSelect(array('choices' => new sfCallable(array($a = new stdClass(), 'foo')))); $w1 = clone $w; $callable = $w1->getOption('choices')->getCallable(); $t->is(spl_object_hash($callable[0]), spl_object_hash($a), '__clone() changes nothing if the choices is a callable and the object is not an instance of the current object');
public function getForm4Urls() { //to check out the page, an example url: http://searchwww.sec.gov/EDGARFSClient/jsp/EDGAR_Query_Result.jsp?queryString=&queryForm=Form4&isAdv=1&queryCik=876437&numResults=100#topAnchor $types = array('Form3', 'Form4'); $form4_urls = array(); $unique_ciks = array(); foreach ($types as $type) { $search_pages = 0; $next_page = true; $url = 'http://searchwww.sec.gov/EDGARFSClient/jsp/EDGAR_MainAccess.jsp?search_text=*&sort=Date&formType=' . $type . '&isAdv=true&stemming=true&numResults=100&queryCik=' . $this->entity->sec_cik . '&fromDate=01/01/' . strval($this->years[0]) . '&toDate=01/01/' . strval($this->years[count($this->years) - 1] + 1); $this->printDebug("Form 3/4 search url: " . $url); //loop through search results while ($next_page == true && $search_pages < $this->search_depth) { if (!$this->browser->get($url)->responseIsError()) { $selector = $this->browser->getResponseDomCssSelector(); $text = $this->browser->getResponseText(); $rows = $selector->matchAll('tr')->getNodes(); for ($i = 0; $i < count($rows); $i++) { $row = new sfDomCssSelector(array($rows[$i])); $links = $row->matchAll('a')->getNodes(); $person_cik = null; foreach ($links as $link) { if ($link->getAttribute('name') == 'cikSearch') { $cik = trim($link->textContent); //break if it's the same as corp's cik if ($cik != $this->entity->sec_cik) { $person_cik = $cik; break; } } } if (!$person_cik) { continue; } if (!in_array($person_cik, $unique_ciks)) { $prev_row = new sfDomCssSelector($rows[$i - 1]); if (!is_object($href = $prev_row->matchSingle('a')->getNode())) { continue; } $href = $href->getAttribute('href'); //if not an xml doc, grab the parent filing underneath the listing if (!stripos($href, '.xml')) { $next_row = new sfDomCssSelector($rows[$i + 2]); if (!is_object($href = $next_row->matchSingle('a')->getNode())) { continue; } if (trim($href->getAttribute('title')) == 'Parent Filing') { $href = $href->getAttribute('href'); } else { continue; } } if (preg_match("/\\'([^\\']+)\\'/", $href, $matches)) { $unique_ciks[] = $person_cik; $u = str_replace('xslF345/', '', $matches[1]); if ($u != $matches[1]) { $form4_urls[] = array('xmlUrl' => $u, 'htmlUrl' => $matches[1], 'readableXmlUrl' => preg_replace('/[^\\/]+\\.xml/i', 'xslF345X03/$0', $u)); } } } } $next_page = false; $links = $selector->matchAll('.clsBlueBg')->getNodes(); foreach ($links as $link) { if ($link->getAttribute('title') == "Next Page") { $url = "http://searchwww.sec.gov" . $link->getAttribute('href'); $next_page = true; } } } $search_pages++; } } return $form4_urls; }
$t->is($css->matchSingle('#foo_minute')->getNode()->nextSibling->nodeValue, ':', '->render() renders 3 selects with a default : as a format'); $t->diag('change date and time format option'); $w->setOption('date', array('format' => '%month%-%day%-%year%')); $w->setOption('time', array('format' => '%hour%!%minute%!%second%', 'with_seconds' => true)); $dom->loadHTML($w->render('foo', '2005-10-15 12:30:35')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#foo_day')->getNode()->nextSibling->nodeValue, '-', '__construct() can change the default format'); $t->like($css->matchSingle('#foo_month')->getNode()->nextSibling->nodeValue, '/^-/', '__construct() can change the default format'); $t->is($css->matchSingle('#foo_hour')->getNode()->nextSibling->nodeValue, '!', '__construct() can change the default format'); $t->is($css->matchSingle('#foo_minute')->getNode()->nextSibling->nodeValue, '!', '__construct() can change the default format'); // with_time option $t->diag('with_time option'); $w = new sfWidgetFormDateTime(array('with_time' => false)); $dom->loadHTML($w->render('foo', '2005-10-15 12:30:35')); $css = new sfDomCssSelector($dom); $t->is(count($css->matchAll('#foo_hour')->getNodes()), 0, '->render() does not render the time if the with_time option is disabled'); // date and time options as array $t->diag('date and time options as array'); $w = new sfWidgetFormDateTime(array('date' => 'a string')); try { $w->render('foo'); $t->fail('__construct() throws a InvalidArgumentException if the date/time options is not an array'); } catch (InvalidArgumentException $e) { $t->pass('__construct() throws a InvalidArgumentException if the date/time options is not an array'); } // attributes $t->diag('attributes'); $w = new sfWidgetFormDateTime(); $dom->loadHTML($w->render('foo', '2005-10-15 12:30:35', array('date' => array('disabled' => 'disabled'), 'time' => array('disabled' => 'disabled')))); $t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 5, '->render() takes the attributes into account for all the five embedded widgets'); $w->setAttribute('date', array('disabled' => 'disabled'));
<?php include dirname(__FILE__) . '/../../bootstrap/functional.php'; $browser = new opTestFunctional(new opBrowser(), new lime_test(null, new lime_output_color())); $browser->info('0. Login')->get('/member/login')->click('ログイン', array('authMailAddress' => array('mail_address' => '*****@*****.**', 'password' => 'password')))->isStatusCode(302)->info('1. Community list is shown on the member\'s home.')->get('member/home'); $selector = new sfDomCssSelector($browser->getResponseDom()); $list = $selector->matchAll('#Left h3:contains("コミュニティリスト")')->getNodes(); $browser->test()->ok($list, 'a community list gadget exists'); $photoLink = ''; $textLink = ''; $xpath = new DOMXPath($browser->getResponseDom()); foreach ($xpath->query('../../table/tr', $list[0]) as $item) { if ($item->getAttribute('class') === 'photo') { $photoLink = $item->firstChild->getElementsByTagName('a')->item(0)->getAttribute('href'); } elseif ($item->getAttribute('class') === 'text') { $textLink = $item->firstChild->getElementsByTagName('a')->item(0)->getAttribute('href'); } } $browser->test()->ok($photoLink, 'photo link exists'); $browser->test()->ok($textLink, 'text link exists'); $browser->info('links in a community list is a valid (ref. #3546)')->info('photo link is a valid')->get($photoLink)->isStatusCode(200)->with('request')->begin()->isParameter('module', 'community')->isParameter('action', 'home')->end()->info('text link is a valid')->get($textLink)->isStatusCode(200)->with('request')->begin()->isParameter('module', 'community')->isParameter('action', 'home')->end();
$t->is($css->matchSingle('#foo_minute')->getNode()->nextSibling->nodeValue, ':', '->render() renders 3 selects with a default : as a format'); $t->diag('change date and time format option'); $w->setOption('date', array('format' => '%month%-%day%-%year%')); $w->setOption('time', array('format' => '%hour%!%minute%!%second%', 'with_seconds' => true)); $dom->loadHTML($w->render('foo', $year . '-10-15 12:30:35')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#foo_day')->getNode()->nextSibling->nodeValue, '-', '__construct() can change the default format'); $t->like($css->matchSingle('#foo_month')->getNode()->nextSibling->nodeValue, '/^-/', '__construct() can change the default format'); $t->is($css->matchSingle('#foo_hour')->getNode()->nextSibling->nodeValue, '!', '__construct() can change the default format'); $t->is($css->matchSingle('#foo_minute')->getNode()->nextSibling->nodeValue, '!', '__construct() can change the default format'); // with_time option $t->diag('with_time option'); $w = new sfWidgetFormDateTime(array('with_time' => false)); $dom->loadHTML($w->render('foo', $year . '-10-15 12:30:35')); $css = new sfDomCssSelector($dom); $t->is(count($css->matchAll('#foo_hour')->getNodes()), 0, '->render() does not render the time if the with_time option is disabled'); // date and time options as array $t->diag('date and time options as array'); $w = new sfWidgetFormDateTime(array('date' => 'a string')); try { $w->render('foo'); $t->fail('__construct() throws a InvalidArgumentException if the date/time options is not an array'); } catch (InvalidArgumentException $e) { $t->pass('__construct() throws a InvalidArgumentException if the date/time options is not an array'); } // attributes $t->diag('attributes'); $w = new sfWidgetFormDateTime(); $dom->loadHTML($w->render('foo', $year . '-10-15 12:30:35', array('date' => array('disabled' => 'disabled'), 'time' => array('disabled' => 'disabled')))); $t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 5, '->render() takes the attributes into account for all the five embedded widgets'); $w->setAttribute('date', array('disabled' => 'disabled'));
$dom->validateOnParse = true; // ->configure() $t->diag('->configure()'); try { new sfWidgetFormI18nChoiceCurrency(array('culture' => 'en', 'currencies' => array('xx'))); $t->fail('->configure() throws an InvalidArgumentException if a currency does not exist'); } catch (InvalidArgumentException $e) { $t->pass('->configure() throws an InvalidArgumentException if a currency does not exist'); } $v = new sfWidgetFormI18nChoiceCurrency(array('culture' => 'en', 'currencies' => array('EUR', 'USD'))); $t->is(array_keys($v->getOption('choices')), array('EUR', 'USD'), '->configure() can restrict the number of currencies with the currencies option'); // ->render() $t->diag('->render()'); $w = new sfWidgetFormI18nChoiceCurrency(array('culture' => 'fr')); $dom->loadHTML($w->render('currency', 'EUR')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#currency option[value="EUR"]')->getValue(), 'euro', '->render() renders all currencies as option tags'); $t->is(count($css->matchAll('#currency option[value="EUR"][selected="selected"]')->getNodes()), 1, '->render() renders all currencies as option tags'); // Test for ICU Upgrade // should be 0. Test will break after ICU Update, which is fine. change count to 0 $t->is(count($css->matchAll('#currency option[value="XXX"]')), 1, '->render() does not output ICU dummy data'); // add_empty $t->diag('add_empty'); $w = new sfWidgetFormI18nChoiceCurrency(array('culture' => 'fr', 'add_empty' => true)); $dom->loadHTML($w->render('currency', 'EUR')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#currency option[value=""]')->getValue(), '', '->render() renders an empty option if add_empty is true'); $w = new sfWidgetFormI18nChoiceCurrency(array('culture' => 'fr', 'add_empty' => 'foo')); $dom->loadHTML($w->render('currency', 'EUR')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#currency option[value=""]')->getValue(), 'foo', '->render() renders an empty option if add_empty is true');
$t->is($c->getTexts('p:lt(2)'), array('header', 'multi-classes'), '->getTexts() :lt'); $t->is($c->getTexts('p:gt(2)'), array('myfoo bis', 'works great', 'First paragraph', 'Second paragraph', 'Third paragraph'), '->getTexts() :gt'); $t->is($c->getTexts('p:odd'), array('multi-classes', 'myfoo bis', 'First paragraph', 'Third paragraph'), '->getTexts() :odd'); $t->is($c->getTexts('p:even'), array('header', 'myfoo', 'works great', 'Second paragraph'), '->getTexts() :even'); $t->is($c->getTexts('#simplelist li:first-child'), array('First', 'First'), '->getTexts() :first-child'); $t->is($c->getTexts('#simplelist li:nth-child(1)'), array('First', 'First'), '->getTexts() :nth-child'); $t->is($c->getTexts('#simplelist li:nth-child(2)'), array('Second with a link', 'Second'), '->getTexts() :nth-child'); $t->is($c->getTexts('#simplelist li:nth-child(3)'), array('Third with another link'), '->getTexts() :nth-child'); $t->is($c->getTexts('#simplelist li:last-child'), array('Second with a link', 'Third with another link'), '->getTexts() :last-child'); $t->diag('combinations of pseudo-selectors'); $t->is($c->getTexts('.myfoo:contains("myfoo"):contains("bis")'), array('myfoo bis'), '->getTexts() :contains():contains()'); $t->is($c->getTexts('.myfoo:contains("myfoo"):last'), array('myfoo bis'), '->getTexts() :contains():last'); $t->is($c->getTexts('.myfoo:last:contains("foobarbaz")'), array(), '->getTexts() :last:contains()'); $t->is($c->getTexts('.myfoo:contains("myfoo"):contains(\'bis\'):contains(foo)'), array('myfoo bis'), '->getTexts() :contains() supports different quote styles'); // ->matchAll() $t->diag('->matchAll()'); $t->is($c->matchAll('ul')->matchAll('li')->getValues(), $c->matchAll('ul li')->getValues(), '->matchAll() returns a new sfDomCssSelector restricted to the result nodes'); // ->matchSingle() $t->diag('->matchSingle()'); $t->is(array($c->matchAll('ul li')->getValue()), $c->matchSingle('ul li')->getValues(), '->matchSingle() returns a new sfDomCssSelector restricted to the first result node'); // ->getValues() $t->diag('->getValues()'); $t->is($c->matchAll('p.myfoo')->getValues(), array('myfoo', 'myfoo bis'), '->getValues() returns all node values'); // ->getValue() $t->diag('->getValue()'); $t->is($c->matchAll('h1')->getValue(), 'Test page', '->getValue() returns the first node value'); $t->is($c->getTexts('#adjacent_bug > p'), array('First paragraph', 'Second paragraph', 'Third paragraph'), '->getTexts() suppports the + combinator'); $t->is($c->getTexts('#adjacent_bug > p > a'), array('paragraph'), '->getTexts() suppports the + combinator'); $t->is($c->getTexts('#adjacent_bug p + p'), array('Second paragraph', 'Third paragraph'), '->getTexts() suppports the + combinator'); $t->is($c->getTexts('#adjacent_bug > p + p'), array('Second paragraph', 'Third paragraph'), '->getTexts() suppports the + combinator'); $t->is($c->getTexts('#adjacent_bug > p + p > a'), array('paragraph'), '->getTexts() suppports the + combinator');
<p>Second paragraph</p> <p>Third <a href='#'>paragraph</a></p> </div> <div id="footer">footer</div> </body> </html> EOF; $dom = new DomDocument('1.0', 'utf-8'); $dom->validateOnParse = true; $dom->loadHTML($html); $c = new sfDomCssSelector($dom); // ->matchAll() $t->diag('->matchAll()'); $t->diag('basic selectors'); $t->is($c->matchAll('h1')->getValues(), array('Test page'), '->matchAll() takes a CSS selector as its first argument'); $t->is($c->matchAll('h2')->getValues(), array('Title 1', 'Title 2'), '->matchAll() returns an array of matching texts'); $t->is($c->matchAll('#footer')->getValues(), array('footer'), '->matchAll() supports searching html elements by id'); $t->is($c->matchAll('div#footer')->getValues(), array('footer'), '->matchAll() supports searching html elements by id for a tag name'); $t->is($c->matchAll('*[class="myfoo"]')->getValues(), array('myfoo', 'myfoo bis'), '->matchAll() can take a * to match every elements'); $t->is($c->matchAll('.header')->getValues(), array('header'), '->matchAll() supports searching html elements by class name'); $t->is($c->matchAll('p.header')->getValues(), array('header'), '->matchAll() supports searching html elements by class name for a tag name'); $t->is($c->matchAll('div.header')->getValues(), array(), '->matchAll() supports searching html elements by class name for a tag name'); $t->is($c->matchAll('*.header')->getValues(), array('header'), '->matchAll() supports searching html elements by class name'); $t->is($c->matchAll('.foo')->getValues(), array('multi-classes'), '->matchAll() supports searching html elements by class name for multi-class elements'); $t->is($c->matchAll('.bar')->getValues(), array('multi-classes'), '->matchAll() supports searching html elements by class name for multi-class elements'); $t->is($c->matchAll('.foobar')->getValues(), array('multi-classes'), '->matchAll() supports searching html elements by class name for multi-class elements'); $t->is($c->matchAll('ul#mylist ul li')->getValues(), array('element 3', 'element 4'), '->matchAll() supports searching html elements by several selectors'); $t->is($c->matchAll('#nonexistant')->getValues(), array(), '->matchAll() returns an empty array if the id does not exist'); $t->diag('attribute selectors'); $t->is($c->matchAll('ul#list li a[href]')->getValues(), array('link'), '->matchAll() supports checking attribute existence');
$css = new sfDomCssSelector($dom); $t->is($css->matchSingle('select')->getNode()->getAttribute('name'), 'foo[minute]', '__construct() can change the default time format'); // hours / minutes / seconds options $t->diag('hours / minutes / seconds options'); $w->setOption('hours', array(1 => 1, 2 => 2, 3 => 3, 4 => 4)); $w->setOption('minutes', array(1 => 1, 2 => 2)); $w->setOption('seconds', array(15 => 15, 30 => 30, 45 => 45)); $dom->loadHTML($w->render('foo', '12:30:35')); $css = new sfDomCssSelector($dom); $t->is(count($css->matchAll('#foo_hour option')->getNodes()), 5, '__construct() can change the default array used for hours'); $t->is(count($css->matchAll('#foo_minute option')->getNodes()), 3, '__construct() can change the default array used for minutes'); $t->is(count($css->matchAll('#foo_second option')->getNodes()), 4, '__construct() can change the default array used for seconds'); // with_seconds option $t->diag('with_seconds option'); $w->setOption('with_seconds', false); $dom->loadHTML($w->render('foo', '12:30:35')); $css = new sfDomCssSelector($dom); $t->is(count($css->matchAll('#foo_second option')->getNodes()), 0, '__construct() can enable or disable the seconds select box with the with_seconds option'); $w->setOption('format_without_seconds', '%hour%#%minute%'); $dom->loadHTML($w->render('foo', '12:30:35')); $css = new sfDomCssSelector($dom); $t->like($css->matchSingle('#foo_hour')->getNode()->nextSibling->nodeValue, '/^#/', '__construct() can change the default format'); $t->ok(!count($css->matchSingle('#foo_second')->getNodes()), '__construct() can change the default format'); // attributes $t->diag('attributes'); $w->setOption('with_seconds', true); $dom->loadHTML($w->render('foo', '12:30:35', array('disabled' => 'disabled'))); $t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 3, '->render() takes the attributes into account for all the three embedded widgets'); $w->setAttribute('disabled', 'disabled'); $dom->loadHTML($w->render('foo', '12:30:35')); $t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 3, '->render() takes the attributes into account for all the three embedded widgets');
// ->configure() $t->diag('->configure()'); try { new sfWidgetFormI18nChoiceCountry(array('culture' => 'en', 'countries' => array('EN'))); $t->fail('->configure() throws an InvalidArgumentException if a country does not exist'); } catch (InvalidArgumentException $e) { $t->pass('->configure() throws an InvalidArgumentException if a country does not exist'); } $v = new sfWidgetFormI18nChoiceCountry(array('culture' => 'en', 'countries' => array('FR', 'GB'))); $t->is(array_keys($v->getOption('choices')), array('FR', 'GB'), '->configure() can restrict the number of countries with the countries option'); // ->render() $t->diag('->render()'); $w = new sfWidgetFormI18nChoiceCountry(array('culture' => 'fr')); $dom->loadHTML($w->render('country', 'FR')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#country option[value="FR"]')->getValue(), 'France', '->render() renders all countries as option tags'); $t->is(count($css->matchAll('#country option[value="FR"][selected="selected"]')->getNodes()), 1, '->render() renders all countries as option tags'); // Test for ICU Upgrade and Ticket #7988 // should be 0. Tests will break after ICU Update, which is fine. change count to 0 $t->is(count($css->matchAll('#country option[value="ZZ"]')), 1, '->render() does not contain dummy data'); $t->is(count($css->matchAll('#country option[value="419"]')), 0, '->render() does not contain region data'); // add_empty $t->diag('add_empty'); $w = new sfWidgetFormI18nChoiceCountry(array('culture' => 'fr', 'add_empty' => true)); $dom->loadHTML($w->render('country', 'FR')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#country option[value=""]')->getValue(), '', '->render() renders an empty option if add_empty is true'); $w = new sfWidgetFormI18nChoiceCountry(array('culture' => 'fr', 'add_empty' => 'foo')); $dom->loadHTML($w->render('country', 'FR')); $css = new sfDomCssSelector($dom); $t->is($css->matchSingle('#country option[value=""]')->getValue(), 'foo', '->render() renders an empty option if add_empty is true');
private function getForm4Urls($corp_cik) { //to check out the page, an example url: http://searchwww.sec.gov/EDGARFSClient/jsp/EDGAR_Query_Result.jsp?queryString=&queryForm=Form4&isAdv=1&queryCik=876437&numResults=100#topAnchor $url = 'http://searchwww.sec.gov/EDGARFSClient/jsp/EDGAR_Query_Result.jsp?queryString=&queryForm=Form4&isAdv=1&queryCik=' . $corp_cik . '&numResults=10'; $form4_urls = array(); $search_pages = 0; $unique_ciks = array(); $next_page = true; //loop through search results while ($next_page == true && $search_pages < $this->search_depth) { if (!$this->browser->get($url)->responseIsError()) { $selector = $this->browser->getResponseDomCssSelector(); $text = $this->browser->getResponseText(); $rows = $selector->matchAll('tr')->getNodes(); for ($i = 0; $i < count($rows); $i++) { $row = new sfDomCssSelector(array($rows[$i])); $links = $row->matchAll('a')->getNodes(); $person_cik = null; foreach ($links as $link) { if ($link->getAttribute('name') == 'cikSearch') { $person_cik = trim($link->textContent); //break if it's not same as corp's cik if ($person_cik != $corp_cik) { break; } } } if (!$person_cik) { continue; } if (!in_array($person_cik, $unique_ciks)) { $prev_row = new sfDomCssSelector($rows[$i - 1]); $href = $prev_row->matchSingle('a')->getNode(); if (!is_object($href)) { continue; } $href = $href->getAttribute('href'); //if not an xml doc, grab the parent filing underneath the listing if (!stripos($href, '.xml')) { $next_row = new sfDomCssSelector($rows[$i + 2]); $href = $next_row->matchSingle('a')->getNode(); if (!is_object($href)) { continue; } if (trim($href->getAttribute('title')) == 'Parent Filing') { $href = $href->getAttribute('href'); } else { continue; } } if (preg_match("/\\'([^\\']+)\\'/", $href, $matches)) { $unique_ciks[] = $person_cik; $u = str_replace('xslF345/', '', $matches[1]); if ($u != $matches[1]) { $form4_urls[] = array('xmlUrl' => $u, 'htmlUrl' => $matches[1]); } } } } $next_page = false; $links = $selector->matchAll('.clsBlueBg')->getNodes(); foreach ($links as $link) { if ($link->getAttribute('title') == "Next Page") { $url = "http://searchwww.sec.gov" . $link->getAttribute('href'); $next_page = true; } } } $search_pages++; } return $form4_urls; }