Ejemplo n.º 1
0
 public function setUp()
 {
     WP::setUp();
     $this->plugin = \Cft\Plugin::getInstance();
     $this->plugin->set('validatorBuilder', new \Cft\ValidatorBuilder($this->plugin));
     $this->plugin->set('fieldBuilder', new \Cft\FieldBuilder($this->plugin));
 }
Ejemplo n.º 2
0
 public function testGetInstance()
 {
     $plugin1 = Plugin::getInstance();
     $class = get_class($plugin1);
     $this->assertEquals($class, 'Cft\\Plugin');
     // make sure it's a true singleton
     $this->assertEquals(spl_object_hash($plugin1), spl_object_hash(Plugin::getInstance()));
 }
 protected function getViewPath($file)
 {
     $dirs = Plugin::getInstance()->get('viewDirs');
     foreach ($dirs as $dir) {
         // return the first existing template from all possible locations
         if (file_exists($dir . $file)) {
             return $dir . $file;
         }
     }
 }
 public function testSave()
 {
     $instance = $this->getInstanceWithTrait(['foo' => 'text', 'bar' => ['type' => 'text'], 'baz' => 'textarea', 'qux' => 'wysiwyg']);
     WP::wpFunction('wp_verify_nonce', ['args' => ['nonce value', 'cft_save_meta'], 'times' => 1, 'return' => 1]);
     $plugin = Plugin::getInstance();
     $plugin->set('request', ['cft_nonce' => 'nonce value', 'foo' => 'I am FOO', 'bar' => 'I am BAR', 'baz' => 'I am BAZ', 'qux' => 'I am QUX']);
     $plugin->set('validatorBuilder', new ValidatorBuilder($plugin));
     // Mock Field instances
     $foo = $this->getField($this->postId, 'foo', 'text', 'I am FOO');
     $bar = $this->getField($this->postId, 'bar', ['type' => 'text'], 'I am BAR');
     $baz = $this->getField($this->postId, 'baz', 'textarea', 'I am BAZ');
     $qux = $this->getField($this->postId, 'qux', 'wysiwyg', 'I am QUX');
     // Map FieldBuilder::build parameters to specific mock instances
     $map = [[$this->postId, 'foo', 'text', 'I am FOO', $foo], [$this->postId, 'bar', ['type' => 'text'], 'I am BAR', $bar], [$this->postId, 'baz', 'textarea', 'I am BAZ', $baz], [$this->postId, 'qux', 'wysiwyg', 'I am QUX', $qux]];
     $builder = $this->getMockBuilder('\\Cft\\FieldBuilder')->setConstructorArgs([$plugin])->setMethods(['build'])->getMock();
     $builder->method('build')->will($this->returnValueMap($map));
     Plugin::getInstance()->set('fieldBuilder', $builder);
     $instance->save();
 }
    public function testRender()
    {
        $expected = <<<_SELECT_
<select name="my_select" class="foo">
  <option value="1">one</option>
  <option value="2" selected>two</option>
  <option value="3">three</option>
</select>
_SELECT_;
        \Cft\Plugin::getInstance()->set('view', function () use($expected) {
            $twig = $this->getMockBuilder('\\Twig_Environment')->getMock();
            $data = $this->config;
            $data['name'] = $this->name;
            $data['value'] = '2';
            $twig->expects($this->once())->method('render')->with('select.twig', $data)->will($this->returnValue($expected));
            return new \Cft\View\TwigView($twig);
        });
        $this->subject->setValue('2');
        $rendered = $this->getRendered(function () {
            $this->subject->render();
        });
        $this->assertHtmlEquals($expected, $rendered);
    }
 public function setUp()
 {
     $this->plugin = Plugin::getInstance();
     $this->builder = new ValidatorBuilder($this->plugin);
 }
Ejemplo n.º 7
0
 public function render()
 {
     $view = Plugin::getInstance()->get('view');
     echo $view->render('textarea.twig', ['name' => $this->getName(), 'text' => $this->getValue(), 'attributes' => $this->getConfig('attributes')]);
 }
Ejemplo n.º 8
0
 public function render()
 {
     $view = Plugin::getInstance()->get('view');
     echo $view->render('select.twig', ['name' => $this->getName(), 'value' => $this->getValue(), 'type' => $this->getType(), 'attributes' => $this->getConfig('attributes'), 'options' => $this->getConfig('options')]);
 }
 public function setUp()
 {
     $this->plugin = Plugin::getInstance();
     $this->plugin->set('validatorBuilder', new ValidatorBuilder($this->plugin));
     $this->builder = new FieldBuilder($this->plugin);
 }
 protected function getPostedValue($name)
 {
     $request = Plugin::getInstance()->get('request') ?: [];
     return isset($request[$name]) ? $request[$name] : '';
 }