示例#1
0
 /**
  * Render ajax toggle element.
  *
  * @param array|string $url
  * @param array $data
  * @param Entity|\Cake\ORM\Entity $entity
  * @return string
  */
 public function toggle($entity, $url = [], array $data = [])
 {
     if (empty($url)) {
         $url = ['action' => 'toggle', 'prefix' => $this->request->param('prefix'), 'plugin' => $this->request->param('plugin'), 'controller' => $this->request->param('controller'), (int) $entity->get('id'), (int) $entity->get('status')];
     }
     $data = Hash::merge(['url' => $url, 'entity' => $entity], $data);
     return $this->_View->element(__FUNCTION__, $data);
 }
示例#2
0
 /**
  * Test render toggle element.
  *
  * @return void
  */
 public function testToggle()
 {
     $request = new Request(['params' => ['plugin' => 'TestPlugin', 'controller' => 'Pages', 'action' => 'add', 'pass' => []]]);
     $entity = new Entity();
     $view = new AppView($request);
     $union = new UnionHelper($view);
     $entity->set('id', 10);
     $entity->set('status', 0);
     $actual = $union->toggle($entity);
     $expected = ['div' => ['class' => 'un-toggle-wrapper jsToggle'], 'a' => ['href' => 'javascript:void(0);', 'class' => 'un-red un-link', 'data-url' => '/test_plugin/pages/toggle/10/0'], 'i' => ['class' => 'un-icon fa fa-circle'], '/i', '/a', '/div'];
     $this->assertHtml($expected, $actual);
     $actual = $union->toggle($entity, '/my/path/1/2');
     $expected = ['div' => ['class' => 'un-toggle-wrapper jsToggle'], 'a' => ['href' => 'javascript:void(0);', 'class' => 'un-red un-link', 'data-url' => '/my/path/1/2'], 'i' => ['class' => 'un-icon fa fa-circle'], '/i', '/a', '/div'];
     $this->assertHtml($expected, $actual);
 }