/** * @Given there are the following Content Type Groups: * * Make sure that content type groups in the provided table exist, by identifier. Example: * | group | * | testContentTypeGroup1 | * | testContentTypeGroup2 | * | testContentTypeGroup3 | */ public function ensureContentTypeGroupsExists(TableNode $table) { $contentTypeGroups = $table->getTable(); array_shift($contentTypeGroups); foreach ($contentTypeGroups as $contentTypeGroup) { $this->ensureContentTypeGroupExists($contentTypeGroup[0]); } }
/** * @Given /^Truncated tables$/ * @param TableNode $table */ public function truncatedTables(TableNode $table) { foreach ($table->getTable() as $tableNames) { foreach ($tableNames as $tableName) { $this->clearTable($tableName); } } }
/** * @When I call the :operation operation * @When I call the :operation operation with */ public function iCallTheOperation($operation, TableNode $table = null) { $this->result = null; $args = []; if ($table) { foreach ($table->getTable() as $row) { $args[$row[0]] = $row[1]; } } $this->result = call_user_func([$this->sdk, $operation], $args); }
/** * @param TableNode $table * @return TableNode */ protected function transformTableNode(TableNode $table) { $tempList = $table->getTable(); foreach ($tempList as $key => $row) { foreach ($row as $columnKey => $column) { $newValue = $this->transformValue($column); $tempList[$key][$columnKey] = $newValue; } } return new TableNode($tempList); }
/** * @When I call the :operation operation * @When I call the :operation operation with */ public function iCallTheOperation($operation, TableNode $table = null) { $this->result = null; $args = []; if ($table) { foreach ($table->getTable() as $row) { if (isset($query)) { $query .= "&"; } else { $query = ''; } $query .= $row[0] . '=' . $row[1]; } if ($query) { parse_str($query, $args); } } try { $this->result = call_user_func([$this->sdk, $operation], $args); } catch (CommandClientException $e) { $this->exception = $e; } }
/** * @Then I should have the application */ public function applicationExists(TableNode $table) { /** @var ApplicationManager $applicationManager */ $applicationManager = self::$application->getServiceManager()->get('application/application-manager'); $data = []; foreach ($table->getTable() as $row) { $data[$row[0]] = $row[1]; } $application = $applicationManager->get($data['name']); \PHPUnit_Framework_Assert::assertInstanceOf('Continuous\\DeployAgent\\Application\\Application', $application); foreach ($data as $property => $value) { switch ($property) { case 'pipeline': $property = 'reference'; case 'token': case 'repositoryProvider': case 'repository': \PHPUnit_Framework_Assert::assertAttributeEquals($value, $property, $application->getProvider()); break; case 'provider': $provider = self::$application->getServiceManager()->get('provider/' . $value); \PHPUnit_Framework_Assert::assertAttributeInstanceOf(get_class($provider), $property, $application); break; default: \PHPUnit_Framework_Assert::assertAttributeEquals($value, $property, $application); } } }
/** * @Then The following headers should be set * @param \Behat\Gherkin\Node\TableNode $table * @throws \Exception */ public function theFollowingHeadersShouldBeSet(\Behat\Gherkin\Node\TableNode $table) { foreach ($table->getTable() as $header) { $headerName = $header[0]; $expectedHeaderValue = $header[1]; $returnedHeader = $this->response->getHeader($headerName); if ($returnedHeader !== $expectedHeaderValue) { throw new \Exception(sprintf("Expected value '%s' for header '%s', got '%s'", $expectedHeaderValue, $headerName, $returnedHeader)); } } }
/** * @Then User with name :username has the following fields: * @Then User with name :username exists with the following fields: * * Checks that user ':username' exists with the values provided in the field/value table. example: * | Name | value | * | email | testuser@ez.no | * | password | testuser | * | first_name | Test | * | last_name | User | */ public function assertUserWithNameExistsWithFields($username, TableNode $table) { Assertion::assertTrue($this->checkUserExistenceByUsername($username), "Couldn't find User with name '{$username}'."); $user = $this->userService->loadUserByLogin($username); $fieldsTable = $table->getTable(); array_shift($fieldsTable); $updateFields = array(); foreach ($fieldsTable as $fieldRow) { $fieldName = $fieldRow[0]; $expectedValue = $fieldRow[1]; switch ($fieldName) { case 'email': $fieldValue = $user->email; break; case 'password': $fieldValue = $user->passwordHash; $expectedValue = $this->createPasswordHash($username, $expectedValue, $user->hashAlgorithm); break; default: $fieldValue = $user->getFieldValue($fieldName); } Assertion::assertEquals($expectedValue, $fieldValue, "Field '{$fieldName}' did not contain expected value '{$expectedValue}'."); } }
/** * @Then The order totals should be as follows */ public function theOrderTotalsShouldBeAsFollows(TableNode $table) { $orderTotals = $this->_getOrderTotals(); $data = $table->getTable(); foreach ($data as $expectedTotals) { if (count($expectedTotals) !== 2) { throw new \Exception('Malformed table. Each row should have two columns'); } $expectedValue = array_pop($expectedTotals); $expectedKey = array_pop($expectedTotals); if (!isset($orderTotals[$expectedKey])) { throw new \Exception("Expected to find a total of {$expectedKey} but this was not found on the page"); } if ($orderTotals[$expectedKey] !== $expectedValue) { throw new \Exception("Expected {$expectedKey} to have a value of {$expectedValue}, found {$orderTotals[$expectedKey]}"); } } }
/** * @Given there are the following User Groups: * * Make sure that user groups in the provided table exist in their respective parent group. Example: * | childGroup | parentGroup | * | testUserGroup1 | Members | # should create. * | testUserGroup1 | Editors | # should create. * | testUserGroup3 | Test Parent | # parent and child should be created. * | innerGroup3-1 | testUserGroup3 | # should be created inside previous. */ public function iHaveTheFollowingUserGroups(TableNode $table) { $userGroups = $table->getTable(); array_shift($userGroups); foreach ($userGroups as $userGroup) { $this->getUserGroupManager()->ensureUserGroupExists($userGroup[0], $userGroup[1]); } }
public function testGetTable() { $table = new TableNode($a = array(5 => array('username', 'password'), 10 => array('everzet', 'qwerty'), 13 => array('antono', 'pa$sword'))); $this->assertEquals($a, $table->getTable()); }
/** * Helper method to transform column names in row tables. * * @param \Behat\Gherkin\Node\TableNode $table_node * The table to transform. * @param array $aliases * An associative array of aliases that are uses for the column names. Keyed * by alias, and with the transformed string as value. * * @return \Behat\Gherkin\Node\TableNode * The transformed table * * @see self::transformArticleNodeTable() */ protected function transformRowTable(TableNode $table_node, array $aliases) { $table = $table_node->getTable(); array_walk($table, function (&$row) use($aliases) { // The first column of the row contains the field names. Replace the // aliased field name with the machine name if it exists. if (array_key_exists($row[0], $aliases)) { $row[0] = $aliases[$row[0]]; } }); return new TableNode($table); }
/** * Transforms human readable field names into machine names. * * This is used in field_handlers.feature for testing if human readable names * can be used instead of machine names in tests. * * @param TableNode $post_table * The original table. * * @return TableNode * The transformed table. * * @Transform rowtable:title,body,reference,date,links,select,address */ public function transformPostContentTable(TableNode $post_table) { $aliases = array('reference' => 'field_post_reference', 'date' => 'field_post_date', 'links' => 'field_post_links', 'select' => 'field_post_select', 'address' => 'field_post_address'); $table = $post_table->getTable(); array_walk($table, function (&$row) use($aliases) { // The first column of the row contains the field names. Replace the // human readable field name with the machine name if it exists. if (array_key_exists($row[0], $aliases)) { $row[0] = $aliases[$row[0]]; } }); return new TableNode($table); }
/** * Transforms long address field columns into shorter aliases. * * This is used in field_handlers.feature for testing if lengthy field:column * combinations can be shortened to more human friendly aliases. * * @Transform table:name,mail,street,city,postcode,country */ public function castUsersTable(TableNode $user_table) { $aliases = ['country' => 'field_post_address:country', 'city' => 'field_post_address:locality', 'street' => 'field_post_address:thoroughfare', 'postcode' => 'field_post_address:postal_code']; // The first row of the table contains the field names. $table = $user_table->getTable(); reset($table); $first_row = key($table); // Replace the aliased field names with the actual ones. foreach ($table[$first_row] as $key => $alias) { if (array_key_exists($alias, $aliases)) { $table[$first_row][$key] = $aliases[$alias]; } } return new TableNode($table); }
/** * Tests if a link is present in the breadcrumbs. * @Then the breadcrumb has the following links: */ public function breadcrumbHasTheFollowingLinks(TableNode $table) { foreach ($table->getTable() as $breadcrumbItem) { $text = $breadcrumbItem[0]; $url = $breadcrumbItem[1]; // this is not a link (the current page) if ($url === 'null') { $query = sprintf('//ul[@id="wo-breadcrumbs"]/li/span[text()="%s"]', $text); } else { $query = sprintf('//ul[@id="wo-breadcrumbs"]/li/a[@href="%s"]/span[text()="%s"]', $url, $text); } Assertion::assertCount(1, $this->getXpath()->findXpath($query)); } }
/** * @Then :fileName shared by :sharingUser has the following tags for :user * @param string $fileName * @param string $sharingUser * @param string $user * @param TableNode $table * @throws \Exception */ public function sharedByHasTheFollowingTagsFor($fileName, $sharingUser, $user, TableNode $table) { $loadedExpectedTags = $table->getTable(); $expectedTags = []; foreach ($loadedExpectedTags as $expected) { $expectedTags[] = $expected[0]; } // Get the real tags try { $request = $this->client->createRequest('PROPFIND', $this->baseUrl . '/remote.php/dav/systemtags-relations/files/' . $this->getFileIdForPath($fileName, $sharingUser), ['auth' => [$user, $this->getPasswordForUser($user)], 'body' => '<?xml version="1.0"?> <d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns"> <d:prop> <oc:id /> <oc:display-name /> <oc:user-visible /> <oc:user-assignable /> </d:prop> </d:propfind>']); $this->response = $this->client->send($request)->getBody()->getContents(); } catch (\GuzzleHttp\Exception\ClientException $e) { $this->response = $e->getResponse(); } preg_match_all('/\\<oc:display-name\\>(.*)\\<\\/oc:display-name\\>/', $this->response, $realTags); $realTags = array_filter($realTags); $expectedTags = array_filter($expectedTags); foreach ($expectedTags as $key => $row) { foreach ($realTags as $tag) { foreach ($tag as $index => $foo) { if ($tag[$index] === $row) { unset($expectedTags[$key]); } } } } if (count($expectedTags) !== 0) { throw new \Exception('Not all tags found.'); } }
/** * @When /^I fill in (.+) form with:$/ */ public function whenIFillInFormWith($base, TableNode $table) { $page = $this->getSession()->getPage(); foreach ($table->getTable() as $item) { list($name, $value) = $item; $field = $this->findField($base, $name); $fieldName = $field->getAttribute('name'); if ($name == 'machine' || $name == 'game') { $key = $name == 'machine' ? 'username' : 'name'; $entity = $this->findOneBy($name, array($key => $value)); $value = $entity->getId(); } if ($field->getTagName() == 'select') { $this->selectOption($fieldName, $value); } elseif ($field->getAttribute('type') == 'checkbox') { $this->fillCheckbox($fieldName, $value); } elseif ($field->getAttribute('type') == 'radio') { $this->fillRadio($fieldName, $value); } else { $this->fillField($fieldName, $value); } } }