[pLog-svn] r3851 - in plog/trunk/class: dao test/tests/dao

oscar at devel.lifetype.net oscar at devel.lifetype.net
Wed Aug 9 18:10:33 GMT 2006


Author: oscar
Date: 2006-08-09 18:10:32 +0000 (Wed, 09 Aug 2006)
New Revision: 3851

Added:
   plog/trunk/class/test/tests/dao/blogs_test.class.php
Modified:
   plog/trunk/class/dao/blogs.class.php
Log:
fixed an issue with blog names (the "mangled name") not being unique, and added a test case to verify that now it works as it should


Modified: plog/trunk/class/dao/blogs.class.php
===================================================================
--- plog/trunk/class/dao/blogs.class.php	2006-08-09 17:04:21 UTC (rev 3850)
+++ plog/trunk/class/dao/blogs.class.php	2006-08-09 18:10:32 UTC (rev 3851)
@@ -104,9 +104,13 @@
         {
 			// load the previous version of this blog
 			$prevVersion = $this->getBlogInfo( $blog->getId());
+			
+			// check that the mangled_blog field is unique
+            $mangledBlog = $blog->getMangledBlogName();
+            $i = 1;
+			
 			if( ($result = $this->update( $blog ))) {
 				// reset the caches
-                // TODO: jondaley: is this doing the right thing?
 				$this->_cache->removeData( $blog->getCustomDomain(), CACHE_BLOGIDBYDOMAIN );
 				$this->_cache->removeData( $blog->getMangledBlogName(), CACHE_BLOGIDBYNAME );
 				$this->_cache->removeData( $blog->getId(), CACHE_BLOGINFOS );
@@ -144,6 +148,18 @@
             if( !$blogSettings )
                 $blogSettings = new BlogSettings();
 
+			// check that the mangled_blog field is unique
+            $mangledBlog = $blog->getMangledBlogName();
+            $i = 1;
+            // check if there already is a blog with the same mangled name
+            while($this->getBlogInfoByName( $mangledBlog ))
+            {
+                $i++;
+                $mangledBlog = substr($mangledBlog, 0,
+                               ($i > 2) ? strlen($mangledBlog)-strlen($i-1) : strlen($mangledBlog)).$i;
+            }
+            $blog->setMangledBlogName($mangledBlog);
+
 			$blogId = $this->add( $blog );
 			
 			// update blog categories

Added: plog/trunk/class/test/tests/dao/blogs_test.class.php
===================================================================
--- plog/trunk/class/test/tests/dao/blogs_test.class.php	2006-08-09 17:04:21 UTC (rev 3850)
+++ plog/trunk/class/test/tests/dao/blogs_test.class.php	2006-08-09 18:10:32 UTC (rev 3851)
@@ -0,0 +1,46 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+
+	/**
+	 * \ingroup Test
+	 *
+	 * Test cases for the Blogs class
+	 */
+	class Blogs_Test extends LifeTypeTestCase
+	{
+		/** 
+		 * regression test for Mantis 1005 (http://bugs.lifetype.net/view.php?id=1005)
+		 */
+		function testAddBlogUniqueMangledBlog()
+		{
+			$blogs = new Blogs();
+			
+			// create two blogs, both with the same name. The mangled_blog field should be 'xxx' for the first
+			// one that was added and 'xxx2' for the second one. If not, throw an error.
+			
+			// an absolutely random name
+			$randomName = md5(time());
+			
+			// add the blogs
+			$blog1 = new BlogInfo( $randomName, 1, "About blog 1", new BlogSettings());
+			$blog2 = new BlogInfo( $randomName, 1, "About blog 2", new BlogSettings());
+			$blog3 = new BlogInfo( $randomName, 1, "About blog 3", new BlogSettings());			
+			$blogs->addBlog( $blog1 );
+			$blogs->addBlog( $blog2 );
+			$blogs->addBlog( $blog3 );			
+			
+			// compare the mangled names
+			$this->assertEquals( $randomName, $blog1->getMangledBlogName());
+			$this->assertEquals( $randomName."2", $blog2->getMangledBlogName());
+			$this->assertEquals( $randomName."3", $blog3->getMangledBlogName());		
+			
+			// delete the temporary blogs
+			$blogs->deleteBlog( $blog1->getId());
+			$blogs->deleteBlog( $blog2->getId());
+			$blogs->deleteBlog( $blog3->getId());
+		}
+	}
+?>
\ No newline at end of file



More information about the pLog-svn mailing list