Exemplo n.º 1
0
 /**
  * @param int $width
  * @param int $height
  * @param string $extension
  * @return string
  */
 private function buildFolderPath($width, $height, $extension)
 {
     if (null === ($disposition = Image::resolveDisposition($width, $height))) {
         $disposition = Faker::randomElement([Image::LANDSCAPE, Image::PORTRAIT]);
     }
     return sprintf('%s/%s/%s', $this->folder, $disposition, $extension);
 }
Exemplo n.º 2
0
 public function testInsertAndFindAll()
 {
     $id1 = (int) \Faker\Provider\Base::randomNumber(5);
     $faker = \Faker\Factory::create();
     $objectToInsert1 = new \test\data\Customer();
     $objectToInsert1->id = $id1;
     $objectToInsert1->name = $faker->name;
     $objectToInsert1->contacts = ['telephone1' => 123456, 'telephone2' => 345678, 'telephone3' => 345678];
     $objectToInsert1->prices = [1000000, 1000000, 1000000, 1000000];
     $objectToInsert1->kids = ['Alice', 'Billy', 'Charlie'];
     $this->assertTrue($objectToInsert1->save(false));
     $objectsFromFind = \test\data\Customer::findAll(['id' => [$id1]]);
     /* @var $objectFromFind data\Customer */
     $this->assertEquals(1, count($objectsFromFind));
     $id2 = (int) \Faker\Provider\Base::randomNumber(5);
     $objectToInsert2 = new \test\data\Customer();
     $objectToInsert2->id = $id2;
     $objectToInsert2->name = $faker->name;
     $objectToInsert2->contacts = ['telephone2' => 223456, 'telephone2' => 345678, 'telephone3' => 345678];
     $objectToInsert2->prices = [2000000, 2000000, 2000000, 2000000];
     $objectToInsert2->kids = ['Alice', 'Billy', 'Charlie'];
     $this->assertTrue($objectToInsert2->save(false));
     $objectsFromFind2 = \test\data\Customer::findAll(['id' => [$id1, $id2]]);
     /* @var $objectFromFind data\Customer */
     $this->assertEquals(2, count($objectsFromFind2));
     $this->assertTrue($objectsFromFind2[0]->id = $id1 || ($objectsFromFind2[0]->id = $id2));
 }
Exemplo n.º 3
0
 /**
  * @param \Faker\Generator $generator
  * @param Mandango $mandango
  * @return array
  */
 public function guessColumnFormatters(\Faker\Generator $generator, Mandango $mandango)
 {
     $formatters = array();
     $nameGuesser = new \Faker\Guesser\Name($generator);
     $columnTypeGuesser = new \Faker\ORM\Mandango\ColumnTypeGuesser($generator);
     $metadata = $mandango->getMetadata($this->class);
     // fields
     foreach ($metadata['fields'] as $fieldName => $field) {
         if ($formatter = $nameGuesser->guessFormat($fieldName)) {
             $formatters[$fieldName] = $formatter;
             continue;
         }
         if ($formatter = $columnTypeGuesser->guessFormat($field)) {
             $formatters[$fieldName] = $formatter;
             continue;
         }
     }
     // references
     foreach (array_merge($metadata['referencesOne'], $metadata['referencesMany']) as $referenceName => $reference) {
         if (!isset($reference['class'])) {
             continue;
         }
         $referenceClass = $reference['class'];
         $formatters[$referenceName] = function ($insertedEntities) use($referenceClass) {
             if (isset($insertedEntities[$referenceClass])) {
                 return Base::randomElement($insertedEntities[$referenceClass]);
             }
         };
     }
     return $formatters;
 }
Exemplo n.º 4
0
 /**
  * @param string|null $type If specified, return the type value. See {@see User::getAllowedTypes()} to see valid
  *                          type names; if is invalid will return en empty array. Otherwise return an array with a
  *                          random of types.
  *
  * @return array Array of user types.
  */
 public function userTypes($type = null)
 {
     $allowedTypes = User::getAllowedTypes();
     if (null === $type) {
         return BaseProvider::randomElements($allowedTypes, BaseProvider::numberBetween(1, count($allowedTypes)));
     }
     return isset($allowedTypes[$type]) ? [$allowedTypes[$type]] : [];
 }
 /**
  * {@inheritdoc}
  *
  * @param FixtureMatchReferenceValue $value
  *
  * @throws UnresolvableValueException
  */
 public function resolve(ValueInterface $value, FixtureInterface $fixture, ResolvedFixtureSet $fixtureSet, array $scope, GenerationContext $context) : ResolvedValueWithFixtureSet
 {
     if (null === $this->resolver) {
         throw ResolverNotFoundExceptionFactory::createUnexpectedCall(__METHOD__);
     }
     $possibleIds = $this->getSuitableIds($value, $fixtureSet);
     $id = Base::randomElement($possibleIds);
     if (null === $id) {
         throw UnresolvableValueExceptionFactory::createForNoFixtureOrObjectMatchingThePattern($value);
     }
     return $this->resolver->resolve(new FixtureReferenceValue($id), $fixture, $fixtureSet, $scope, $context);
 }
Exemplo n.º 6
0
 /**
  * @param ColumnMap $columnMap
  * @return bool
  */
 protected function isColumnBehavior(ColumnMap $columnMap)
 {
     foreach ($columnMap->getTable()->getBehaviors() as $name => $params) {
         $columnName = Base::toLower($columnMap->getName());
         switch ($name) {
             case 'nested_set':
                 $columnNames = array($params['left_column'], $params['right_column'], $params['level_column']);
                 if (in_array($columnName, $columnNames)) {
                     return true;
                 }
                 break;
             case 'timestampable':
                 $columnNames = array($params['create_column'], $params['update_column']);
                 if (in_array($columnName, $columnNames)) {
                     return true;
                 }
                 break;
         }
     }
     return false;
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $imagine = new Imagine();
     $width = $input->getOption('width') ?: Faker::numberBetween(200, 1200);
     $height = $input->getOption('height') ?: Faker::numberBetween(200, 1200);
     $extension = $input->getOption('extension') ?: Faker::randomElement($this->getAvailableExtensions());
     $selector = new Selector($input->getOption('samples'));
     $images = $selector->select($width, $height, $extension);
     $filter = array_filter($images, function (Image $image) use($width, $height) {
         return $width * $height >= $image->getPixels();
     });
     if (true === empty($filter)) {
         $image = Faker::randomElement($images);
     } else {
         $image = Faker::randomElement($filter);
     }
     $transformed = tempnam(sys_get_temp_dir(), uniqid());
     $transformation = new Transformation();
     $transformation->thumbnail(new Box($width, $height), ImageInterface::THUMBNAIL_OUTBOUND)->save($transformed);
     $transformation->apply($imagine->open($image->getPath()));
     $this->getFormatter($input->getOption('formatter'))->output(new Image($transformed), $output);
 }
Exemplo n.º 8
0
 /**
  * From range return a random Integer
  * Providing the $elements param will limit the returning integer to the total number of elements
  *
  * @param  array|int $qty   The range or integer
  * @param  null|int|array $elements {
  *      @example null  Will not limit the Range to a maximum int
  *      @example int   Limits the range to this maximum
  *      @example array Counts the elements in array and limit to that
  * }
  * @return int
  */
 public function get_qty_from_range($range, $total = null)
 {
     if (is_array($range)) {
         // Remove non-wanted items
         $range = array_filter($range);
         // Grabs Min
         $min = reset($range);
         // Grabs Max if range has 2 elements
         if (count($range) > 1) {
             $max = end($range);
         } else {
             // Otherwise just set qty to the Min
             $qty = $min;
         }
     } elseif (is_numeric($range)) {
         // If we have a numeric we just set it
         $qty = $range;
     } else {
         // All the other cases are a qty 0
         return 0;
     }
     // Now we treat the Range and select a random number
     if (!isset($qty)) {
         $qty = Faker\Provider\Base::numberBetween($min, $max);
     }
     // If an array for the total was provided, turn it to a integer
     if (is_array($total)) {
         $total = count($total);
     }
     // If we have a numeric total, make sure we don't go over that
     if (is_numeric($total)) {
         $qty = min($qty, $total);
     }
     // We just make sure we are dealing with a absolute number
     return absint($qty);
 }
Exemplo n.º 9
0
 /**
  * Transforms a basic regular expression into a random string satisfying the expression.
  *
  * @example $faker->regexify('[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}'); // sm0@y8k96a.ej
  *
  * Regex delimiters '/.../' and begin/end markers '^...$' are ignored.
  *
  * Only supports a small subset of the regex syntax. For instance,
  * unicode, negated classes, unbouned ranges, subpatterns, back references,
  * assertions, recursive patterns, and comments are not supported. Escaping
  * support is extremely fragile.
  *
  * This method is also VERY slow. Use it only when no other formatter
  * can generate the fake data you want. For instance, prefer calling
  * `$faker->email` rather than `regexify` with the previous regular
  * expression.
  *
  * Also note than `bothify` can probably do most of what this method does,
  * but much faster. For instance, for a dummy email generation, try
  * `$faker->bothify('?????????@???.???')`.
  *
  * @see https://github.com/icomefromthenet/ReverseRegex for a more robust implementation
  *
  * @param string $regex A regular expression (delimiters are optional)
  * @return string
  */
 public static function regexify($regex = '')
 {
     // ditch the anchors
     $regex = preg_replace('/^\\/?\\^?/', '', $regex);
     $regex = preg_replace('/\\$?\\/?$/', '', $regex);
     // All {2} become {2,2}
     $regex = preg_replace('/\\{(\\d+)\\}/', '{\\1,\\1}', $regex);
     // Single-letter quantifiers (?, *, +) become bracket quantifiers ({0,1}, {0,rand}, {1, rand})
     $regex = preg_replace('/(?<!\\\\)\\?/', '{0,1}', $regex);
     $regex = preg_replace('/(?<!\\\\)\\*/', '{0,' . static::randomDigitNotNull() . '}', $regex);
     $regex = preg_replace('/(?<!\\\\)\\+/', '{1,' . static::randomDigitNotNull() . '}', $regex);
     // [12]{1,2} becomes [12] or [12][12]
     $regex = preg_replace_callback('/(\\[[^\\]]+\\])\\{(\\d+),(\\d+)\\}/', function ($matches) {
         return str_repeat($matches[1], Base::randomElement(range($matches[2], $matches[3])));
     }, $regex);
     // (12|34){1,2} becomes (12|34) or (12|34)(12|34)
     $regex = preg_replace_callback('/(\\([^\\)]+\\))\\{(\\d+),(\\d+)\\}/', function ($matches) {
         return str_repeat($matches[1], Base::randomElement(range($matches[2], $matches[3])));
     }, $regex);
     // A{1,2} becomes A or AA or \d{3} becomes \d\d\d
     $regex = preg_replace_callback('/(\\\\?.)\\{(\\d+),(\\d+)\\}/', function ($matches) {
         return str_repeat($matches[1], Base::randomElement(range($matches[2], $matches[3])));
     }, $regex);
     // (this|that) becomes 'this' or 'that'
     $regex = preg_replace_callback('/(?<!\\\\)\\((.*?)\\)/', function ($matches) {
         return Base::randomElement(explode('|', str_replace(array('(', ')'), '', $matches[1])));
     }, $regex);
     // All A-F inside of [] become ABCDEF
     $regex = preg_replace_callback('/\\[([^\\]]+)\\]/', function ($matches) {
         return '[' . preg_replace_callback('/(\\w|\\d)\\-(\\w|\\d)/', function ($range) {
             return join(range($range[1], $range[2]), '');
         }, $matches[1]) . ']';
     }, $regex);
     // All [ABC] become B (or A or C)
     $regex = preg_replace_callback('/\\[([^\\]]+)\\]/', function ($matches) {
         return Base::randomElement(str_split($matches[1]));
     }, $regex);
     // replace \d with number and \w with letter and . with ascii
     $regex = preg_replace_callback('/\\\\w/', 'static::randomLetter', $regex);
     $regex = preg_replace_callback('/\\\\d/', 'static::randomDigit', $regex);
     $regex = preg_replace_callback('/(?<!\\\\)\\./', 'static::randomAscii', $regex);
     // remove remaining backslashes
     $regex = str_replace('\\', '', $regex);
     // phew
     return $regex;
 }
Exemplo n.º 10
0
 /**
  * @param string $name
  * @param int|null $size Length of field, if known
  * @return callable
  */
 public function guessFormat($name, $size = null)
 {
     $name = Base::toLower($name);
     $generator = $this->generator;
     if (preg_match('/^is[_A-Z]/', $name)) {
         return function () use($generator) {
             return $generator->boolean;
         };
     }
     if (preg_match('/(_a|A)t$/', $name)) {
         return function () use($generator) {
             return $generator->dateTime;
         };
     }
     switch (str_replace('_', '', $name)) {
         case 'firstname':
             return function () use($generator) {
                 return $generator->firstName;
             };
         case 'lastname':
             return function () use($generator) {
                 return $generator->lastName;
             };
         case 'username':
         case 'login':
             return function () use($generator) {
                 return $generator->userName;
             };
         case 'email':
         case 'emailaddress':
             return function () use($generator) {
                 return $generator->email;
             };
         case 'phonenumber':
         case 'phone':
         case 'telephone':
         case 'telnumber':
             return function () use($generator) {
                 return $generator->phoneNumber;
             };
         case 'address':
             return function () use($generator) {
                 return $generator->address;
             };
         case 'city':
         case 'town':
             return function () use($generator) {
                 return $generator->city;
             };
         case 'streetaddress':
             return function () use($generator) {
                 return $generator->streetAddress;
             };
         case 'postcode':
         case 'zipcode':
             return function () use($generator) {
                 return $generator->postcode;
             };
         case 'state':
             return function () use($generator) {
                 return $generator->state;
             };
         case 'county':
             if ($this->generator->locale == 'en_US') {
                 return function () use($generator) {
                     return sprintf('%s County', $generator->city);
                 };
             }
             return function () use($generator) {
                 return $generator->state;
             };
         case 'country':
             switch ($size) {
                 case 2:
                     return function () use($generator) {
                         return $generator->countryCode;
                     };
                 case 3:
                     return function () use($generator) {
                         return $generator->countryISOAlpha3;
                     };
                 case 5:
                 case 6:
                     return function () use($generator) {
                         return $generator->locale;
                     };
                 default:
                     return function () use($generator) {
                         return $generator->country;
                     };
             }
             break;
         case 'locale':
             return function () use($generator) {
                 return $generator->locale;
             };
         case 'currency':
         case 'currencycode':
             return function () use($generator) {
                 return $generator->currencyCode;
             };
         case 'url':
         case 'website':
             return function () use($generator) {
                 return $generator->url;
             };
         case 'company':
         case 'companyname':
         case 'employer':
             return function () use($generator) {
                 return $generator->company;
             };
         case 'title':
             if ($size !== null && $size <= 10) {
                 return function () use($generator) {
                     return $generator->title;
                 };
             }
             return function () use($generator) {
                 return $generator->sentence;
             };
         case 'body':
         case 'summary':
         case 'article':
         case 'description':
             return function () use($generator) {
                 return $generator->text;
             };
     }
 }
Exemplo n.º 11
0
 public function testRandomElements()
 {
     $this->assertCount(1, BaseProvider::randomElements(), 'Should work without any input');
     $empty = BaseProvider::randomElements(array(), 0);
     $this->assertInternalType('array', $empty);
     $this->assertCount(0, $empty);
     $shuffled = BaseProvider::randomElements(array('foo', 'bar', 'baz'), 3);
     $this->assertContains('foo', $shuffled);
     $this->assertContains('bar', $shuffled);
     $this->assertContains('baz', $shuffled);
 }
Exemplo n.º 12
0
 /**
  * Constructor
  * @param Generator $generator
  * @param array $options
  */
 public function __construct(Generator $generator, $options = [])
 {
     parent::__construct($generator);
     if (isset($options[self::OPTION_BASE_URL])) {
         $this->baseUrl = $options[self::OPTION_BASE_URL];
     }
     if (isset($options[self::OPTION_BASE_URL])) {
         $this->limitImageResolution = $options[self::OPTION_BASE_URL];
     }
 }
Exemplo n.º 13
0
 public static function bothify($string)
 {
     return parent::bothify($string);
 }
Exemplo n.º 14
0
 /**
  * @param Generator $generator
  * @param string    $trigger
  */
 public function __construct(Generator $generator, $trigger)
 {
     parent::__construct($generator);
     $this->trigger = $trigger;
 }
Exemplo n.º 15
0
 public function guessFormat($name)
 {
     $name = Base::toLower($name);
     $generator = $this->generator;
     if (preg_match('/^is[_A-Z]/', $name)) {
         return function () use($generator) {
             return $generator->boolean;
         };
     }
     if (preg_match('/(_a|A)t$/', $name)) {
         return function () use($generator) {
             return $generator->dateTime;
         };
     }
     switch ($name) {
         case 'first_name':
         case 'firstname':
             return function () use($generator) {
                 return $generator->firstName;
             };
         case 'last_name':
         case 'lastname':
             return function () use($generator) {
                 return $generator->lastName;
             };
         case 'username':
         case 'login':
             return function () use($generator) {
                 return $generator->userName;
             };
         case 'email':
             return function () use($generator) {
                 return $generator->email;
             };
         case 'phone_number':
         case 'phonenumber':
         case 'phone':
             return function () use($generator) {
                 return $generator->phoneNumber;
             };
         case 'address':
             return function () use($generator) {
                 return $generator->address;
             };
         case 'city':
             return function () use($generator) {
                 return $generator->city;
             };
         case 'streetaddress':
             return function () use($generator) {
                 return $generator->streetAddress;
             };
         case 'postcode':
         case 'zipcode':
             return function () use($generator) {
                 return $generator->postcode;
             };
         case 'state':
             return function () use($generator) {
                 return $generator->state;
             };
         case 'country':
             return function () use($generator) {
                 return $generator->country;
             };
         case 'title':
             return function () use($generator) {
                 return $generator->sentence;
             };
         case 'body':
         case 'summary':
             return function () use($generator) {
                 return $generator->text;
             };
     }
 }
Exemplo n.º 16
0
 public function ttl()
 {
     return [[Base::numberBetween(60, 2678400)]];
 }
Exemplo n.º 17
0
 public function testBothifyCombinesNumerifyAndLexify()
 {
     $this->assertRegExp('/foo[a-z]Ba\\dr/', BaseProvider::bothify('foo?Ba#r'));
 }
Exemplo n.º 18
0
 /**
  * @param \Faker\Generator $generator
  * @param Kernel
  */
 public function __construct(Generator $generator, Kernel $kernel)
 {
     $this->kernel = $kernel;
     parent::__construct($generator);
 }
Exemplo n.º 19
0
 /**
  * @return string Random job abbreviation title
  */
 public function jobAbbreviation()
 {
     return BaseProvider::randomElement($this->abbreviationProvider);
 }
 /**
  * Generate the admin form type entity.
  */
 private function generateBehatTest()
 {
     $configDir = $this->bundle->getPath() . '/Resources/config';
     // Get the context names for each section config file
     $sectionInfo = array();
     $dir = $configDir . '/pageparts/';
     foreach ($this->sections as $section) {
         $data = Yaml::parse($dir . $section);
         $sectionInfo[basename($section, '.yml')] = array('context' => $data['context'], 'pagetempates' => array());
     }
     /*
         Example $sectionInfo contents:
         Array
         (
             [main] => Array
                 (
                     [context] => main
                     [pagetempates] => Array
                         (
                         )
                 )
         )
     */
     // Get a list of page templates that use this context
     $allTemplates = glob($configDir . '/pagetemplates/*.yml');
     $contextTemplates = array();
     foreach ($allTemplates as $templatePath) {
         $parts = explode("/", $templatePath);
         $fileName = basename($parts[count($parts) - 1], '.yml');
         $data = Yaml::parse($templatePath);
         $templateName = $data['name'];
         if (array_key_exists('rows', $data) && is_array($data['rows'])) {
             foreach ($data['rows'] as $row) {
                 if (is_array($row) && array_key_exists('regions', $row) && is_array($row['regions'])) {
                     foreach ($row['regions'] as $region) {
                         $contextTemplates[$region['name']][$fileName] = $templateName;
                     }
                 }
             }
         }
     }
     /*
         Example $contextTemplates contents:
         Array
         (
             [main] => Array
                 (
                     [full-width-page] => Full width page
                     [homepage] => Home page
                     [sidebar-page] => Page with left sidebar
                 )
             [top] => Array
                 (
                     [homepage] => Home page
                 )
             [sidebar] => Array
                 (
                     [homepage] => Home page
                     [sidebar-page] => Page with left sidebar
                 )
         )
     */
     // Link the page templates to the sections
     foreach ($sectionInfo as $fileName => $info) {
         $context = $info['context'];
         if (array_key_exists($context, $contextTemplates)) {
             $sectionInfo[$fileName]['pagetempates'] = $contextTemplates[$context];
         }
     }
     /*
         Example $sectionInfo contents:
         Array
         (
             [main] => Array
                 (
                     [context] => main
                     [pagetempates] => Array
                         (
                             [full-width-page] => Full width page
                             [homepage] => Home page
                             [sidebar-page] => Page with left sidebar
                         )
     
                 )
     
         )
     */
     $folder = $this->registry->getRepository('KunstmaanMediaBundle:Folder')->findOneBy(array('rel' => 'image'));
     $images = $this->registry->getRepository('KunstmaanMediaBundle:Media')->findBy(array('folder' => $folder, 'deleted' => false), array(), 2);
     // Get all the available pages
     $allPages = glob($this->bundle->getPath() . '/Entity/Pages/*.php');
     $pages = array();
     foreach ($allPages as $pageFile) {
         $parts = explode("/", $pageFile);
         $className = basename($parts[count($parts) - 1], '.php');
         $contents = file_get_contents($pageFile);
         if (strpos($contents, 'abstract class') === false && strpos($contents, 'interface ') === false) {
             $classNamespace = '\\' . $this->bundle->getNamespace() . '\\Entity\\Pages\\' . $className;
             $entity = new $classNamespace();
             if (!method_exists($entity, 'getPagePartAdminConfigurations') || !method_exists($entity, 'getPageTemplates')) {
                 continue;
             }
             $ppConfigs = $entity->getPagePartAdminConfigurations();
             $ptConfigs = $entity->getPageTemplates();
             foreach ($ppConfigs as $ppConfig) {
                 $parts = explode(":", $ppConfig);
                 $ppConfigFilename = $parts[count($parts) - 1];
                 // Context found in this Page class
                 if (array_key_exists($ppConfigFilename, $sectionInfo)) {
                     // Search for templates
                     foreach ($ptConfigs as $ptConfig) {
                         $parts = explode(":", $ptConfig);
                         $ptConfigFilename = $parts[count($parts) - 1];
                         // Page template found
                         if (array_key_exists($ptConfigFilename, $sectionInfo[$ppConfigFilename]['pagetempates'])) {
                             $formType = $entity->getDefaultAdminType();
                             if (!is_object($formType)) {
                                 $formType = $this->container->get($formType);
                             }
                             // Get all page properties
                             $form = $this->container->get('form.factory')->create($formType);
                             $children = $form->createView()->children;
                             $pageFields = array();
                             foreach ($children as $field) {
                                 $name = $field->vars['name'];
                                 $attr = $field->vars['attr'];
                                 $blocks = $field->vars['block_prefixes'];
                                 if ($name == 'title' || $name == 'pageTitle') {
                                     continue;
                                 }
                                 if ($blocks[1] == 'hidden') {
                                     // do nothing
                                 } elseif ($blocks[1] == 'choice' && $blocks[1] == 'entity') {
                                     // do nothing
                                 } elseif ($blocks[1] == 'datetime') {
                                     $pageFields[]['datetime'] = array('label' => $this->labelCase($name), 'date_random' => DateTime::date('d/m/Y'), 'time_random' => DateTime::time('H:i'));
                                 } elseif ($blocks[1] == 'number') {
                                     $pageFields[]['decimal'] = array('label' => $this->labelCase($name), 'random' => Base::randomFloat(2, 0, 99999));
                                 } elseif ($blocks[1] == 'integer') {
                                     $pageFields[]['integer'] = array('label' => $this->labelCase($name), 'random' => Base::randomNumber(3000, 99999));
                                 } elseif ($blocks[1] == 'checkbox') {
                                     $pageFields[]['boolean'] = array('label' => $this->labelCase($name));
                                 } elseif ($blocks[1] == 'media') {
                                     $id = count($images) > 0 ? $images[0]->getId() : 1;
                                     $pageFields[]['media'] = array('label' => $this->labelCase($name), 'random' => $id);
                                 } elseif ($blocks[2] == 'urlchooser') {
                                     $pageFields[]['link'] = array('label' => $this->labelCase($name), 'random' => 'http://www.' . strtolower(Lorem::word()) . '.com');
                                 } elseif ($blocks[2] == 'textarea' && array_key_exists('class', $attr) && $attr['class'] == 'rich_editor') {
                                     $pageFields[]['rich_text'] = array('label' => $this->labelCase($name), 'random' => Lorem::sentence());
                                 } elseif ($blocks[2] == 'textarea' || $blocks[1] == 'text') {
                                     $pageFields[]['text'] = array('label' => $this->labelCase($name), 'random' => Lorem::word());
                                 }
                             }
                             $pages[] = array('name' => $className, 'section' => $sectionInfo[$ppConfigFilename]['context'], 'template' => $sectionInfo[$ppConfigFilename]['pagetempates'][$ptConfigFilename], 'fields' => $pageFields);
                         }
                     }
                 }
             }
         }
     }
     /*
         Example $pages contents:
         Array
         (
             [0] => Array
                 (
                     [name] => ContentPage
                     [section] => main
                     [template] => Page with left sidebar
                     [fields] => Array
                         (
                             ...
                         )
                 )
             [1] => Array
                 (
                     [name] => ContentPage
                     [section] => main
                     [template] => Full width page
                     [fields] => Array
                         (
                             ...
                         )
                 )
             [2] => Array
                 (
                     [name] => HomePage
                     [section] => main
                     [template] => Home page
                     [fields] => Array
                         (
                             ...
                         )
                 )
         )
     */
     // Add some random values in the field array, so that this values can be uses as test values
     foreach ($this->fields as $fkey => $fieldSet) {
         foreach ($fieldSet as $key => $values) {
             switch ($key) {
                 case 'multi_line':
                 case 'single_line':
                     $values[0]['random1'] = Lorem::word();
                     $values[0]['random2'] = Lorem::word();
                     $values[0]['lName'] = $this->labelCase($values[0]['fieldName']);
                     break;
                 case 'rich_text':
                     $values[0]['random1'] = Lorem::sentence();
                     $values[0]['random2'] = Lorem::sentence();
                     $values[0]['lName'] = $this->labelCase($values[0]['fieldName']);
                     break;
                 case 'link':
                     $values['url']['random1'] = 'http://www.' . strtolower(Lorem::word()) . '.com';
                     $values['url']['random2'] = 'http://www.' . strtolower(Lorem::word()) . '.com';
                     $values['url']['lName'] = $this->labelCase($values['url']['fieldName']);
                     $values['text']['random1'] = Lorem::word();
                     $values['text']['random2'] = Lorem::word();
                     $values['text']['lName'] = $this->labelCase($values['text']['fieldName']);
                     $values['new_window']['lName'] = $this->labelCase($values['new_window']['fieldName']);
                     break;
                 case 'image':
                     if (count($images) > 0) {
                         if (count($images) > 1) {
                             $values['image']['id_random1'] = $images[0]->getId();
                             $values['image']['url_random1'] = $images[0]->getUrl();
                             $values['image']['id_random2'] = $images[1]->getId();
                             $values['image']['url_random2'] = $images[1]->getUrl();
                         } else {
                             $values['image']['id_random1'] = $values['image']['id_random2'] = $images[0]->getId();
                             $values['image']['url_random1'] = $values['image']['url_random2'] = $images[0]->getUrl();
                         }
                     } else {
                         $values['image']['id_random1'] = $values['image']['id_random2'] = '1';
                         $values['image']['url_random1'] = $values['image']['url_random2'] = 'XXX';
                     }
                     $values['image']['lName'] = $this->labelCase($values['image']['fieldName']);
                     $values['alt_text']['random1'] = Lorem::word();
                     $values['alt_text']['random2'] = Lorem::word();
                     $values['alt_text']['lName'] = $this->labelCase($values['alt_text']['fieldName']);
                     break;
                 case 'boolean':
                     $values[0]['lName'] = $this->labelCase($values[0]['fieldName']);
                     break;
                 case 'integer':
                     $values[0]['random1'] = Base::randomNumber(3000, 99999);
                     $values[0]['random2'] = Base::randomNumber(3000, 99999);
                     $values[0]['lName'] = $this->labelCase($values[0]['fieldName']);
                     break;
                 case 'decimal':
                     $values[0]['random1'] = Base::randomFloat(2, 0, 99999);
                     $values[0]['random2'] = Base::randomFloat(2, 0, 99999);
                     $values[0]['lName'] = $this->labelCase($values[0]['fieldName']);
                     break;
                 case 'datetime':
                     $values[0]['date_random1'] = DateTime::date('d/m/Y');
                     $values[0]['date_random2'] = DateTime::date('d/m/Y');
                     $values[0]['time_random1'] = DateTime::time('H:i');
                     $values[0]['time_random2'] = DateTime::time('H:i');
                     $dparts = explode('/', $values[0]['date_random1']);
                     $values[0]['datetime_random1'] = $dparts[2] . '-' . $dparts[1] . '-' . $dparts[0] . ' ' . $values[0]['time_random1'] . ':00';
                     $dparts = explode('/', $values[0]['date_random2']);
                     $values[0]['datetime_random2'] = $dparts[2] . '-' . $dparts[1] . '-' . $dparts[0] . ' ' . $values[0]['time_random2'] . ':00';
                     $values[0]['lName'] = $this->labelCase($values[0]['fieldName']);
                     break;
             }
             $this->fields[$fkey][$key] = $values;
         }
     }
     $params = array('name' => $this->entity, 'pages' => $pages, 'fields' => $this->fields);
     $this->renderFile('/Features/PagePart.feature', $this->bundle->getPath() . '/Features/Admin' . $this->entity . '.feature', $params);
     $this->assistant->writeLine('Generating behat test : <info>OK</info>');
 }
Exemplo n.º 21
0
 public function __construct(Generator $generator)
 {
     parent::__construct($generator);
     $generator->addProvider(new Lorem($generator));
     $generator->addProvider(new Internet($generator));
 }