Пример #1
0
 function testDeleteObservers()
 {
     $dispatcher = PMVC\plug('dispatcher');
     $mockObserver = new MockObserver();
     $dispatcher->attach($mockObserver, 'test');
     $this->assertTrue($dispatcher->contains($mockObserver, 'test'));
     $dispatcher->cleanObserver();
     $this->assertFalse($dispatcher->contains($mockObserver, 'test'));
 }
Пример #2
0
 function testGetDb()
 {
     $fake_db = __NAMESPACE__ . '\\FakeSSDB';
     $db_plug = 'fake_ssdb';
     \PMVC\option('set', 'GUID_DB', $db_plug);
     \PMVC\unplug($this->plug);
     PMVC\plug($db_plug, array(_CLASS => $fake_db));
     $db = PMVC\plug($this->plug)->getDb('manager');
     $this->assertEquals($fake_db, get_class($db->db));
 }
Пример #3
0
 public function parseFile($v)
 {
     if (!isset($v['url'])) {
         $v = array('url' => $v);
     }
     if (p\exists('url', 'plugin')) {
         $v['url'] = p\plug('url')->toHttp($v['url']);
     }
     return $v;
 }
Пример #4
0
 public function dump($p, $type = 'debug')
 {
     $cli = p\plug('cli');
     if (p\plug('debug')->isShow($type, $this['level'])) {
         if (!is_array($p)) {
             $cli->dump($p, $this->getColor($type));
         } else {
             $cli->tree($p, $this->getColor($type));
         }
     }
 }
Пример #5
0
 private function getStatic()
 {
     if ($this->bInitJs) {
         return p\plug('asset');
     }
     $this->bInitJs = true;
     $static = p\plug('asset');
     $static->importJs('//cdn-htlovestory.netdna-ssl.com/lib/dlog/dlog.min.1.js');
     $static->js("var log = new dlog({ level: 'trace'});");
     return $static;
 }
Пример #6
0
 function testPlugin()
 {
     $c = \PMVC\plug('controller');
     $c->setApp($this->_app);
     $r = $c->getRequest();
     $r->setMethod('GET');
     $url = \PMVC\plug('url', ['REQUEST_URI' => '/yo/session/xxid', 'SCRIPT_NAME' => '/yo/']);
     $c->plugApp(['../'], [], 'index_api');
     \PMVC\initPlugIn(['guid' => [_CLASS => __NAMESPACE__ . '\\FakeGuid'], 'view' => [_CLASS => '\\PMVC\\FakeView'], 'default_forward' => null]);
     $result = $c->process();
 }
Пример #7
0
 function processConstantArray(&$arr)
 {
     $_ = \PMVC\plug('underscore')->array()->toUnderscore($arr['_']);
     unset($arr['_']);
     foreach ($_ as $k => $v) {
         $k = substr($k, 1);
         if (defined($k)) {
             $k = constant($k);
         }
         $arr[$k] = $v;
     }
 }
Пример #8
0
 function testPlugin()
 {
     $view = \PMVC\plug('view', [_CLASS => '\\PMVC\\FakeView']);
     $c = \PMVC\plug('controller');
     $c->setApp('error');
     $c->plugApp(['./']);
     $r = $c->getRequest();
     $r['errors'][] = 1001;
     $result = $c->process();
     $actual = \PMVC\value($result, [0, 'v', 'errors', '0']);
     $expected = new Error('1001', ['message' => 'Username can\'t empty, and must be at least 6 characters long', 'field' => 'username']);
     $this->assertEquals($expected, $actual);
 }
Пример #9
0
 function testDebug()
 {
     $c = \PMVC\plug('controller');
     $c->setApp('dimension');
     $c->plugApp(['./']);
     \PMVC\plug('dev');
     \PMVC\plug('debug', ['level' => 'dimension', 'output' => 'debug_store']);
     $r = $c->getRequest();
     $r['test'] = 'fakeDimension';
     $result = $c->process();
     $actual = \PMVC\value($result, [0, 'v', 'debugs', '0']);
     $expected = ['dimension', ['fakeDimension' => 'test']];
     $this->assertEquals($expected, $actual);
 }
Пример #10
0
 public function setOutput()
 {
     $output = $this['output'];
     if (p\getOption(_VIEW_ENGINE) === 'json') {
         $output = 'debug_store';
     }
     if (!is_object($output)) {
         $outputParam = [];
         if (isset($this['level'])) {
             $outputParam['level'] = $this['level'];
         }
         $output = p\plug($output, $outputParam);
     }
     if (empty($output)) {
         return !trigger_error('[PMVC:PlugIn:Debug:getOutput] Get Output failded.', E_USER_WARNING);
     }
     if (!$output->is(__NAMESPACE__ . '\\DebugDumpInterface')) {
         return !trigger_error('[' . get_class($output) . '] is not a valid debug output object,' . 'expedted DebugDumpInterface. ' . print_r($output, true), E_USER_WARNING);
     }
     $this['output'] = $output;
     $this->_output = $output;
 }
Пример #11
0
 function testProcessWithEmpty()
 {
     $curl = PMVC\plug($this->_plug);
     $o = $curl->get('http://tw.yahoo.com');
     $o->clean();
     $this->assertTrue(empty($o->getInstance()));
     $curl->process();
 }
Пример #12
0
 public function update(SplSubject $SplSubject = null)
 {
     parent::update($SplSubject);
     return p\plug($this->_view);
 }
Пример #13
0
 public function dump($p, $type = 'debug')
 {
     if (p\plug('debug')->isShow($type, $this['level'])) {
         $this->_appendToView([$type, $p]);
     }
 }