示例#1
0
 public function testAddingFetchingfields()
 {
     $field = $this->getMock('Bolt\\Field\\Base', null, array('test', 'test.twig'));
     $manager = new Manager();
     $manager->addField($field);
     $this->assertTrue($manager->has('test'));
     $this->assertEquals($field, $manager->getField('test'));
     $this->assertFalse($manager->getField('nonexistent'));
     $this->assertGreaterThan(5, $manager->fields());
 }
示例#2
0
 /**
  * Sanity checks for doubles in in contenttypes.
  */
 public function checkConfig()
 {
     $slugs = array();
     $wrongctype = false;
     foreach ($this->data['contenttypes'] as $key => $ct) {
         /**
          * Make sure any field that has a 'uses' parameter actually points to a field that exists.
          *
          * For example, this will show a notice:
          * entries:
          *   name: Entries
          *     singular_name: Entry
          *     fields:
          *       title:
          *         type: text
          *         class: large
          *       slug:
          *         type: slug
          *         uses: name
          */
         foreach ($ct['fields'] as $fieldname => $field) {
             // Verify that the contenttype doesn't try to add fields that are reserved.
             if ($fieldname != 'slug' && in_array($fieldname, $this->reservedFieldNames)) {
                 $error = Trans::__('contenttypes.generic.reserved-name', array('%contenttype%' => $key, '%field%' => $fieldname));
                 $this->app['session']->getFlashBag()->add('error', $error);
                 return;
             }
             // Check 'uses'. If it's an array, split it up, and check the separate parts. We also need to check
             // for the fields that are always present, like 'id'.
             if (is_array($field) && !empty($field['uses'])) {
                 foreach ($field['uses'] as $useField) {
                     if (!empty($field['uses']) && empty($ct['fields'][$useField]) && !in_array($useField, $this->reservedFieldNames)) {
                         $error = Trans::__('contenttypes.generic.wrong-use-field', array('%contenttype%' => $key, '%field%' => $fieldname, '%uses%' => $useField));
                         $this->app['session']->getFlashBag()->add('error', $error);
                         return;
                     }
                 }
             }
             // Make sure the 'type' is in the list of allowed types
             if (!isset($field['type']) || !$this->fields->has($field['type'])) {
                 $error = Trans::__('contenttypes.generic.no-proper-type', array('%contenttype%' => $key, '%field%' => $fieldname, '%type%' => $field['type']));
                 $this->app['session']->getFlashBag()->add('error', $error);
                 $wrongctype = true && $this->app['users']->getCurrentUsername();
             }
         }
         // Keep a running score of used slugs.
         if (!isset($slugs[$ct['slug']])) {
             $slugs[$ct['slug']] = 0;
         }
         $slugs[$ct['slug']]++;
         if (!isset($slugs[$ct['singular_slug']])) {
             $slugs[$ct['singular_slug']] = 0;
         }
         if ($ct['singular_slug'] != $ct['slug']) {
             $slugs[$ct['singular_slug']]++;
         }
     }
     // Check DB-tables integrity
     if (!$wrongctype && $this->app['integritychecker']->needsCheck() && count($this->app['integritychecker']->checkTablesIntegrity()) > 0 && $this->app['users']->getCurrentUsername()) {
         $msg = Trans::__("The database needs to be updated/repaired. Go to 'Configuration' > '<a href=\"%link%\">Check Database</a>' to do this now.", array('%link%' => Lib::path('dbcheck')));
         $this->app['session']->getFlashBag()->add('error', $msg);
         return;
     }
     // Sanity checks for taxonomy.yml
     foreach ($this->data['taxonomy'] as $key => $taxo) {
         // Show some helpful warnings if slugs or keys are not set correctly.
         if ($taxo['slug'] != $key) {
             $error = Trans::__("The identifier and slug for '%taxonomytype%' are the not the same ('%slug%' vs. '%taxonomytype%'). Please edit taxonomy.yml, and make them match to prevent inconsistencies between database storage and your templates.", array('%taxonomytype%' => $key, '%slug%' => $taxo['slug']));
             $this->app['session']->getFlashBag()->add('error', $error);
             return;
         }
     }
     // if there aren't any other errors, check for duplicates across contenttypes.
     if (!$this->app['session']->getFlashBag()->has('error')) {
         foreach ($slugs as $slug => $count) {
             if ($count > 1) {
                 $error = Trans::__("The slug '%slug%' is used in more than one contenttype. Please edit contenttypes.yml, and make them distinct.", array('%slug%' => $slug));
                 $this->app['session']->getFlashBag()->add('error', $error);
                 return;
             }
         }
     }
 }