php - PHPUnit Symfony 1.4 url_for returning wrong URL -
i'm trying create unit test specific function returns given url switch based on set of params. fine until return url_for.
here's returned output:
http:///opt/ipc/bin/phpunit/phpunit/nikon-d7200-review http:///opt/ipc/bin/phpunit/phpunit/nikon-d7200-review http:///opt/ipc/bin/phpunit/phpunit/benq-gw2765-specs http:///opt/ipc/bin/phpunit/phpunit/benq-gw2765-photos-2 http:///opt/ipc/bin/phpunit/phpunit/benq-gw2765-photos-2 http:///opt/ipc/bin/phpunit/phpunit/benq-gw2765-best-deals http:///opt/ipc/bin/phpunit/phpunit/nikon-d7200-user-reviews http:///opt/ipc/bin/phpunit/phpunit/canon-eos-7d-mkii-video-review http:///opt/ipc/bin/phpunit/phpunit/best-mobile-puzzle-games_round-up http:///opt/ipc/bin/phpunit/phpunit/best-mobile-puzzle-games_round-up http:///opt/ipc/bin/phpunit/phpunit/best-mobile-puzzle-games_round-up http:///opt/ipc/bin/phpunit/phpunit/best-mobile-puzzle-games_round-up http:///opt/ipc/bin/phpunit/phpunit/round-ups/laptops http:///opt/ipc/bin/phpunit/phpunit/news/wearables-fitness http:///opt/ipc/bin/phpunit/phpunit/opinions/5-ways-the-humble-light-bulb-is-being-reinvented http:///opt/ipc/bin/phpunit/phpunit/opinions/5-ways-the-humble-light-bulb-is-being-reinvented http:///opt/ipc/bin/phpunit/phpunit/digital-cameras http:///opt/ipc/bin/phpunit/phpunit/cameras http:///opt/ipc/bin/phpunit/phpunit/info/evan-kypreos http:///opt/ipc/bin/phpunit/phpunit/default/vitamix-s30
as can see returning url has replaced site url phunit version. returned url more this:
http://www.somesite.com/nikon-d7200-review http://www.somesite.com/benq-gw2765-specs http://www.somesite.com/benq-gw2765-photos-2 http://www.somesite.com/benq-gw2765-best-deals http://www.somesite.com/nikon-d7200-user-reviews http://www.somesite.com/canon-eos-7d-mkii-video-review http://www.somesite.com/best-mobile-puzzle-games_round-up
i'm using command line run tests.
if need more information please i'll best explain further.
the function causing issue this...
url_for('@round_up?slug=digital_cameras', true);
and test script
class api2compositionshelpertest extends phpunit_framework_testcase { public function setup(){} public function teardown() {} public function testurlforitemtype() { if(function_exists('url_for_itemtype')) { /** * create stubs function. itemtype => params * * params avaliable * - itemslug * - absolute * - page * - pagetile * - itemindex * - itemcategoryidentifier */ $stub = array( 'itemtype' => array( // todo: find out if preview being used. // 'preview' => array( // 'itemslug' => '', // 'absolute' => '', // 'page' => '', // 'pagetile' => '', // 'itemindex' => '' //), 'review' => array( 'itemslug' => 'nikon-d7200', 'pagetitle' => 'image-quality-performance-and-verdict', ), 'reviews' => array( 'itemslug' => 'nikon-d7200', 'pagetitle' => 'image-quality-performance-and-verdict', 'page' => 2 ), 'review_specs' => array( 'itemslug' => 'benq-gw2765' ), 'review_photo' => array( 'itemslug' => 'benq-gw2765', ), 'review_photos' => array( 'itemslug' => 'benq-gw2765', 'itemindex' => 2 ), 'review_compareprices' => array( 'itemslug' => 'benq-gw2765', ), // todo: check recombu deals still being used. //'review_recombudeals' => array( // 'itemslug' => null, // 'absolute' => null, // 'page' => null, // 'pagetile' => null, // 'itemindex' => null, // 'itemcategoryidentifier' => null //), 'review_userreviews' => array( 'itemslug' => 'nikon-d7200' ), 'review_video' => array( 'itemslug' => 'canon-eos-7d-mkii' ), 'roundup|roundups|round_up|round_ups' => array( 'itemslug' => 'best-mobile-puzzle-games' ), 'round_up_index' => array( 'itemslug' => 'laptops' ), 'news' => array( 'itemslug' => 'wearables-fitness' ), 'opinion|opinions' => array( 'itemslug' => '5-ways-the-humble-light-bulb-is-being-reinvented' ), 'category' => array( 'itemslug' => 'digital-cameras' ), 'root_category' => array( 'itemslug' => 'cameras' ), 'author' => array( 'itemslug' => 'evan-kypreos' ), 'default' => array( 'itemslug' => 'vitamix-s30' ) ) ); // loop through foreach($stub['itemtype'] $itemtype => $params) { $itemtype = explode('|', $itemtype); foreach($itemtype $itemtype) { // test params $route = url_for_itemtype( array_merge( array( 'itemtype' => $itemtype ), $params ) ); // check url. switch($itemtype) { case 'preview': // see above todo break; case 'review': case 'reviews': if(isset($params['page'])) { $pattern = '^www.trustedreviews.com\/([a-za-z0-9-]+)review([a-za-z-]+)page([-0-9]+)^'; } else { $pattern = '^http:\/\/www.trustedreviews.com\/([a-za-z0-9-]+)-review^'; } break; case 'review_specs': $pattern = '^http:\/\/www.trustedreviews.com\/([a-za-z0-9-]+)specs^'; break; case 'review_photo': case 'review_photos': if(isset($params['itemindex'])) { $pattern = '^http:\/\/www.trustedreviews.com\/([a-za-z0-9-]+)photos([0-9-]+)^'; } else { $pattern = '^http:\/\/www.trustedreviews.com\/([a-za-z0-9-]+)photos^'; } break; case 'review_compareprices': $pattern = '^http:\/\/www.trustedreviews.com\/([a-za-z0-9-]+)best-deals^'; break; case 'review_recombudeals': // see above todo break; case 'review_userreviews': $pattern = '^http:\/\/www.trustedreviews.com\/([a-za-z0-9-]+)user-reviews^'; break; case 'review_video': $pattern = '^http:\/\/www.trustedreviews.com\/([a-za-z0-9-]+)video-review^'; break; case 'roundup': case 'roundups': case 'round_up': case 'round_ups': $pattern = '^http:\/\/www.trustedreviews.com\/([a-za-z0-9-]+)_round-up^'; break; case 'round_up_index': $pattern = '^http:\/\/www.trustedreviews.com\/round-ups\/([a-za-z0-9-]+)^'; break; case 'news': $pattern = '^http:\/\/www.trustedreviews.com\/news\/([a-za-z0-9-]+)^'; break; case 'opinion': case 'opinions': $pattern = '^http:\/\/www.trustedreviews.com\/opinions\/([a-za-z0-9-]+)^'; break; case 'category': $pattern = '^http:\/\/www.trustedreviews.com\/([a-za-z0-9-]+)^'; break; case 'root_category': $pattern = '^http:\/\/www.trustedreviews.com\/([a-za-z0-9-]+)^'; break; case 'author': $pattern = '^http:\/\/www.trustedreviews.com\/info\/([a-za-z0-9-]+)^'; break; default: // todo: research pattern default $pattern = '^http:\/\/www.trustedreviews.com\/([a-za-z0-9-]+)^'; break; } // check pattern matches url structure $this->assertregexp($pattern, $route); } } } else { $this->assertfalse(true); } } }
thanks.
try this, did generate links in sitemaps in cli task, looks similar need:
$context = sfcontext::createinstance($this->configuration); $context->getconfiguration()->loadhelpers('partial'); $routing = $context->getrouting(); $routingoptions = $routing->getoptions(); $routingoptions['context']['prefix'] = ''; $routingoptions['context']['host'] = sfconfig::get('sf_host'); $routing->initialize($this->dispatcher, $routing->getcache(), $routingoptions);
Comments
Post a Comment