Esempio n. 1
0
 function test()
 {
     $store = $this->getStore();
     ok($store);
     $store->destroy();
     $store->load();
     $user = new \Phifty\JsonStore\FileJsonModel('User', $store);
     $id = $user->save(array('name' => 123));
     ok($id);
     $store->save();
     $items = $store->items();
     ok($items);
     count_ok(1, $items);
     $user = new \Phifty\JsonStore\FileJsonModel('User', $store);
     $id = $user->save(array('name' => 333));
     ok($id);
     $items = $store->items();
     ok($items);
     count_ok(2, $items);
     $user = new \Phifty\JsonStore\FileJsonModel('User', $store);
     $id = $user->save(array('id' => 99, 'name' => 'with Id'));
     ok($id);
     ok($store->get(99));
     ok($store->get("99"));
     $items = $store->items();
     ok($items);
     count_ok(3, $items);
     ok($store->destroy());
 }
Esempio n. 2
0
 public function testMuxCompiler()
 {
     $mux = new Mux();
     $mux->add('/hello/:name', array('FooController', 'index'));
     $mux->compile("hello_mux.php");
     $mux2 = new Mux();
     $mux2->add('/bye/:name', array('FooController', 'index'));
     $mux2->compile("bye_mux.php");
     $compiler = new MuxCompiler();
     ok($compiler->load("hello_mux.php"));
     ok($compiler->load("bye_mux.php"));
     $compiler->compileReflectionParameters();
     ok($compiler->compile("merged_mux.php"));
     path_ok("merged_mux.php");
     $mux = (require "merged_mux.php");
     ok($mux);
     $routes = $mux->getRoutes();
     ok($routes);
     count_ok(2, $routes);
     ok($mux->dispatch('/hello/John'));
     ok($mux->dispatch('/bye/John'));
     unlink("merged_mux.php");
     unlink("hello_mux.php");
     unlink("bye_mux.php");
 }
Esempio n. 3
0
 /**
  * @depends testControllerConstructor
  */
 public function testExpand($controller)
 {
     $mux = $controller->expand();
     ok($mux);
     ok($routes = $mux->getRoutes());
     count_ok(3, $routes);
 }
Esempio n. 4
0
 public function testGetRoutes()
 {
     $submux = new \Pux\Mux();
     $submux->any('/hello/:name', array('HelloController2', 'indexAction'));
     ok($submux);
     ok($routes = $submux->getRoutes());
     ok(is_array($routes));
     count_ok(1, $routes);
 }
Esempio n. 5
0
 function test3()
 {
     $arg = new Argument('-abc');
     ok($arg->withExtraFlagOptions());
     $args = $arg->extractExtraFlagOptions();
     ok($args);
     count_ok(2, $args);
     is('-b', $args[0]);
     is('-c', $args[1]);
     is('-a', $arg->arg);
 }
Esempio n. 6
0
 /**
  * @depends testBasicRoutes
  */
 public function testExport($mux)
 {
     $code = $mux->export();
     ok($code);
     eval('$newMux = ' . $code . ';');
     ok($newMux);
     $routes = $newMux->getRoutes();
     ok($routes);
     count_ok(2, $routes);
     is(2, $newMux->length());
 }
Esempio n. 7
0
 public function testMuxGetMethod()
 {
     $mux = new \Pux\Mux();
     ok($mux);
     $mux->get('/news', ['NewsController', 'listAction']);
     $mux->get('/news_item', ['NewsController', 'itemAction'], []);
     $routes = $mux->getRoutes();
     ok($routes);
     count_ok(2, $routes);
     is(2, $mux->length());
     $_SERVER['REQUEST_METHOD'] = "GET";
     ok($mux->dispatch('/news_item'));
     ok($mux->dispatch('/news'));
 }
Esempio n. 8
0
 public function testAnnotationForGetActionMethods()
 {
     $con = new ChildController();
     ok($con);
     ok($map = $con->getActionMethods());
     ok(is_array($map));
     ok(isset($map['postAction']));
     ok(isset($map['pageAction']));
     ok(isset($map['subpageAction']));
     is(array(array("Route" => "/post", "Method" => "POST"), array("class" => "ChildController")), $map['postAction']);
     $routeMap = $con->getActionRoutes();
     count_ok(3, $routeMap);
     list($path, $method, $options) = $routeMap[0];
     is('/page', $path);
     is('pageAction', $method);
     is(array('method' => REQUEST_METHOD_GET), $options);
 }
 function testParser3()
 {
     $appspecs = new OptionSpecCollection();
     $appspecs->add('v|verbose');
     $appspecs->add('c|color');
     $appspecs->add('d|debug');
     $cmdspecs = new OptionSpecCollection();
     $cmdspecs->add('a');
     $cmdspecs->add('b');
     $cmdspecs->add('c');
     $subcommands = array('subcommand1', 'subcommand2', 'subcommand3');
     $subcommand_specs = array('subcommand1' => $cmdspecs, 'subcommand2' => $cmdspecs, 'subcommand3' => $cmdspecs);
     $subcommand_options = array();
     $arguments = array();
     $argv = explode(' ', 'program -v -d -c subcommand1 -a -b -c subcommand2 -c subcommand3 arg1 arg2 arg3');
     $parser = new ContinuousOptionParser($appspecs);
     ok($parser);
     $app_options = $parser->parse($argv);
     while (!$parser->isEnd()) {
         if (@$subcommands[0] && $parser->getCurrentArgument() == $subcommands[0]) {
             $parser->advance();
             $subcommand = array_shift($subcommands);
             $parser->setSpecs($subcommand_specs[$subcommand]);
             $subcommand_options[$subcommand] = $parser->continueParse();
         } else {
             $arguments[] = $parser->advance();
         }
     }
     count_ok(3, $arguments);
     is('arg1', $arguments[0]);
     is('arg2', $arguments[1]);
     is('arg3', $arguments[2]);
     ok($subcommand_options);
     ok($subcommand_options['subcommand1']);
     ok($subcommand_options['subcommand1']->a);
     ok($subcommand_options['subcommand1']->b);
     ok($subcommand_options['subcommand1']->c);
     ok($subcommand_options['subcommand2']);
     ok(!$subcommand_options['subcommand2']->a);
     ok(!$subcommand_options['subcommand2']->b);
     ok($subcommand_options['subcommand2']->c);
     ok($subcommand_options['subcommand3']);
 }
Esempio n. 10
0
 public function testManyToManyRelationFetch()
 {
     $author = new Author();
     $author->create(array('name' => 'Z', 'email' => 'z@z', 'identity' => 'z'));
     // XXX: in different database engine, it's different.
     // sometimes it's string, sometimes it's integer
     // ok( is_string( $author->getValue('id') ) );
     ok(is_integer($author->get('id')));
     $book = $author->books->create(array('title' => 'Book Test'));
     ok($book);
     ok($book->id, 'book is created');
     $ret = $book->delete();
     ok($ret->success);
     $ab = new \AuthorBooks\Model\AuthorBook();
     $book = new \AuthorBooks\Model\Book();
     // should not include this
     ok($book->create(array('title' => 'Book I Ex'))->success);
     ok($book->create(array('title' => 'Book I'))->success);
     ok($ab->create(array('author_id' => $author->id, 'book_id' => $book->id))->success);
     ok($book->create(array('title' => 'Book II'))->success);
     $ab->create(array('author_id' => $author->id, 'book_id' => $book->id));
     ok($book->create(array('title' => 'Book III'))->success);
     $ab->create(array('author_id' => $author->id, 'book_id' => $book->id));
     // retrieve books from relationshipt
     $author->flushCache();
     $books = $author->books;
     is(3, $books->size(), 'We have 3 books');
     $bookTitles = array();
     foreach ($books->items() as $item) {
         $bookTitles[$item->title] = true;
         $item->delete();
     }
     count_ok(3, array_keys($bookTitles));
     ok($bookTitles['Book I']);
     ok($bookTitles['Book II']);
     ok($bookTitles['Book III']);
     ok(!isset($bookTitles['Book I Ex']));
     $author->delete();
 }
Esempio n. 11
0
 /**
  * @depends testControllerConstructor
  */
 public function testMountNoExpand($controller)
 {
     $mainMux = new Mux();
     $mainMux->expand = false;
     $mainMux->mount('/product', $controller);
     $mainMux->any('/', array('ProductController', 'indexAction'));
     ok($mainMux->getRoutes());
     count_ok(2, $mainMux->getRoutes(), 'route count should be 2');
     ok($r = $mainMux->dispatch('/product'), 'matched /product');
     // match indexAction
     $this->assertSame(array('CRUDProductController', 'indexAction'), $r[2]);
     ok($r = $mainMux->dispatch('/product/add'));
     $this->assertSame(array('CRUDProductController', 'addAction'), $r[2]);
     ok($r = $mainMux->dispatch('/product/del'));
     $this->assertSame(array('CRUDProductController', 'delAction'), $r[2]);
     ok(null == $mainMux->dispatch('/foo'));
     ok(null == $mainMux->dispatch('/bar'));
 }
Esempio n. 12
0
 public function testManyToManyRelationFetchRecord()
 {
     $author = new \AuthorBooks\Model\Author();
     $author->create(array('name' => 'Z', 'email' => 'z@z', 'identity' => 'z'));
     $book = $author->books->create(array('title' => 'Book Test'));
     ok($book);
     ok($book->id, 'book is created');
     $ret = $book->delete();
     ok($ret->success);
     $ab = new \AuthorBooks\Model\AuthorBook();
     $book = new \AuthorBooks\Model\Book();
     // should not include this
     ok($book->create(array('title' => 'Book I Ex'))->success);
     ok($book->create(array('title' => 'Book I'))->success);
     result_ok($ab->create(array('author_id' => $author->id, 'book_id' => $book->id)));
     ok($book->create(array('title' => 'Book II'))->success);
     $ab->create(array('author_id' => $author->id, 'book_id' => $book->id));
     ok($book->create(array('title' => 'Book III'))->success);
     $ab->create(array('author_id' => $author->id, 'book_id' => $book->id));
     // retrieve books from relationshipt
     $author->flushCache();
     $books = $author->books;
     is(3, $books->size(), 'We have 3 books');
     $bookTitles = array();
     foreach ($books->items() as $item) {
         $bookTitles[$item->title] = true;
         $item->delete();
     }
     count_ok(3, array_keys($bookTitles));
     ok($bookTitles['Book I']);
     ok($bookTitles['Book II']);
     ok($bookTitles['Book III']);
     ok(!isset($bookTitles['Book I Ex']));
     $author->delete();
 }
 public function testModelColumnDefaultValueBuilder()
 {
     $name = new \TestApp\Model\Name();
     $ret = $name->create(array('name' => 'Foo', 'country' => 'Taiwan'));
     $this->assertResultSuccess($ret);
     $this->assertNotEmpty($ret->validations);
     $this->assertTrue(isset($ret->validations['address']));
     $this->assertTrue($ret->validations['address']['valid']);
     ok($vlds = $ret->getSuccessValidations());
     count_ok(1, $vlds);
     ok($name->id);
     ok($name->address);
     $ret = $name->create(array('name' => 'Foo', 'address' => 'f**k', 'country' => 'Tokyo'));
     ok($ret->validations);
     foreach ($ret->getErrorValidations() as $vld) {
         $this->assertFalse($vld['valid']);
         $this->assertEquals('Please don\'t', $vld['message']);
     }
 }
Esempio n. 14
0
 public function testSpecCollection()
 {
     $this->specs->add('f|foo:', 'option requires a value.');
     $this->specs->add('b|bar+', 'option with multiple value.');
     $this->specs->add('z|zoo?', 'option with optional value.');
     $this->specs->add('v|verbose', 'verbose message.');
     $this->specs->add('d|debug', 'debug message.');
     $this->specs->add('long', 'long option name only.');
     $this->specs->add('s', 'short option name only.');
     ok($this->specs->all());
     ok($this->specs);
     count_ok(7, $array = $this->specs->toArray());
     $this->assertNotEmpty(isset($array[0]['long']));
     $this->assertNotEmpty(isset($array[0]['short']));
     $this->assertNotEmpty(isset($array[0]['desc']));
 }
Esempio n. 15
0
 function testSpecCollection()
 {
     $opt = new \GetOptionKit\GetOptionKit();
     ok($opt);
     $opt->add('f|foo:', 'option requires a value.');
     $opt->add('b|bar+', 'option with multiple value.');
     $opt->add('z|zoo?', 'option with optional value.');
     $opt->add('v|verbose', 'verbose message.');
     $opt->add('d|debug', 'debug message.');
     $opt->add('long', 'long option name only.');
     $opt->add('s', 'short option name only.');
     ok($opt->specs->all());
     ok($opt->specs);
     ok($opt->getSpecs());
     count_ok(7, $array = $opt->specs->toArray());
     ok(isset($array[0]['long']));
     ok(isset($array[0]['short']));
     ok(isset($array[0]['description']));
     ob_start();
     $opt->specs->printOptions();
     $content = ob_get_contents();
     ob_clean();
     like('/option with/m', $content);
     # echo "\n".$content;
 }
Esempio n. 16
0
 public function testFilter()
 {
     $book = new \AuthorBooks\Model\Book();
     $results = array();
     result_ok($results[] = $book->create(array('title' => 'My Book I')));
     result_ok($results[] = $book->create(array('title' => 'My Book II')));
     result_ok($results[] = $book->create(array('title' => 'Perl Programming')));
     result_ok($results[] = $book->create(array('title' => 'My Book IV')));
     $books = new \AuthorBooks\Model\BookCollection();
     $books->fetch();
     count_ok(4, $books);
     $perlBooks = $books->filter(function ($item) {
         return $item->title == 'Perl Programming';
     });
     ok($perlBooks);
     is(1, $perlBooks->size());
     count_ok(1, $perlBooks->items());
     foreach ($results as $result) {
         ok($result->id);
         $record = new Book($result->id);
         $record->delete();
     }
     $someBooks = $books->splice(0, 2);
     is(2, count($someBooks));
 }
Esempio n. 17
0
 /**
  * @depends testBasicRoutes
  */
 public function testMuxAddPCRERoute($mux)
 {
     $routes = $mux->getRoutes();
     ok($routes);
     count_ok(2, $routes);
     is(2, $mux->length());
 }
Esempio n. 18
0
 public function testSplitWords()
 {
     $words = CompletionUtils::split_words("foo bar zoo");
     ok($words);
     count_ok(3, $words);
 }