Example #1
0
 /**
  * @covers Foote\Ginny\Map\BaseBundle::validate
  */
 public function testValidatesOK()
 {
     $field = new BaseField('name');
     $field->type = 'string';
     $model = new BaseModel('Thing');
     $model->addField($field);
     $bundle = new BaseBundle('Bundle');
     $bundle->addModel($model);
     $bundle->validate();
     //all is good, no exceptions
     $this->assertTrue(true);
 }
Example #2
0
 /**
  * covers \Foote\Ginny\Twig\UIExtension::getName
  * covers \Foote\Ginny\Twig\UIExtension::getFilters
  * covers \Foote\Ginny\Twig\UIExtension::getFunctions
  */
 public function testui()
 {
     $extension = new UIExtension();
     $this->assertEquals($extension->getName(), 'ui_extension');
     /**
      * @var $filter \Twig_SimpleFilter
      */
     foreach ($extension->getFilters() as $filter) {
         $callable = $filter->getCallable();
         if ($filter->getName() == 'blade') {
             $user = \Foote\Ginny\Map\BaseModel::create('User');
             $this->assertEquals($callable($user), '{{ $user }}');
         }
     }
     /**
      * @var $filter \Twig_SimpleFunction
      */
     foreach ($extension->getFunctions() as $filter) {
         $callable = $filter->getCallable();
         if ($filter->getName() == 'blade_url') {
             $user = \Foote\Ginny\Map\BaseModel::create('User');
             $user->route = 'admin.system.users';
             $this->assertEquals($callable($user), "{{ URL::route('admin.system.users.index') }}");
         }
         if ($filter->getName() == 'i') {
             $this->assertEquals($callable('create'), '<i class="fa fa-plus"></i>');
         }
     }
 }
Example #3
0
 function __construct($name, $params = [])
 {
     parent::__construct($name, $params);
     $this->keys = new Collection();
     $this->models = new Collection();
     $this->models->set('owner', $this->owner);
     $this->owner->addAssociation($this);
     switch ($this->type) {
         case 'belongsTo':
             $this->models->set('child', $this->owner);
             $this->models->set('parent', $this->target);
             $this->addKey('local', $this->owner->fields->get($this->ownerKey));
             $this->addKey('parent', $this->target->fields->get($this->targetKey));
             $this->owner->fields->get($this->ownerKey)->parent = $this->target;
             break;
         case 'belongsToMany':
             $this->pivotOwnerBelongsTo = $this->pivot->associations->get($this->owner->name);
             $this->pivotTargetBelongsTo = $this->pivot->associations->get($this->target->name);
             $this->models->set('child', $this->owner);
             $this->models->set('parent', $this->target);
             $this->models->set('pivot', $this->pivot);
             $this->addKey('local', $this->owner->fields->get($this->ownerKey));
             $this->addKey('parent', $this->target->fields->get($this->targetKey));
             $this->addKey('pivot_local', $this->pivotOwnerBelongsTo->keys('local'));
             $this->addKey('pivot_parent', $this->pivotTargetBelongsTo->keys('local'));
             break;
         case 'hasMany':
             $this->models->set('child', $this->target);
             $this->models->set('parent', $this->owner);
             $this->addKey('local', $this->owner->fields->get($this->ownerKey));
             $this->addKey('foreign', $this->target->fields->get($this->targetKey));
             break;
         case 'hasOne':
             $this->models->set('child', $this->target);
             $this->models->set('parent', $this->owner);
             $this->addKey('local', $this->owner->fields->get($this->ownerKey));
             $this->addKey('foreign', $this->target->fields->get($this->targetKey));
             break;
     }
 }
Example #4
0
 /**
  * @covers Foote\Ginny\Map\BaseAssociation::update
  */
 public function testupdate()
 {
     $bundle = new BaseBundle('Bundle');
     $site = BaseModel::create('Site');
     $site->bundle = $bundle;
     $site->addField(BaseField::create('id', ['type' => 'integer']));
     // Site hasOne Profile
     $profile = BaseModel::create('Profile');
     $profile->bundle = $bundle;
     $profile->addField(BaseField::create('id', ['type' => 'integer']));
     //add unique field to Profile
     $field = BaseField::create('site_id', ['type' => 'integer']);
     $field->unique = true;
     $profile->addField($field);
     $association = BaseAssociation::create('SiteProfile', ['owner' => $site, 'ownerKey' => 'id', 'type' => 'hasMany', 'target' => $profile, 'targetKey' => 'site_id']);
     //hasMany should be converted to hasOne since Profile.site_id is unique
     $association->update();
     $this->assertEquals('hasOne', $association->type);
 }