/** * @param BinaryIterator $binary * * @return $this */ public function setBinaryString(BinaryIterator $binary) { $iterator = new \MultipleIterator(\MultipleIterator::MIT_NEED_ALL | \MultipleIterator::MIT_KEYS_ASSOC); $iterator->attachIterator(new RectIterator($this->width, $this->height), 'rect'); $iterator->attachIterator($binary, 'bin'); foreach ($iterator as $current) { $this->setPixel($current['rect'][0], $current['rect'][1], $current['bin']); } return $this; }
function mmap(callable $callback, ...$iterators) { $mi = new MultipleIterator(MultipleIterator::MIT_NEED_ANY); foreach ($iterators as $iterator) { $mi->attachIterator($iterator); } foreach ($mi as $values) { (yield $callback(...$values)); } }
protected function execute(InputInterface $input) { $iterator = new \MultipleIterator(); $writer = $this->getWriter($input); foreach ($input->getArgument('files') as $i => $file) { $iterator->attachIterator($this->getReader($input, $i)); } foreach ($iterator as $data) { $writer->write(call_user_func_array('array_merge', $data)); } }
function test2() { $first = [1 => 1, 5 => 5, 10 => 10]; $second = range(11, 21); $third = [3 => 3, 5 => 5, 7 => 7]; $iterator = new MultipleIterator(MultipleIterator::MIT_KEYS_ASSOC); $iterator->attachIterator(new ArrayIterator($first), 'elso'); $iterator->attachIterator(new ArrayIterator($second), 'masodik'); $iterator->attachIterator(new ArrayIterator($third), 'harmadik'); foreach ($iterator as $key => $value) { printf("%s => %s, %s => %s, %s => %s\n", $key['elso'], $value['elso'], $key['masodik'], $value['masodik'], $key['harmadik'], $value['harmadik']); } }
/** * Get the registered iterator instances. * * @return array */ public function current() { $out = parent::current(); foreach ($out as $key => &$value) { if (null === $value) { $value = $this->_infos[$key]; } } return $out; }
public function testIndexGET() { // 1. Login, GET the url, parse the response and send it back. $html = $this->loginRequestResponse(FixtureConstants::userAndyAdminId, '/roles/index'); // 2. Get a the count of all <A> tags that are presently unaccounted for. $this->content = $html->find('div#RolesIndex', 0); $this->assertNotNull($this->content); $unknownATag = count($this->content->find('a')); // 3. Look for the create new role link $this->assertEquals(1, count($html->find('a#RoleAdd'))); $unknownATag--; // 4. Ensure that there is a suitably named table to display the results. $this->table = $html->find('table#RolesTable', 0); $this->assertNotNull($this->table); // 5. 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, 'title'); $this->assertEquals($thead_ths[1]->id, 'actions'); $column_count = count($thead_ths); $this->assertEquals($column_count, 2); // no other columns // 6. Ensure that the tbody section has the same // quantity of rows as the count of roles records in the fixture. $this->tbody = $this->table->find('tbody', 0); $tbody_rows = $this->tbody->find('tr'); $this->assertEquals(count($tbody_rows), count($this->rolesFixture->records)); // 7. 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($this->rolesFixture->records)); $iterator->attachIterator(new \ArrayIterator($tbody_rows)); foreach ($iterator as $values) { $fixtureRecord = $values[0]; $this->htmlRow = $values[1]; $htmlColumns = $this->htmlRow->find('td'); // 7.0 title $this->assertEquals($fixtureRecord['title'], $htmlColumns[0]->plaintext); // 7.1 Now examine the action links $this->td = $htmlColumns[1]; $actionLinks = $this->td->find('a'); $this->assertEquals('RoleView', $actionLinks[0]->name); $unknownATag--; $this->assertEquals('RoleEdit', $actionLinks[1]->name); $unknownATag--; $this->assertEquals('RoleDelete', $actionLinks[2]->name); $unknownATag--; // 7.9 No other columns $this->assertEquals(count($htmlColumns), $column_count); } // 8. Ensure that all the <A> tags have been accounted for $this->assertEquals(0, $unknownATag); }
<?php $iter1 = new ArrayIterator(array(1, 2, 3)); $iter2 = new ArrayIterator(array(1, 2)); $iter3 = new ArrayIterator(array(new stdClass(), "string", 3)); $m = new MultipleIterator(); echo "-- Default flags, no iterators --\n"; foreach ($m as $value) { var_dump($value); } var_dump($m->current()); $m->attachIterator($iter1); $m->attachIterator($iter2); $m->attachIterator($iter3); echo "-- Default flags, MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_KEYS_NUMERIC --\n"; var_dump($m->getFlags() === (MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_KEYS_NUMERIC)); foreach ($m as $key => $value) { var_dump($key, $value); } try { $m->current(); } catch (RuntimeException $e) { echo "RuntimeException thrown: " . $e->getMessage() . "\n"; } try { $m->key(); } catch (RuntimeException $e) { echo "RuntimeException thrown: " . $e->getMessage() . "\n"; } echo "-- Flags = MultipleIterator::MIT_NEED_ANY | MultipleIterator::MIT_KEYS_NUMERIC --\n"; $m->setFlags(MultipleIterator::MIT_NEED_ANY | MultipleIterator::MIT_KEYS_NUMERIC);
public function testIndexGET() { // 1. Login, GET the url, parse the response and send it back. $html = $this->loginRequestResponse(FixtureConstants::userAndyAdminId, '/interactions/index'); // 2. Get a the count of all <A> tags that are presently unaccounted for. $this->content = $html->find('div#InteractionsIndex', 0); $this->assertNotNull($this->content); $unknownATag = count($this->content->find('a')); // 3. Look for the create new interaction link $this->assertEquals(1, count($html->find('a#InteractionAdd'))); $unknownATag--; // 4. Ensure that there is a suitably named table to display the results. $this->table = $html->find('table#InteractionsTable', 0); $this->assertNotNull($this->table); // 5. 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); $this->thead_ths = $this->thead->find('tr th'); $this->assertEquals($this->thead_ths[0]->id, 'clazz'); $this->assertEquals($this->thead_ths[1]->id, 'student'); $this->assertEquals($this->thead_ths[2]->id, 'itype'); $this->assertEquals($this->thead_ths[3]->id, 'participate'); $this->assertEquals($this->thead_ths[4]->id, 'actions'); $column_count = count($this->thead_ths); $this->assertEquals($column_count, 5); // no other columns // 6. Ensure that the tbody section has the same // quantity of rows as the count of interaction records in the fixture. $this->tbody = $this->table->find('tbody', 0); $this->tbody_rows = $this->tbody->find('tr'); $this->assertEquals(count($this->tbody_rows), count($this->interactionsFixture->records)); // 7. 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($this->interactionsFixture->records)); $iterator->attachIterator(new \ArrayIterator($this->tbody_rows)); foreach ($iterator as $values) { $fixtureRecord = $values[0]; $this->htmlRow = $values[1]; $htmlColumns = $this->htmlRow->find('td'); // 7.0 clazz_nickname. read from Table because we need to compute // the 'nickname' virtual field. $clazz = $this->clazzes->get($fixtureRecord['clazz_id']); $this->assertEquals($clazz->nickname, $htmlColumns[0]->plaintext); // 7.1 student_fullname. read from Table because we need to compute // the 'fullname' virtual field. $student = $this->students->get($fixtureRecord['student_id']); $this->assertEquals($student->fullname, $htmlColumns[1]->plaintext); // 7.2 itype_id requires finding the related value in the ItypesFixture $itype_id = $fixtureRecord['itype_id']; $itype = $this->itypesFixture->get($itype_id); $this->assertEquals($itype['title'], $htmlColumns[2]->plaintext); // 7.3 participate $this->assertEquals($fixtureRecord['participate'], $htmlColumns[3]->plaintext); // 7.4 Now examine the action links $this->td = $htmlColumns[4]; $actionLinks = $this->td->find('a'); $this->assertEquals('InteractionView', $actionLinks[0]->name); $unknownATag--; $this->assertEquals('InteractionEdit', $actionLinks[1]->name); $unknownATag--; $this->assertEquals('InteractionDelete', $actionLinks[2]->name); $unknownATag--; // 7.9 No other columns $this->assertEquals(count($htmlColumns), $column_count); } // 8. Ensure that all the <A> tags have been accounted for $this->assertEquals(0, $unknownATag); }
public function testIndexGET() { // 1. Simulate login, submit request, examine response. /*$this->fakeLogin(FixtureConstants::userAndyAdminId); $this->get('/teachers/index'); $this->assertResponseOk(); // 2xx $this->assertNoRedirect(); // 2. Parse the html from the response $html = str_get_html($this->_response->body());*/ // 1. Login, GET the url, parse the response and send it back. $html = $this->loginRequestResponse(FixtureConstants::userAndyAdminId, '/teachers/index'); // 2. Get a the count of all <A> tags that are presently unaccounted for. $this->content = $html->find('div#TeachersIndex', 0); $this->assertNotNull($this->content); $unknownATag = count($this->content->find('a')); // 3. Look for the create new subject link $this->assertEquals(1, count($html->find('a#TeacherAdd'))); $unknownATag--; // 4. Ensure that there is a suitably named table to display the results. $this->table = $html->find('table#TeachersTable', 0); $this->assertNotNull($this->table); // 5. 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, 'fam_name'); $this->assertEquals($thead_ths[1]->id, 'giv_name'); $this->assertEquals($thead_ths[2]->id, 'username'); $this->assertEquals($thead_ths[3]->id, 'actions'); $column_count = count($thead_ths); $this->assertEquals($column_count, 4); // no other columns // 6. Ensure that the tbody section has the same // quantity of rows as the count of subject records in the fixture. $this->tbody = $this->table->find('tbody', 0); $tbody_rows = $this->tbody->find('tr'); $this->assertEquals(count($tbody_rows), count($this->teachersFixture->records)); // 7. 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($this->teachersFixture->records)); $iterator->attachIterator(new \ArrayIterator($tbody_rows)); foreach ($iterator as $values) { $fixtureRecord = $values[0]; $this->htmlRow = $values[1]; $htmlColumns = $this->htmlRow->find('td'); // 7.0 fam_name $this->assertEquals($fixtureRecord['fam_name'], $htmlColumns[0]->plaintext); // 7.1 giv_name $this->assertEquals($fixtureRecord['giv_name'], $htmlColumns[1]->plaintext); // 7.2 username requires finding the related value in the UsersFixture $user_id = $fixtureRecord['user_id']; if (is_null($user_id)) { $expectedValue = ''; } else { $user = $this->usersFixture->get($user_id); $expectedValue = $user['username']; } $this->assertEquals($expectedValue, $htmlColumns[2]->plaintext); // 7.3 Now examine the action links $this->td = $htmlColumns[3]; $actionLinks = $this->td->find('a'); $this->assertEquals('TeacherView', $actionLinks[0]->name); $unknownATag--; $this->assertEquals('TeacherEdit', $actionLinks[1]->name); $unknownATag--; $this->assertEquals('TeacherDelete', $actionLinks[2]->name); $unknownATag--; // 7.9 No other columns $this->assertEquals(count($htmlColumns), $column_count); } // 9. Ensure that all the <A> tags have been accounted for $this->assertEquals(0, $unknownATag); }
public function testGET_index() { // 1. Submit request, examine response, observe no redirect, and parse the response. $this->get("/books"); $this->assertResponseCode(200); $this->assertNoRedirect(); $dom = new \DomDocument(); $dom->loadHTML($this->_response->body()); $xpath = new \DomXPath($dom); // 2. Isolate the content produced by this controller method (excluding the layout.) $content_node = $this->getTheOnlyOne($xpath, "//div[@id='BooksIndex']"); // 3. Count the A tags. $unknownATagCnt = $xpath->query(".//a", $content_node)->length; // 4. Look for the create new book link $this->getTheOnlyOne($xpath, "//a[@id='BookNewform']", $content_node); $unknownATagCnt--; // 5. Ensure that there is a suitably named table to display the results. $table_node = $this->getTheOnlyOne($xpath, "//table[@id='BooksTable']", $content_node); // 6. Now inspect the caption of the table. $this->assertContains("Books", $this->getTheOnlyOne($xpath, "caption", $table_node)->textContent); // 7. Ensure that said table's thead element contains the correct // headings, in the correct order, and nothing else. $column_header_nodes = $xpath->query("thead/tr/th", $table_node); $this->assertEquals($column_header_nodes->length, 2); // no other columns $this->getTheOnlyOne($xpath, "thead/tr/th[1][@id='title']", $table_node); $this->getTheOnlyOne($xpath, "thead/tr/th[2][@id='actions']", $table_node); // 8. Ensure that the tbody section has the correct quantity of rows. $dbRecords = $this->Books->find()->order(['id']); $tbody_nodes = $xpath->query("tbody/tr", $table_node); $this->assertTrue($tbody_nodes->length == $dbRecords->count()); // 9. 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($dbRecords->execute()->fetchAll('assoc'))); $iterator->attachIterator(new \ArrayIterator(iterator_to_array($tbody_nodes))); foreach ($iterator as $values) { $fixtureRecord = $values[0]; $row_node = $values[1]; $column_nodes = $xpath->query("td", $row_node); $this->assertEquals($fixtureRecord['Books__title'], $column_nodes->item(0)->textContent); // 9.1 Now examine the action links $action_nodes = $xpath->query("a", $column_nodes->item(1)); $this->assertTrue($action_nodes->length == 2); $this->getTheOnlyOne($xpath, "a[@name='BookView']", $column_nodes->item(1)); $unknownATagCnt--; $this->getTheOnlyOne($xpath, "a[@name='BookEdit']", $column_nodes->item(1)); $unknownATagCnt--; // 9.9 No other colu mns $this->assertEquals($column_nodes->length, $column_header_nodes->length); } // 10. Ensure that all the <A> tags have been accounted for $this->assertEquals(0, $unknownATagCnt); }
echo '--------------------------------- RecursiveTreeIterator END-----------------------------------', '<br />'; /** * RecursiveTreeIterator 已可视的方式显示一个树形结构 */ $array = array("a" => "lemon", "b" => "orange", array("a" => "apple", "p" => "pear")); $rtreeIt = new RecursiveTreeIterator(new RecursiveArrayIterator($array), null, null, RecursiveIteratorIterator::LEAVES_ONLY); foreach ($rtreeIt as $item) { echo $item; } echo '--------------------------------- RecursiveTreeIterator START-----------------------------------', '<br />'; echo '----------------------------------- MultipleIterator END ---------------------------------', '<br />'; /** * MultipleIterator 用于迭代器的连接器 * 预定义常量: * MultipleIterator::MIT_NEED_ANY 不需要所有的子迭代作为有用的节点. 不能设置键值。默认数字键值 * MultipleIterator::MIT_NEED_ALL 所有的子节点都是有用的迭代. 不能设置键值。默认数字键值 * MultipleIterator::MIT_KEYS_NUMERIC 将子节点的位置作为键值key. 不能设置键值。默认数字键值 * MultipleIterator::MIT_KEYS_ASSOC 为子迭代增加键值.使用attachIterator,可以为每一个设置键值 * */ $person_id = new ArrayIterator(array('001', '002', '003')); $person_name = new ArrayIterator(array('name1', 'name2', 'name3')); $person_age = new ArrayIterator(array(22, 23, 11)); $persons = new MultipleIterator(MultipleIterator::MIT_KEYS_ASSOC); $persons->attachIterator($person_id, "ID"); $persons->attachIterator($person_name, "NAME"); $persons->attachIterator($person_age, "AGE"); foreach ($persons as $person) { var_dump($person); } echo '--------------------------------- MultipleIterator END-----------------------------------', '<br />';
/** * update() * Builds update statement * * @param string $table Table name you want to update * @param array $data Array of strings that needs to be updated, example array("fieldname" => "value"); * @throws Exception * @return object Query() */ public function update($table, $data) { $this->table = $table; if (!isset($this->table)) { throw new Exception("Table name is required for update method to build query"); } if (!isset($data) || !is_array($data)) { throw new Exception("Update Values are required to build query"); } $this->query = "UPDATE " . $this->escapeField($this->table) . " SET "; $this->buildBindAndFieldObjectsFromArray($data); $multipleIterator = new \MultipleIterator(); $multipleIterator->attachIterator(new \ArrayIterator($this->fields)); $multipleIterator->attachIterator(new \ArrayIterator($this->bind)); $multipleIterator->attachIterator(new \ArrayIterator(array_keys($this->bind))); foreach ($multipleIterator as $data) { list($field, $bindValues, $bindKeys) = $data; $this->query .= $this->escapeField($field) . " = " . $this->implodeBindValues(array($bindKeys => $bindValues)) . ", "; } $this->query = substr($this->query, 0, -2) . " "; $this->cleanFunctionsFromBind(); return $this; }
public function testGET_indexa() { // 1. Submit submit request, examine response, observe no redirect, and parse the response. $account_id = FixtureConstants::accountTypical; $account = $this->{'Accounts'}->get($account_id); $this->get('/books/' . FixtureConstants::bookTypical . '/accounts/' . $account_id . '/distributions'); $this->assertResponseCode(200); $this->assertNoRedirect(); $dom = new \DomDocument(); $dom->loadHTML($this->_response->body()); $xpath = new \DomXPath($dom); // 2. Isolate the content produced by this controller method (excluding the layout.) $content_node = $this->getTheOnlyOne($xpath, "//div[@id='DistributionsIndex']"); // 3. Count the A tags. $unknownATagCnt = $xpath->query(".//a", $content_node)->length; // 4. Look for the create new distribution link //$this->getTheOnlyOne($xpath,"//a[@id='DistributionAdd']",$content_node); //$unknownATagCnt--; // 5. Ensure that there is a suitably named table to display the results. $table_node = $this->getTheOnlyOne($xpath, "//table[@id='DistributionsTable']", $content_node); // 6. Now inspect the caption of the table. $title = $account['title']; $this->assertContains("Distributions for Account : {$title}", $this->getTheOnlyOne($xpath, "caption", $table_node)->textContent); // 6. Ensure that said table's thead element contains the correct // headings, in the correct order, and nothing else. $column_header_nodes = $xpath->query("thead/tr/th", $table_node); $this->assertEquals($column_header_nodes->length, 6); // no other columns $this->getTheOnlyOne($xpath, "thead/tr/th[1][@id='tran_datetime']", $table_node); $this->getTheOnlyOne($xpath, "thead/tr/th[2][@id='note']", $table_node); $this->getTheOnlyOne($xpath, "thead/tr/th[3][@id='drcr']", $table_node); $this->getTheOnlyOne($xpath, "thead/tr/th[4][@id='amount']", $table_node); $this->getTheOnlyOne($xpath, "thead/tr/th[5][@id='currency']", $table_node); $this->getTheOnlyOne($xpath, "thead/tr/th[6][@id='run_total']", $table_node); // 7. Ensure that the tbody section has the correct quantity of rows. $dbRecords = $this->Distributions->find()->contain(['Accounts.Categories', 'Currencies', 'Transactions'])->where(['account_id' => $account_id])->order('Transactions.tran_datetime'); $tbody_nodes = $xpath->query("tbody/tr", $table_node); $this->assertTrue($tbody_nodes->length == $dbRecords->count()); // 8. 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($dbRecords->execute()->fetchAll('assoc'))); $iterator->attachIterator(new \ArrayIterator(iterator_to_array($tbody_nodes))); foreach ($iterator as $values) { $fixtureRecord = $values[0]; $row_node = $values[1]; $column_nodes = $xpath->query("td", $row_node); //$this->assertEquals($fixtureRecord['Transactions__tran_datetime'], $column_nodes->item(0)->textContent); $this->assertEquals($fixtureRecord['Transactions__note'], $column_nodes->item(1)->textContent); $this->assertEquals($fixtureRecord['Distributions__drcr'] == 1 ? 'DR' : 'CR', $column_nodes->item(2)->textContent); $this->assertEquals($fixtureRecord['Distributions__amount'], $column_nodes->item(3)->textContent); $this->assertEquals($fixtureRecord['Currencies__symbol'], $column_nodes->item(4)->textContent); // 9.5 run_total check this later //$this->assertEquals($fixtureRecord['Distributions__amount'], $htmlColumns[3]->plaintext); // No action links // 9.9 No other columns $this->assertEquals($column_nodes->length, $column_header_nodes->length); } // 10. Ensure that all the <A> tags have been accounted for $this->assertEquals(0, $unknownATagCnt); }
public function testIndexGET() { // 1. Login, GET the url, parse the response and send it back. $html = $this->loginRequestResponse(FixtureConstants::userAndyAdminId, '/cohorts/index'); // 2. Get a the count of all <A> tags that are presently unaccounted for. $this->content = $html->find('div#CohortsIndex', 0); $this->assertNotNull($this->content); $unknownATag = count($this->content->find('a')); // 3. Look for the create new cohort link $this->assertEquals(1, count($html->find('a#CohortAdd'))); $unknownATag--; // 4. Ensure that there is a suitably named table to display the results. $this->table = $html->find('table#CohortsTable', 0); $this->assertNotNull($this->table); // 5. 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, 'start_year'); $this->assertEquals($thead_ths[1]->id, 'major'); $this->assertEquals($thead_ths[2]->id, 'seq'); $this->assertEquals($thead_ths[3]->id, 'nickname'); $this->assertEquals($thead_ths[4]->id, 'actions'); $column_count = count($thead_ths); $this->assertEquals($column_count, 5); // no other columns // 6. Ensure that the tbody section has the same // quantity of rows as the count of cohort records in the fixture. $this->tbody = $this->table->find('tbody', 0); $tbody_rows = $this->tbody->find('tr'); $this->assertEquals(count($tbody_rows), count($this->cohortsFixture->records)); // 7. 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($this->cohortsFixture->records)); $iterator->attachIterator(new \ArrayIterator($tbody_rows)); foreach ($iterator as $values) { $fixtureRecord = $values[0]; $this->htmlRow = $values[1]; $htmlColumns = $this->htmlRow->find('td'); // 7.0 start_year $this->assertEquals($fixtureRecord['start_year'], $htmlColumns[0]->plaintext); // 7.1 major_id requires finding the related value in the MajorsFixture $major_id = $fixtureRecord['major_id']; $major = $this->majorsFixture->get($major_id); $this->assertEquals($major['sdesc'], $htmlColumns[1]->plaintext); // 7.2 seq $this->assertEquals($fixtureRecord['seq'], $htmlColumns[2]->plaintext); // 7.3 nickname is computed by the Cohort Entity. $cohort = $this->cohorts->get($fixtureRecord['id'], ['contain' => ['Majors']]); $this->assertEquals($cohort->nickname, $htmlColumns[3]->plaintext); // 8.4 Now examine the action links $this->td = $htmlColumns[4]; $actionLinks = $this->td->find('a'); $this->assertEquals('CohortView', $actionLinks[0]->name); $unknownATag--; $this->assertEquals('CohortEdit', $actionLinks[1]->name); $unknownATag--; $this->assertEquals('CohortDelete', $actionLinks[2]->name); $unknownATag--; // 8.9 No other columns $this->assertEquals(count($htmlColumns), $column_count); } // 9. Ensure that all the <A> tags have been accounted for $this->assertEquals(0, $unknownATag); }
<?php function gen1() { (yield 'a'); (yield 'aa'); } function gen2() { (yield 'b'); (yield 'bb'); } $it = new MultipleIterator(); $it->attachIterator(gen1()); $it->attachIterator(gen2()); foreach ($it as $values) { var_dump($values); }
function key() { return current(parent::key()); }
/** * Iterates over each of the objects at once, returning an array of values from objects in argument order. * @return \Iterator */ public static function zip() { $retval = new \MultipleIterator(\MultipleIterator::MIT_NEED_ALL | \MultipleIterator::MIT_KEYS_NUMERIC); foreach (\func_get_args() as $o) { $iter = self::ensureIsIterator($o); $retval->attachIterator($iter); } return $retval; }
public function repeatvisitor($start_date, $end_date, $website) { $iterator = new MultipleIterator(); $iterator1 = new MultipleIterator(); $start_date2 = $start_date; $end_date2 = $end_date; $website2 = $website; $users_two = $this->newusers($start_date2, $end_date2, $website2); //var_dump($users_two); $repeat = array(); $final = array(); $result = array(); $result1 = array(); foreach ($users_two as $user) { $user = (double) $user->users; array_push($result, $user); } foreach ($users_two as $val) { $new = (double) $val->newUsers; array_push($result1, $new); } $iterator->attachIterator(new ArrayIterator($result)); $iterator->attachIterator(new ArrayIterator($result1)); foreach ($iterator as $values) { $repeatuser = $values[0] - $values[1]; array_push($repeat, $repeatuser); } $iterator1->attachIterator(new ArrayIterator($repeat)); $iterator1->attachIterator(new ArrayIterator($result)); foreach ($iterator1 as $values) { $rusers = $values[0] / $values[1] * 100; array_push($final, $rusers); } $mean_session = $this->narrationengine->mean($final); $dev_session = $this->narrationengine->StandardDeviation($final); $cutt_upper = round($mean_session + $dev_session, 0); $cutt_lower = round($mean_session - $dev_session, 0); $r['upper_limit'] = $cutt_upper; $r['lower_limit'] = $cutt_lower; return $r; }
/** * 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; }
private function tstAttendGET($clazz_id = null) { if (is_null($clazz_id)) { $url = '/interactions/attend'; } else { $url = '/interactions/attend?clazz_id=' . $clazz_id; } // 1. Login, GET the url, parse the response and send it back. $html = $this->loginRequestResponse(FixtureConstants::userAndyAdminId, $url); // 2. Ensure that the correct form exists /* @var \simple_html_dom_node $form */ $form = $html->find('form#InteractionAttendForm', 0); $this->assertNotNull($form); // 3. Get a the count of all <A> tags that are presently unaccounted for. $this->content = $html->find('div#InteractionsAttend', 0); $this->assertNotNull($this->content); $unknownATag = count($this->content->find('a')); // 4. Ensure that there is a suitably named table to display the results. $this->table = $form->find('table#InteractionsTable', 0); $this->assertNotNull($this->table); // 5. 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); $this->thead_ths = $this->thead->find('tr th'); $this->assertEquals($this->thead_ths[0]->id, 'sort'); $this->assertEquals($this->thead_ths[1]->id, 'sid'); $this->assertEquals($this->thead_ths[2]->id, 'fam_name'); $this->assertEquals($this->thead_ths[3]->id, 'giv_name'); $this->assertEquals($this->thead_ths[4]->id, 'phonetic_name'); $this->assertEquals($this->thead_ths[5]->id, 'attend'); $column_count = count($this->thead_ths); $this->assertEquals($column_count, 6); // no other columns // 6. 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($clazz_id)) //$this->interactionsFixture->filterByClazzId($clazz_id); /* @var \Cake\Database\Connection $connection */ $connection = ConnectionManager::get('default'); // This query should be essentially the same as the query in InteractionsController.attend $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\n from students\n left join cohorts on students.cohort_id = cohorts.id\n left join sections on sections.cohort_id = cohorts.id\n left join clazzes on clazzes.section_id = sections.id\n 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); // 7. Ensure that the values displayed in each row are correct. // The values should be presented in a particular order // with nothing else thereafter. $iterator = new \MultipleIterator(); $iterator->attachIterator(new \ArrayIterator($studentsResults)); $iterator->attachIterator(new \ArrayIterator($this->tbody_rows)); foreach ($iterator as $values) { $attendanceRecord = $values[0]; $this->htmlRow = $values[1]; $htmlColumns = $this->htmlRow->find('td'); // 7.0 sort. $this->assertEquals($attendanceRecord['sort'], $htmlColumns[0]->plaintext); // 7.1 sid. $s1 = $htmlColumns[1]->plaintext; $this->assertEquals($attendanceRecord['sid'], $htmlColumns[1]->plaintext); // 7.2 fam_name. $this->assertEquals($attendanceRecord['fam_name'], $htmlColumns[2]->plaintext); // 7.3 giv_name. $this->assertEquals($attendanceRecord['giv_name'], $htmlColumns[3]->plaintext); // 7.4 phonetic_name. $this->assertEquals($attendanceRecord['phonetic_name'], $htmlColumns[4]->plaintext); // 7.5 attend. //$name='attend['.$attendanceRecord['id'].']'; // name of hidden field $student_id = 'attend-' . $attendanceRecord['student_id']; /* @var \simple_html_dom_node $td */ $td = $htmlColumns[5]; /* @var \simple_html_dom_node $input */ $input = $td->find('input[id=' . $student_id . ']')[0]; $this->assertNotNull($input); $checked = $input->find('input[checked=checked]'); $this->assertEquals(0, count($checked)); // No action links // 7.9 No other columns $this->assertEquals(count($htmlColumns), $column_count); } // 8. Ensure that all the <A> tags have been accounted for $this->assertEquals(0, $unknownATag); }
/** * 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; }
public function testIndexGET() { // 1. Login, GET the url, parse the response and send it back. $html = $this->loginRequestResponse(FixtureConstants::userAndyAdminId, '/sections/index'); // 2. Get a the count of all <A> tags that are presently unaccounted for. $this->content = $html->find('div#SectionsIndex', 0); $this->assertNotNull($this->content); $unknownATag = count($this->content->find('a')); // 3. Look for the create new section link $this->assertEquals(1, count($html->find('a#SectionAdd'))); $unknownATag--; // 4. Ensure that there is a suitably named table to display the results. $this->table = $html->find('table#SectionsTable', 0); $this->assertNotNull($this->table); // 5. 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, 'semester'); $this->assertEquals($thead_ths[1]->id, 'seq'); $this->assertEquals($thead_ths[2]->id, 'cohort'); $this->assertEquals($thead_ths[3]->id, 'subject'); $this->assertEquals($thead_ths[4]->id, 'teacher'); $this->assertEquals($thead_ths[5]->id, 'tplan'); $this->assertEquals($thead_ths[6]->id, 'weekday'); $this->assertEquals($thead_ths[7]->id, 'start_time'); $this->assertEquals($thead_ths[8]->id, 'thours'); $this->assertEquals($thead_ths[9]->id, 'actions'); $column_count = count($thead_ths); $this->assertEquals($column_count, 10); // no other columns // 6. Ensure that the tbody section has the same // quantity of rows as the count of section records in the fixture. $this->tbody = $this->table->find('tbody', 0); $this->tbody_rows = $this->tbody->find('tr'); $this->assertEquals(count($this->tbody_rows), count($this->sectionsFixture->records)); // 7. 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($this->sectionsFixture->records)); $iterator->attachIterator(new \ArrayIterator($this->tbody_rows)); foreach ($iterator as $values) { $fixtureRecord = $values[0]; $this->htmlRow = $values[1]; $htmlColumns = $this->htmlRow->find('td'); // 7.0 semester_nickname. read from Table because we need to compute // the 'nickname' virtual field. $semester = $this->semesters->get($fixtureRecord['semester_id']); $this->assertEquals($semester->nickname, $htmlColumns[0]->plaintext); // 7.1 seq $this->assertEquals($fixtureRecord['seq'], $htmlColumns[1]->plaintext); // 7.2 cohort_nickname. read from Table because we need to compute // the 'nickname' virtual field. $cohort = $this->cohorts->get($fixtureRecord['cohort_id'], ['contain' => ['Majors']]); $this->assertEquals($cohort->nickname, $htmlColumns[2]->plaintext); // 7.3 subject. all info is available via fixture. $subject = $this->subjectsFixture->get($fixtureRecord['subject_id']); $this->assertEquals($subject['title'], $htmlColumns[3]->plaintext); // 7.4 teacher. all info is available via fixture. $teacher = $this->teachersFixture->get($fixtureRecord['teacher_id']); $this->assertEquals($teacher['fam_name'], $htmlColumns[4]->plaintext); // 7.5 tplan. all info is available via fixture. $tplan = $this->tplansFixture->get($fixtureRecord['tplan_id']); $this->assertEquals($tplan['title'], $htmlColumns[5]->plaintext); // 7.6 weekday $this->assertEquals($fixtureRecord['weekday'], $htmlColumns[6]->plaintext); // 7.7 start_time $this->assertEquals($fixtureRecord['start_time'], $htmlColumns[7]->plaintext); // 7.8 thours $this->assertEquals($fixtureRecord['thours'], $htmlColumns[8]->plaintext); // 7.9 Now examine the action links $this->td = $htmlColumns[9]; $actionLinks = $this->td->find('a'); $this->assertEquals('SectionAttend', $actionLinks[0]->name); $unknownATag--; $this->assertEquals('SectionClazzes', $actionLinks[1]->name); $unknownATag--; $this->assertEquals('SectionView', $actionLinks[2]->name); $unknownATag--; $this->assertEquals('SectionEdit', $actionLinks[3]->name); $unknownATag--; $this->assertEquals('SectionDelete', $actionLinks[4]->name); $unknownATag--; // 7.10 No other columns $this->assertEquals(count($htmlColumns), $column_count); } // 8. Ensure that all the <A> tags have been accounted for $this->assertEquals(0, $unknownATag); }
public function testIndexGET() { // 1. Login, GET the url, and parse the response. $html = $this->loginRequestResponse(FixtureConstants::userAndyAdminId, '/students/index'); // 2. Get a the count of all <A> tags that are presently unaccounted for. $this->content = $html->find('div#StudentsIndex', 0); $this->assertNotNull($this->content); $unknownATag = count($this->content->find('a')); // 3. Look for the create new student link $this->assertEquals(1, count($html->find('a#StudentAdd'))); $unknownATag--; // 4. Ensure that there is a suitably named table to display the results. $this->table = $html->find('table#StudentsTable', 0); $this->assertNotNull($this->table); // 5. 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, 'sid'); $this->assertEquals($thead_ths[1]->id, 'fullname'); $this->assertEquals($thead_ths[2]->id, 'phonetic_name'); $this->assertEquals($thead_ths[3]->id, 'cohort_nickname'); $this->assertEquals($thead_ths[4]->id, 'username'); $this->assertEquals($thead_ths[5]->id, 'actions'); $column_count = count($thead_ths); $this->assertEquals($column_count, 6); // no other columns // 6. Ensure that the tbody section has the same // quantity of rows as the count of students records in the fixture. $this->tbody = $this->table->find('tbody', 0); $tbody_rows = $this->tbody->find('tr'); $this->assertEquals(count($tbody_rows), count($this->studentsFixture->records)); // 7. 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($this->studentsFixture->records)); $iterator->attachIterator(new \ArrayIterator($tbody_rows)); foreach ($iterator as $values) { $fixtureRecord = $values[0]; $this->htmlRow = $values[1]; $htmlColumns = $this->htmlRow->find('td'); // 7.0 sid $this->assertEquals($fixtureRecord['sid'], $htmlColumns[0]->plaintext); // 7.1 fullname is computed by the Student entity. $student = $this->students->get($fixtureRecord['id'], ['contain' => ['Cohorts.Majors']]); $this->assertEquals($student->fullname, $htmlColumns[1]->plaintext); // 7.2 phonetic_name $this->assertEquals($fixtureRecord['phonetic_name'], $htmlColumns[2]->plaintext); // 7.3 cohort_nickname is computed by the Cohort entity. $expected_value = is_null($student->cohort) ? '' : $student->cohort->nickname; $this->assertEquals($expected_value, $htmlColumns[3]->plaintext); // 7.4 username requires finding the related value in the UsersFixture $user_id = $fixtureRecord['user_id']; if (is_null($user_id)) { $expectedValue = ''; } else { $user = $this->usersFixture->get($user_id); $expectedValue = $user['username']; } $this->assertEquals($expectedValue, $htmlColumns[4]->plaintext); // 7.5 Now examine the action links $this->td = $htmlColumns[5]; $actionLinks = $this->td->find('a'); $this->assertEquals('StudentView', $actionLinks[0]->name); $unknownATag--; $this->assertEquals('StudentEdit', $actionLinks[1]->name); $unknownATag--; $this->assertEquals('StudentDelete', $actionLinks[2]->name); $unknownATag--; // 7.9 No other columns $this->assertEquals(count($htmlColumns), $column_count); } // 8. Ensure that all the <A> tags have been accounted for $this->assertEquals(0, $unknownATag); }
<?php ini_set('max_execution_time', 300); // Twitter autoreply Admin // By Devendra Kumar <*****@*****.**> date_default_timezone_set('Australia/Melbourne'); require 'config.php'; require 'TwitterAutoReply.php'; require 'db.php'; // Consumer key and consumer secret $twitter = new TwitterAutoReply(CONSUMER_KEY, CONSUMER_SECRET); // Token and secret $twitter->setToken(USER_TOKEN, USER_SECRET); //selecting records $sql = "SELECT * FROM search_reply"; //query the database $rs = mysql_query($sql) or die("SQL: " . $sql . " >> " . mysql_error()); // ArrayIterator $keyword = new ArrayIterator(); $reply = new ArrayIterator(); //retrieve our table contents while ($row = mysql_fetch_array($rs)) { $keyword[] = $row['keyword']; $reply[] = $row['reply_msg']; } $iteration = new MultipleIterator(); $iteration->attachIterator($keyword); $iteration->attachIterator($reply); foreach ($iteration as $val) { $twitter->addReply($val[0], $val[1]); } $twitter->run();
/** * Encode secretText * * @param SecretTextInterface $secretText * @param ImageInterface $coverText * @return string */ public function encode(SecretTextInterface $secretText, ImageInterface $coverText) { $this->validateCapacity($secretText, $coverText); $secretText->setBinaryItemSize($this->channelsSize); $iterator = new \MultipleIterator(\MultipleIterator::MIT_NEED_ALL | \MultipleIterator::MIT_KEYS_ASSOC); $iterator->attachIterator($this->getImageIterator($coverText), 'img'); $iterator->attachIterator($secretText->getIterator(), 'secText'); foreach ($iterator as $item) { $this->encodeItem($item['img'], $coverText, $item['secText']); } return $coverText->save(); }