require_once dirname(__FILE__) . '/helper/dmUnitTestHelper.php'; $helper = new dmUnitTestHelper(); $helper->boot(); $t = new lime_test(39); dmDb::table('DmMediaFolder')->checkRoot(); $t->comment('Create a test image media'); $mediaFileName = 'test_' . dmString::random() . '.jpg'; copy(dmOs::join(sfConfig::get('dm_core_dir'), 'data/image/defaultMedia.jpg'), dmOs::join(sfConfig::get('sf_upload_dir'), $mediaFileName)); $media = dmDb::create('DmMedia', array('file' => $mediaFileName, 'dm_media_folder_id' => dmDb::table('DmMediaFolder')->checkRoot()->id))->saveGet(); $t->ok($media->exists(), 'A test media has been created'); $v = new dmValidatorLinkUrl(); // ->clean() $t->diag('->clean()'); foreach (array('http://www.google.com', 'https://google.com/', 'https://google.com:80/', 'http://www.symfony-project.com/', 'http://127.0.0.1/', 'http://127.0.0.1:80/', 'ftp://google.com/foo.tgz', 'ftps://google.com/foo.tgz', 'page:' . dmDb::table('DmPage')->findOne()->id, 'media:' . $media->id, 'page:' . dmDb::table('DmPage')->findOne()->id . ' some text after', 'media:' . $media->id . ' some text after', '#', '#anchor', '@my_route') as $url) { try { $t->is($v->clean($url), $url, '->clean() checks that the value is a valid URL'); } catch (sfValidatorError $e) { $t->fail('->clean() throws an sfValidatorError: ' . $e->getMessage()); } } foreach (array('google.com', 'http:/google.com', 'http://google.com::aa', 'page:a', 'media:a', 'page: some text', 'media: some text', 'page:0', 'media:0', 'page:0 some text after', 'media:0 some text after') as $nonUrl) { try { $v->clean($nonUrl); $t->fail('->clean() throws an sfValidatorError if the value is not a valid URL'); $t->skip('', 1); } catch (sfValidatorError $e) { $t->pass('->clean() throws an sfValidatorError if the value is not a valid URL'); $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError'); } } $v = new sfValidatorUrl(array('protocols' => array('http', 'https')));
$helper->clearDatabase($t); $loremizer = $helper->get('record_loremizer'); $t->is(dmDb::table('DmTestPost')->count(), 0, 'No post exist'); for ($it = 1; $it < 4; $it++) { $t->comment('Loremize a new comment'); $comment = $loremizer->execute(new DmTestComment()); $t->comment('Save generated comment'); $comment->save(); $t->ok($comment->exists(), 'The comment has been saved'); $t->is(dmDb::table('DmTestComment')->count(), $it, $it . ' comments exist'); $post = $comment->Post; $t->ok($post->exists(), 'A post has been created'); $t->is(dmDb::table('DmTestPost')->count(), 1, 'Only one post exists'); $t->is(dmDb::table('DmTestCateg')->count(), 1, 'Only one categ exists'); $v = new dmValidatorLinkUrl(array('required' => false)); $t->is($post->url, $v->clean($post->url), 'Post url is valid: ' . $post->url); $categ = $post->Categ; $t->ok($categ->exists(), 'A categ has been created'); $t->is($categ->Domains->count(), 0, 'The categ has no domain'); $t->is(dmDb::table('DmTestDomain')->count(), 0, 'No domain exist'); } $t->is(dmDb::table('DmTestFruit')->count(), 0, 'No fruit exist'); $t->comment('Delete categ'); $categ->delete(); $t->comment('Loremize a new domain'); $domain = $loremizer->execute(new DmTestDomain()); $t->ok($domain->hasCurrentTranslation(), 'domain has a current translation'); $t->comment('Save generated domain'); $domain->save(); $t->ok($domain->exists(), 'The domain exists'); $t->ok($domain->title, 'The domain title is ' . $domain->title);