コード例 #1
0
ファイル: LoremTest.php プロジェクト: alikhan890/minitwitter
 public function testParagraphWithPositiveNbSentencesReturnsAtLeastOneWord()
 {
     $paragraph = Lorem::paragraph(1);
     $this->assertGreaterThan(1, strlen($paragraph));
     $this->assertGreaterThanOrEqual(1, count(explode(' ', $paragraph)));
 }
コード例 #2
0
 /**
  * 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>');
 }
コード例 #3
0
ファイル: MessageTest.php プロジェクト: tamcy/awspushbundle
 public function localizedNoArgs()
 {
     return [[Lorem::text(1000), Lorem::text(50)]];
 }
コード例 #4
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     set_time_limit(0);
     ignore_user_abort(1);
     $english = Faker\Factory::create('en_GB');
     $french = Faker\Factory::create('fr_FR');
     $chinese = Faker\Factory::create('zh_CN');
     $german = Faker\Factory::create('de_DE');
     $spanish = Faker\Factory::create('es_ES');
     $lorem = new Faker\Provider\Lorem($english);
     $langs = ['fr' => 'french', 'cn' => 'chinese', 'de' => 'german', 'es' => 'spanish', 'en' => 'english'];
     $shopId = $this->argument('shop');
     $categories = (int) $this->argument('categories') + 1;
     $products = (int) $this->argument('products') + 1;
     // create 3 sets of options for color,size & material
     $data = ['Color' => ['Red', 'Green', 'Blue', 'Orange', 'Purple', 'Yellow'], 'Material' => ['Canvas', 'Glossy', 'Matt'], 'Size' => ['Xlarge', 'Large', 'Medium', 'Small', 'Xsmall']];
     // build and create option
     foreach ($data as $key => $options) {
         $currentOptions = [];
         foreach ($langs as $lang => $label) {
             $currentOptions[$lang][$key] = $options;
         }
         $currentOptions['default'] = $currentOptions[$lang];
         $option = Option::create($currentOptions);
     }
     for ($i = 1; $i < $categories; $i++) {
         // create a category;
         $categoryProducts = [];
         $category = new Category();
         $category->shop_id = $shopId;
         $category->parent = 0;
         $category->slug = 'category-' . $i;
         $category->products = [];
         foreach ($langs as $code => $lang) {
             $data = ['name' => ${$lang}->name . ' ' . $i, 'content' => $lorem->sentence($nbWords = 6, $variableNbWords = true)];
             $category->{$code} = $data;
         }
         $category->default = $data;
         $category->save();
         // create products
         for ($x = 1; $x < $products; $x++) {
             // store
             $product = new Product();
             $product->shop_id = $shopId;
             $product->slug = 'product-' . $x . '-category-' . $i;
             $product->sku = 'product-' . $x . '-category-' . $i;
             $product->categories = [$category->id];
             $product->price = number_format(rand(50, 275), 2);
             $product->rrp = number_format($product->price * 1.2, 2);
             $product->salePrice = number_format($product->price * 0.8, 2);
             foreach ($langs as $code => $lang) {
                 $data = ['name' => ${$lang}->name, 'content' => $lorem->sentence($nbWords = 200, $variableNbWords = true), 'excerpt' => $lorem->sentence($nbWords = 50, $variableNbWords = true)];
                 $product->{$code} = $data;
             }
             $product->default = $data;
             // save the product
             $product->save();
             // register product with each new option
             $options = Option::all();
             $newOptions = $toadd = [];
             foreach ($options as $option) {
                 $optionProduct = OptionProduct::firstOrNew(['option_id' => $option->id]);
                 $optionProduct->option_id = $option->id;
                 $optionProduct_products = isset($optionProduct->products) ? $optionProduct->products : [];
                 array_push($optionProduct_products, $product->id);
                 $optionProduct->products = $optionProduct_products;
                 $optionProduct->save();
                 // register option with this product
                 $productOptions = isset($product->options) ? $product->options : [];
                 array_push($productOptions, $option->id);
                 $product->options = $productOptions;
                 $product->option_values = [];
                 $option_default = $option->default;
                 $toadd[$option->id] = reset($option_default);
                 $product->save();
             }
             // we have the options lets add to the product
             $combo = [];
             for ($z = 0; $z < 3; $z++) {
                 foreach ($toadd as $key => $value) {
                     $combo[$z][$key] = array_rand($value, 1);
                 }
             }
             $combo = array_map('unserialize', array_unique(array_map('serialize', $combo)));
             //$newOptions[$option->id][] = array_rand(reset($toadd), 1);
             $count = 0;
             foreach ($combo as $c) {
                 $productOptionValues = $product->option_values;
                 $new = ['sku' => $product->sku . '_' . $count++, 'price' => $product->price, 'options' => $c];
                 $productOptionValues[] = $new;
                 $product->option_values = $productOptionValues;
                 $product->save();
             }
             // add this option to OPV table for quick filtering
             $povs = $product->option_values;
             foreach ($povs as $pov) {
                 foreach ($pov['options'] as $keyz => $optionz) {
                     $opv = OptionProductValue::where('filter', $keyz . '-' . $optionz)->first();
                     if (!$opv) {
                         // insert first
                         OptionProductValue::create(['filter' => $keyz . '-' . $optionz, 'products' => [$product->id]]);
                     } else {
                         // add to list
                         $p = $opv->products;
                         array_push($p, $product->id);
                         $opv->products = array_unique($p);
                         $opv->save();
                     }
                 }
             }
             // add images
             $categoryProducts[] = $product->id;
             app('App\\Http\\Controllers\\Admin\\MediaController')->generateImages('products', $product->id, 'http://lorempixel.com/1600/900/');
             $product->defaultImage = 'images/products/' . $product->id . '/large/image' . $product->id . '.jpg';
             $product->save();
         }
         $category->products = $categoryProducts;
         $category->save();
     }
 }
コード例 #5
0
 public function trimMessage()
 {
     return [[new Message(Lorem::text(10000))]];
 }
コード例 #6
0
    /**
     * @test
     */
    public function longString()
    {
        $loremIpsum = StringUtils::crlfize(Lorem::text(50000));
        $data = ["Section" => ["key" => $loremIpsum]];
        $ini = StringUtils::crlfize(<<<INI
[Section]
key = "{$loremIpsum}"

INI
);
        $this->assertSame($ini, IniSerializer::serialize($data));
        $this->assertSame($data, IniSerializer::deserialize($ini));
    }
コード例 #7
0
ファイル: MessageTest.php プロジェクト: skler/awspushbundle
 /**
  * @dataProvider ttl
  */
 public function testTtl($ttl)
 {
     $message = new Message(Lorem::text(1000));
     $message->setTtl($ttl);
     $string = (string) $message;
     $data = json_decode($string, true);
     $gcmData = json_decode($data['GCM'], true);
     $this->assertEquals($ttl, $gcmData['time_to_live']);
     $admData = json_decode($data['ADM'], true);
     $this->assertEquals($ttl, $admData['expiresAfter']);
 }