/**
  * @Then /^I should see following list$/
  */
 public function iShouldSeeFollowingList(TableNode $table)
 {
     /** @var \FSi\Bundle\AdminTranslatableBundle\Behat\Context\Page\Element\Grid $grid */
     $grid = $this->getElement('Grid');
     expect(count($table->getHash()))->toBe($grid->getRowsCount());
     $rowNumber = 1;
     foreach ($table->getHash() as $row) {
         foreach ($row as $columnName => $cellValue) {
             $cell = $grid->getCell($rowNumber, $grid->getColumnPosition($columnName));
             expect($cell->getText())->toBe($cellValue);
         }
         $rowNumber++;
     }
 }
 /**
  * @Then I should see in database:
  */
 public function iShouldSeeInDatabase(TableNode $table)
 {
     $actual = $this->getConnection()->createQueryBuilder()->select('*')->from($this->workingTable)->execute()->fetchAll();
     foreach ($table->getHash() as $key => $expected) {
         PHPUnit_Framework_Assert::assertEquals($expected, $actual[$key]);
     }
 }
Example #3
0
 /**
  * @Given there is following role hierarchy:
  */
 public function thereIsFollowingRoleHierarchy(TableNode $table)
 {
     $repository = $this->getRepository('role');
     $manager = $this->getEntityManager();
     foreach ($repository->findAll() as $existingRole) {
         $manager->remove($existingRole);
     }
     $manager->flush();
     $root = $repository->createNew();
     $root->setCode('root');
     $root->setName('Root');
     $manager->persist($root);
     $manager->flush();
     $roles = array();
     foreach ($table->getHash() as $data) {
         $role = $repository->createNew();
         $role->setCode($data['code']);
         $role->setName($data['name']);
         if (!empty($data['parent'])) {
             $role->setParent($roles[trim($data['parent'])]);
         } else {
             $role->setParent($root);
         }
         if (!empty($data['security roles'])) {
             $securityRoles = array();
             foreach (explode(',', $data['security roles']) as $securityRole) {
                 $securityRoles[] = trim($securityRole);
             }
             $role->setSecurityRoles($securityRoles);
         }
         $roles[$data['code']] = $role;
         $manager->persist($role);
     }
     $manager->flush();
 }
 /**
  * @Then /^I should get the following products after apply the following updater to it:$/
  *
  * @param TableNode $updates
  *
  * @throws \Exception
  */
 public function iShouldGetTheFollowingProductsAfterApplyTheFollowingUpdaterToIt(TableNode $updates)
 {
     $application = $this->getApplicationsForUpdaterProduct();
     $updateCommand = $application->find('pim:product:update');
     $updateCommand->setContainer($this->getMainContext()->getContainer());
     $updateCommandTester = new CommandTester($updateCommand);
     $getCommand = $application->find('pim:product:get');
     $getCommand->setContainer($this->getMainContext()->getContainer());
     $getCommandTester = new CommandTester($getCommand);
     foreach ($updates->getHash() as $update) {
         $username = isset($update['username']) ? $update['username'] : null;
         $updateCommandTester->execute(['command' => $updateCommand->getName(), 'identifier' => $update['product'], 'json_updates' => $update['actions'], 'username' => $username]);
         $expected = json_decode($update['result'], true);
         if (isset($expected['product'])) {
             $getCommandTester->execute(['command' => $getCommand->getName(), 'identifier' => $expected['product']]);
             unset($expected['product']);
         } else {
             $getCommandTester->execute(['command' => $getCommand->getName(), 'identifier' => $update['product']]);
         }
         $actual = json_decode($getCommandTester->getDisplay(), true);
         if (null === $actual) {
             throw new \Exception(sprintf('An error occured during the execution of the update command : %s', $getCommandTester->getDisplay()));
         }
         if (null === $expected) {
             throw new \Exception(sprintf('Looks like the expected result is not valid json : %s', $update['result']));
         }
         $diff = $this->arrayIntersect($actual, $expected);
         assertEquals($expected, $diff);
     }
 }
 /**
  * @Given /^Users exist:$/
  */
 public function usersExist(TableNode $table)
 {
     $usersData = $table->getHash();
     add_filter('send_password_change_email', '__return_false');
     add_filter('send_email_change_email', '__return_false');
     foreach ($usersData as $userData) {
         if (empty($userData['login'])) {
             throw new \InvalidArgumentException('You must provide a user login!');
         }
         $user = get_user_by('login', $userData['login']);
         $data = $this->getUserDataFromTable($userData);
         if ($user) {
             $data['ID'] = $user->ID;
         }
         $result = $user ? wp_update_user($data) : wp_insert_user($data);
         if (is_wp_error($result)) {
             throw new \UnexpectedValueException('User could not be created: ' . $result->get_error_message());
         }
         foreach ($this->getUserMetaDataFromTable($userData) as $key => $value) {
             update_user_meta($user->ID, $key, $value);
         }
     }
     remove_filter('send_password_change_email', '__return_false');
     remove_filter('send_email_change_email', '__return_false');
 }
 /**
  * Defines the marking guide with the provided data, following marking guide's definition grid cells.
  *
  * This method fills the marking guide of the marking guide definition
  * form; the provided TableNode should contain one row for
  * each criterion and each cell of the row should contain:
  * # Criterion name, a.k.a. shortname
  * # Description for students
  * # Description for markers
  * # Max score
  *
  * Works with both JS and non-JS.
  *
  * @When /^I define the following marking guide:$/
  * @throws ExpectationException
  * @param TableNode $guide
  */
 public function i_define_the_following_marking_guide(TableNode $guide)
 {
     $steptableinfo = '| Criterion name | Description for students | Description for markers | Maximum score |';
     if ($criteria = $guide->getHash()) {
         $addcriterionbutton = $this->find_button(get_string('addcriterion', 'gradingform_guide'));
         foreach ($criteria as $index => $criterion) {
             // Make sure the criterion array has 4 elements.
             if (count($criterion) != 4) {
                 throw new ExpectationException('The criterion definition should contain name, description for students and markers, and maximum points. ' . 'Please follow this format: ' . $steptableinfo, $this->getSession());
             }
             // On load, there's already a criterion template ready.
             $shortnamevisible = false;
             if ($index > 0) {
                 // So if the index is greater than 0, we click the Add new criterion button to add a new criterion.
                 $addcriterionbutton->click();
                 $shortnamevisible = true;
             }
             $criterionroot = 'guide[criteria][NEWID' . ($index + 1) . ']';
             // Set the field value for the Criterion name.
             $this->set_guide_field_value($criterionroot . '[shortname]', $criterion['Criterion name'], $shortnamevisible);
             // Set the field value for the Description for students field.
             $this->set_guide_field_value($criterionroot . '[description]', $criterion['Description for students']);
             // Set the field value for the Description for markers field.
             $this->set_guide_field_value($criterionroot . '[descriptionmarkers]', $criterion['Description for markers']);
             // Set the field value for the Max score field.
             $this->set_guide_field_value($criterionroot . '[maxscore]', $criterion['Maximum score']);
         }
     }
 }
Example #7
0
 /**
  * Creates entries provided in the form:
  * | cn    | attribute1    | attribute2 | attributeN |
  * | primary | value1 | value2 | valueN |
  * | ...      | ...        | ...  | ... |
  *
  * @Given /^Ldap entries:$/
  */
 public function ldapEntries(TableNode $entries)
 {
     foreach ($entries->getHash() as $entry) {
         $ldapEntry = new Entry('cn' . '=' . $entry['cn'] . ',' . $this->rootDn, $entry);
         $this->client->getEntryManager()->add($ldapEntry);
     }
 }
 /**
  * @Given Posts exist:
  */
 public function postsExist(TableNode $table)
 {
     $postsData = $table->getHash();
     foreach ($postsData as $postData) {
         $this->processPost($postData);
     }
 }
 /**
  * @Given /^There are published representative news$/
  */
 public function thereArePublishedLeaderNews(TableNode $table)
 {
     /* @var $em EntityManager */
     $em = $this->getEm();
     /* @var $activityService \Civix\CoreBundle\Service\ActivityUpdate */
     $activityService = $this->getMainContext()->getContainer()->get('civix_core.activity_update');
     $hash = $table->getHash();
     $diffSec = 0;
     foreach ($hash as $row) {
         $diffSec++;
         $news = new RepresentativeNews();
         $news->setUser($em->getRepository(Representative::class)->findOneByUsername($row['username']));
         $news->setSubject($row['subject']);
         $news->setPublishedAt(new \DateTime());
         $em->persist($news);
         $em->flush($news);
         $activity = $activityService->publishLeaderNewsToActivity($news);
         $activity->getSentAt()->sub(new \DateInterval('PT' . (count($hash) - $diffSec) . 'S'));
         $activity->setSentAt(clone $activity->getSentAt());
         if (!empty($row['expired_interval_direction'])) {
             $expired = new \DateTime();
             $expired->{$row}['expired_interval_direction'](new \DateInterval($row['expired_interval_value']));
             $activity->setExpireAt($expired);
             $em->flush($activity);
         }
     }
     $result = $em->getRepository(LeaderNewsActivity::class)->findAll();
     Assert::assertTrue(count($result) >= count($hash));
 }
Example #10
0
 /**
  * @Given /^there are following galleries$/
  */
 public function thereAreFollowingGalleries(TableNode $galleries)
 {
     $generator = Factory::create();
     $imagesDir = $this->createGalleryFixturesDir();
     foreach ($galleries->getHash() as $galleryData) {
         $photos = new ArrayCollection();
         for ($i = 0; $i < (int) $galleryData['Photos count']; $i++) {
             $image = $generator->image($imagesDir, 600, 400);
             $imageFile = new UploadedFile($image, basename($image), null, null, null, true);
             $photo = new Photo();
             $photo->setPhoto($imageFile);
             $this->getDoctrine()->getManager()->persist($photo);
             $this->getDoctrine()->getManager()->flush();
             $photos->add($photo);
         }
         $gallery = new Gallery();
         $gallery->setName($galleryData['Name']);
         $gallery->setDescription($galleryData['Description']);
         $gallery->setVisible($galleryData['Visible'] === 'true');
         $gallery->setPhotos($photos);
         $this->getDoctrine()->getManager()->persist($gallery);
         $this->getDoctrine()->getManager()->flush();
         $this->getDoctrine()->getManager()->clear();
     }
     $this->removeFixtures($imagesDir);
 }
Example #11
0
 /**
  * @Then /^I should have a "([^"]*)" style with the following data on the cell with the coordinates "(\d+),(\d+)" in the sheet "(\d+)":$/
  */
 public function iShouldHaveAStyleWithTheFollowingDataOnTheCell($style, $x, $y, $sheetIndex, TableNode $data)
 {
     $phpExcelStyle = $this->getMainContext()->excelOutput->getSheet($sheetIndex)->getStyleByColumnAndRow($x, $y);
     switch ($style) {
         case 'Alignment':
             $style = $phpExcelStyle->getAlignment();
             break;
         case 'Fill':
             $style = $phpExcelStyle->getFill();
             break;
         case 'Font':
             $style = $phpExcelStyle->getFont();
             break;
         default:
             throw new Exception("You must specify a following style : Font, Fill, Alignment, Format");
             break;
     }
     foreach ($data->getHash()[0] as $property => $value) {
         $method = 'get' . ucfirst($property);
         if (method_exists($style, $method)) {
             $rawValue = $style->{$method}();
             if (is_object($rawValue)) {
                 Assert::assertEquals($value, $style->{$method}()->getRGB());
                 continue;
             }
             Assert::assertEquals($value, $style->{$method}());
         }
     }
 }
Example #12
0
 /**
  * @Given There are the following users
  */
 public function thereAreTheFollowingUsers(TableNode $table)
 {
     #var_dump($table->getHash());echo "\n",__METHOD__,':',__LINE__,"\n";die;
     foreach ($table->getHash() as $hash) {
         #$this->createUser($hash);
     }
 }
 /**
  * @Given I should have the following translations for product :product:
  */
 public function assertProductTranslations(Product $product, TableNode $table)
 {
     foreach ($table->getHash() as $data) {
         PHPUnit_Framework_Assert::assertSame($data['title'], $product->getTranslation($data['locale'])->getTitle());
         PHPUnit_Framework_Assert::assertSame($data['description'], $product->getTranslation($data['locale'])->getDescription());
     }
 }
 /**
  * @Given The following people exist:
  */
 public function theFollowingPeopleExist(TableNode $table)
 {
     $hash = $table->getHash();
     foreach ($hash as $row) {
         $this->users[$row['username']] = $this->createUser($row);
     }
 }
Example #15
0
 public function testHashTable()
 {
     $table = new TableNode(array(array('username', 'password'), array('everzet', 'qwerty'), array('antono', 'pa$sword')));
     $this->assertEquals(array(array('username' => 'everzet', 'password' => 'qwerty'), array('username' => 'antono', 'password' => 'pa$sword')), $table->getHash());
     $table = new TableNode(array(array('username', 'password'), array('', 'qwerty'), array('antono', ''), array('', '')));
     $this->assertEquals(array(array('username' => '', 'password' => 'qwerty'), array('username' => 'antono', 'password' => ''), array('username' => '', 'password' => '')), $table->getHash());
 }
Example #16
0
 /**
  * @Given /^I should see display with following fields$/
  */
 public function iShouldSeeDisplayWithFollowingFields(TableNode $table)
 {
     $display = $this->getPage('News display')->getElement('Display');
     foreach ($table->getHash() as $row) {
         expect($display->hasFieldWithName($row['Field name']))->toBe(true);
     }
 }
Example #17
0
 /**
  * @Given /^there are following taxonomies defined:$/
  */
 public function thereAreFollowingTaxonomies(TableNode $table)
 {
     foreach ($table->getHash() as $data) {
         $this->thereIsTaxonomy($data['name'], false);
     }
     $this->getEntityManager()->flush();
 }
 /**
  * Create a new WordPress website from scratch
  *
  * @Given /^\w+ have a vanilla wordpress installation$/
  */
 public function installWordPress(TableNode $table = null)
 {
     global $wp_rewrite;
     $name = "admin";
     $email = "*****@*****.**";
     $password = "******";
     $username = "******";
     if ($table) {
         $hash = $table->getHash();
         $row = $hash[0];
         $name = $row["name"];
         $username = $row["username"];
         $email = $row["email"];
         $password = $row["password"];
     }
     $mysqli = new \Mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
     $value = $mysqli->multi_query(implode("\n", array("DROP DATABASE IF EXISTS " . DB_NAME . ";", "CREATE DATABASE " . DB_NAME . ";")));
     \PHPUnit_Framework_Assert::assertTrue($value);
     require_once ABSPATH . 'wp-admin/includes/upgrade.php';
     wp_install($name, $username, $email, true, '', $password);
     //This is a bit of a hack, we don't care about the notification e-mails here so clear the inbox
     //we run the risk of deleting stuff we want!
     $this->inboxFactory->getInbox($email)->clearInbox();
     $wp_rewrite->init();
     $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/');
 }
Example #19
0
 /**
  * @When /^las siguientes taquillas:$/
  */
 public function lasSiguientesTaquillas(TableNode $table)
 {
     foreach ($table->getHash() as $item) {
         /** @var Locker $locker */
         $locker = $this->getRepository('locker')->createNew();
         $locker->setCode($item['código']);
         $locker->setStatus($this->status[$item['estado']]);
         if ($item['alquilada_a']) {
             $username = $item['alquilada_a'];
             $user = $this->getRepository('user')->findOneBy(['username' => $username]);
             if (!$user) {
                 throw new \Exception('User not found: ' . $username);
             }
             $start = new \DateTime($item['desde'] . ' days');
             $end = new \DateTime($item['hasta'] . ' days midnight');
             $renewable = isset($item['renovable']) ? $item['renovable'] : 'sí';
             /** @var Rental $rental */
             $rental = $this->getRepository('rental')->createNew();
             $rental->setStartAt($start);
             $rental->setEndAt($end);
             $rental->setUser($user);
             $rental->setLocker($locker);
             $rental->setIsRenewable($renewable === 'sí');
             $locker->setOwner($user);
             $locker->setStatus(Locker::RENTED);
             $this->getEntityManager()->persist($rental);
         }
         $this->getEntityManager()->persist($locker);
     }
     $this->getEntityManager()->flush();
 }
 /**
  * @Given the following users exist:
  */
 public function theFollowingUsersExist(TableNode $table)
 {
     /** @var \Ma27\ApiKeyAuthenticationBundle\Model\Password\PasswordHasherInterface $hasher */
     $hasher = $this->getContainer()->get('ma27_api_key_authentication.password.strategy');
     $em = $this->getEntityManager();
     $userRole = $em->getRepository('Account:Role')->findOneBy(['role' => 'ROLE_USER']);
     $adminRole = $em->getRepository('Account:Role')->findOneBy(['role' => 'ROLE_ADMIN']);
     foreach ($table->getHash() as $row) {
         $user = User::create($row['username'], $hasher->generateHash($row['password']), $row['email']);
         if (isset($row['user_id'])) {
             // there are cases where the user id should be known
             $r = new \ReflectionProperty(User::class, 'id');
             $r->setAccessible(true);
             $r->setValue($user, $row['user_id']);
         }
         if (isset($row['activation_date'])) {
             $user->getPendingActivation()->setActivationDate(new \DateTime($row['activation_date']));
         }
         if (!(isset($row['is_non_activated']) && $row['is_non_activated'] === 'true')) {
             $user->setState(User::STATE_APPROVED);
             // roles only allowed for approved users
             $user->addRole($userRole);
             if (isset($row['is_admin']) && $row['is_admin'] === 'true') {
                 $user->addRole($adminRole);
             }
         } else {
             if (isset($row['activation_key'])) {
                 $user->setActivationKey($row['activation_key']);
             }
         }
         $em->persist($user);
     }
     $em->flush();
 }
 /**
  * @Given the following :entityName entities exist:
  */
 public function theFollowingEntitiesExist($entityName, TableNode $table)
 {
     /** @var EntityManager $doctrine */
     $doctrine = $this->get('doctrine')->getManager();
     $meta = $doctrine->getClassMetadata($entityName);
     $rows = [];
     $hash = $table->getHash();
     foreach ($hash as $row) {
         $id = $row['id'];
         unset($row['id']);
         foreach ($row as $property => &$value) {
             $propertyName = Inflector::camelize($property);
             $fieldType = $meta->getTypeOfField($propertyName);
             switch ($fieldType) {
                 case 'array':
                 case 'json_array':
                     $value = json_decode($value, true);
                     break;
                 case 'datetime':
                     $value = new \DateTime($value);
                     break;
             }
         }
         $rows[$id] = $row;
     }
     $this->persistEntities($entityName, $rows);
 }
Example #22
0
 /**
  * Sets the specified site settings.
  * A table with | Setting label | value | is expected.
  *
  * @Given /^the following site settings are set:$/
  * @param TableNode $table
  * @throws SystemException
  */
 public function site_settings_set(TableNode $table)
 {
     $settings = array();
     foreach ($table->getHash() as $sitesetting) {
         $settings[$sitesetting['field']] = $sitesetting['value'];
     }
     // Validate the settings
     $allowsettings = array('sitename', 'lang', 'country', 'theme', 'dropdownmenu', 'homepageinfo', 'userscanchooseviewthemes', 'remoteavatars', 'userscanhiderealnames', 'searchusernames', 'searchuserspublic', 'anonymouscomments', 'loggedinprofileviewaccess', 'staffreports', 'staffstats', 'userscandisabledevicedetection', 'masqueradingreasonrequired', 'masqueradingnotified', 'showprogressbar', 'exporttoqueue', 'defaultmultipleblogs', 'searchplugin', 'creategroups', 'createpublicgroups', 'allowgroupcategories', 'institutionexpirynotification', 'institutionautosuspend', 'requireregistrationconfirm', 'allowpublicviews', 'allowpublicprofiles', 'allowanonymouspages', 'generatesitemap', 'showselfsearchsideblock', 'showtagssideblock', 'tagssideblockmaxtags', 'viewmicroheaders', 'showonlineuserssideblock', 'onlineuserssideblockmaxusers', 'licensemetadata', 'licenseallowcustom', 'allowmobileuploads', 'wysiwyg', 'sitefilesaccess', 'watchlistnotification_delay', 'skins');
     // if public views are disabled, sitemap generation must also be disabled.
     if (empty($settings['allowpublicviews'])) {
         $settings['generatesitemap'] = false;
     } else {
         // Ensure allowpublicprofiles is set as well
         $settings['allowpublicprofiles'] = 1;
     }
     // Update site settings
     $oldsearchplugin = get_config('searchplugin');
     $oldlanguage = get_config('lang');
     $oldtheme = get_config('theme');
     foreach ($allowsettings as $setting) {
         if (isset($settings[$setting]) && !set_config($setting, $settings[$setting])) {
             throw new SystemException("Can not set the option \"{$setting}\" to \"{$settings[$setting]}\"");
         }
     }
     if (isset($settings['lang']) && $oldlanguage != $settings['lang']) {
         safe_require('artefact', 'file');
         ArtefactTypeFolder::change_public_folder_name($oldlanguage, $settings['lang']);
     }
 }
Example #23
0
 /**
  * @Given the following html response contents:
  *
  * @param TableNode $table
  */
 public function theFollowingHtmlResponses(TableNode $table)
 {
     foreach ($table->getHash() as $item) {
         $this->responseHTMLs[] = file_get_contents(__DIR__ . '/../../Resources/Fixtures/' . $item['content']);
     }
     $this->buildMockHttpClientProvider();
 }
Example #24
0
 /**
  * @Given /^groups memberships:$/
  */
 public function groupsMemberships(TableNode $table)
 {
     $memberships = $table->getHash();
     foreach ($memberships as $membership) {
         // Find group node.
         $group_node = $membership['group'];
         foreach ($this->nodes as $node) {
             if ($node->type == 'group' && $node->title == $group_node) {
                 $group_node = $node;
             }
         }
         // Subscribe nodes and users to group.
         if (isset($membership['members'])) {
             $members = explode(",", $membership['members']);
             foreach ($this->users as $user) {
                 if (in_array($user->name, $members)) {
                     og_group('node', $group_node->nid, array('entity' => $user, 'entity_type' => 'user', "membership type" => OG_MEMBERSHIP_TYPE_DEFAULT));
                     // Patch till i figure out why rules are not firing.
                     if ($user->name == 'editor') {
                         og_role_grant('node', $group_node->nid, $user->uid, 4);
                     }
                 }
             }
         }
         if (isset($membership['nodes'])) {
             $content = explode(",", $membership['nodes']);
             foreach ($this->nodes as $node) {
                 if ($node->type != 'group' && in_array($node->title, $content)) {
                     og_group('node', $group_node->nid, array('entity' => $node, 'entity_type' => 'node', 'state' => OG_STATE_ACTIVE));
                 }
             }
         }
     }
 }
Example #25
0
 /**
  * @Given /^there are the following ([^"]*):$/
  */
 public function thereAreFollowingResources($resource, TableNode $table)
 {
     foreach ($table->getHash() as $data) {
         $this->thereIsResource($resource, $data, false);
     }
     $this->getEntityManager()->flush();
 }
Example #26
0
 /**
  * Creates multiple group memberships.
  *
  * Provide group membership data in the following format:
  *
  * | user  | group     | role on group        | membership status |
  * | Foo   | The Group | administrator member | Active            |
  *
  * @Given group memberships:
  */
 public function addGroupMemberships(TableNode $groupMembershipsTable)
 {
     foreach ($groupMembershipsTable->getHash() as $groupMembershipHash) {
         if (isset($groupMembershipHash['group']) && isset($groupMembershipHash['user'])) {
             $group = $this->getGroupByName($groupMembershipHash['group']);
             $user = user_load_by_name($groupMembershipHash['user']);
             // Add user to group with the proper group permissions and status
             if ($group && $user) {
                 // Add the user to the group
                 og_group("node", $group->nid->value(), array("entity type" => "user", "entity" => $user, "membership type" => OG_MEMBERSHIP_TYPE_DEFAULT, "state" => $this->getMembershipStatusByName($groupMembershipHash['membership status'])));
                 // Grant user roles
                 $group_role = $this->getGroupRoleByName($groupMembershipHash['role on group']);
                 og_role_grant("node", $group->nid->value(), $user->uid, $group_role);
             } else {
                 if (!$group) {
                     throw new \Exception(sprintf("No group was found with name %s.", $groupMembershipHash['group']));
                 }
                 if (!$user) {
                     throw new \Exception(sprintf("No user was found with name %s.", $groupMembershipHash['user']));
                 }
             }
         } else {
             throw new \Exception(sprintf("The group and user information is required."));
         }
     }
 }
Example #27
0
 /**
  * @Given /^the following promotions exist:$/
  * @Given /^there are following promotions configured:$/
  */
 public function theFollowingPromotionsExist(TableNode $table)
 {
     $manager = $this->getEntityManager();
     $factory = $this->getFactory('promotion');
     foreach ($table->getHash() as $data) {
         $promotion = $factory->createNew();
         $promotion->setName($data['name']);
         $promotion->setDescription($data['description']);
         $promotion->setCode($data['code']);
         if (array_key_exists('usage limit', $data) && '' !== $data['usage limit']) {
             $promotion->setUsageLimit((int) $data['usage limit']);
         }
         if (array_key_exists('used', $data) && '' !== $data['used']) {
             $promotion->setUsed((int) $data['used']);
         }
         if (array_key_exists('starts', $data)) {
             $promotion->setStartsAt(new \DateTime($data['starts']));
         }
         if (array_key_exists('ends', $data)) {
             $promotion->setEndsAt(new \DateTime($data['ends']));
         }
         $manager->persist($promotion);
     }
     $manager->flush();
 }
 /**
  * Add these posts to this wordpress installation
  * Example: Given there are posts
  *              | post_title      | post_content              | post_status | post_author | post_date           |
  *              | Just my article | The content of my article | publish     | 1           | 2016-10-11 08:30:00 |
  *
  *
  * @Given /^there are posts$/
  */
 public function thereArePosts(TableNode $table)
 {
     foreach ($table->getHash() as $postData) {
         $postData = $this->parseArgs($postData);
         $this->insert($postData);
     }
 }
Example #29
0
 /**
  * @Given /^there are following tax categories:$/
  * @Given /^the following tax categories exist:$/
  */
 public function thereAreTaxCategories(TableNode $table)
 {
     foreach ($table->getHash() as $data) {
         $this->thereIsTaxCategory($data['name'], false);
     }
     $this->getEntityManager()->flush();
 }
 /**
  *
  * Example
  *    Then I should see the following actions
  *      | actions    |
  *      | Edit       |
  *      | Quick Edit |
  *      | Trash      |
  *      | View       |
  *
  * @Then I should see the following row actions
  */
 public function iShouldSeeTheFollowingRowActions(TableNode $table)
 {
     $rows_actions = $this->getSession()->getPage()->findAll('css', '.wp-list-table tr .row-actions');
     $action_node = false;
     foreach ($rows_actions as $row_actions) {
         if ($row_actions->isVisible()) {
             $action_node = $row_actions;
             break;
         }
     }
     if (!$action_node) {
         throw new \Exception('Row actions not visible');
     }
     $action_nodes = $action_node->findAll('css', 'span');
     $hash = $table->getHash();
     foreach ($hash as $n => $expected_row) {
         if (!isset($action_nodes[$n])) {
             throw new \Exception(sprintf('Expected "%s", but there is no action at index %d.', $expected_row['actions'], $n));
         } elseif (trim($action_nodes[$n]->getText(), ' |') != $expected_row['actions']) {
             throw new \Exception(sprintf('Expected "%s" at index %d. Instead found "%s".', $expected_row['actions'], $n, trim($action_nodes[$n]->getText(), ' |')));
         }
     }
     if (count($hash) !== count($action_nodes)) {
         throw new \Exception(sprintf('Expected %d actions but found %d', count($hash), count($action_nodes)));
     }
 }