From ce6402f8d029d052c27dfdbf9db0c35e9f05bbb9 Mon Sep 17 00:00:00 2001 From: Saophalkun Ponlu Date: Sun, 24 May 2009 12:16:17 +0000 Subject: [PATCH] ENHANCEMENT: use image file name (without file path and extension) for alt attribute when title is not provided git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@77668 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/Image.php | 9 ++++++ tests/model/ImageTest.php | 29 ++++++++++++++++++ tests/model/ImageTest.yml | 8 +++++ .../model/testimages/test.image.with.dots.png | Bin 0 -> 4423 bytes tests/model/testimages/test_image.png | Bin 0 -> 4423 bytes 5 files changed, 46 insertions(+) create mode 100644 tests/model/ImageTest.php create mode 100644 tests/model/ImageTest.yml create mode 100644 tests/model/testimages/test.image.with.dots.png create mode 100644 tests/model/testimages/test_image.png diff --git a/core/model/Image.php b/core/model/Image.php index 7879fcc3b..83708e2f8 100755 --- a/core/model/Image.php +++ b/core/model/Image.php @@ -102,6 +102,15 @@ class Image extends File { $url = $this->URL(); $title = ($this->Title) ? $this->Title : $this->Filename; + if ($this->Title) { + $title = $this->Title; + } + else { + // use the file name (without path and extension) for alt atttribute when the title is not defined + $title = $this->Filename; + if (preg_match("/([^\/]*)\.[a-zA-Z0-9]{1,6}$/", $title, $matches)) $title = $matches[1]; + } + return "\"$title\""; } } diff --git a/tests/model/ImageTest.php b/tests/model/ImageTest.php new file mode 100644 index 000000000..f6f892ba4 --- /dev/null +++ b/tests/model/ImageTest.php @@ -0,0 +1,29 @@ +fixture->objFromFixture('Image', 'imageWithTitle'); + $expected = 'This is a image Title'; + $actual = $image->getTag(); + + $this->assertEquals($expected, $actual); + } + + function testGetTagWithoutTitle() { + $image = $this->fixture->objFromFixture('Image', 'imageWithoutTitle'); + $expected = 'test_image'; + $actual = $image->getTag(); + + $this->assertEquals($expected, $actual); + } + + function testGetTagWithoutTitleContainingDots() { + $image = $this->fixture->objFromFixture('Image', 'imageWithoutTitleContainingDots'); + $expected = 'test.image.with.dots'; + $actual = $image->getTag(); + + $this->assertEquals($expected, $actual); + } +} +?> \ No newline at end of file diff --git a/tests/model/ImageTest.yml b/tests/model/ImageTest.yml new file mode 100644 index 000000000..828702abb --- /dev/null +++ b/tests/model/ImageTest.yml @@ -0,0 +1,8 @@ +Image: + imageWithTitle: + Title: This is a image Title + Filename: sapphire/tests/model/testimages/test_image.png + imageWithoutTitle: + Filename: sapphire/tests/model/testimages/test_image.png + imageWithoutTitleContainingDots: + Filename: sapphire/tests/model/testimages/test.image.with.dots.png \ No newline at end of file diff --git a/tests/model/testimages/test.image.with.dots.png b/tests/model/testimages/test.image.with.dots.png new file mode 100644 index 0000000000000000000000000000000000000000..a95602a86d3d842e97ed84b7ec68ea089b1d7926 GIT binary patch literal 4423 zcmV-N5xDM&P)ExQj};**2-S_|F6CD)=PWobG+~%OOF&;RTvY1zd%11$v!L~hZt_$ zxS3u2+rRwNJkM2C^e}uVqT9EVjJl zEtf@8l-`zAQ>Hzw+jMU#Dp-Q&FcQb$!>??P8~SF?rkaIE+={W3DYhcdTU8fr-_=cH_jO*DZRM-g%2d@6 z$UP$LQ`Jql!+6$J)t2+d#TbzGb>oD6Yg1Cn>sFqbJ&vs^Jt?+wm)x?Hfr3r``}+DS z7k z(!Z>0VRSCNP1})^qzS>^i%);yb6u;C66RQt_eFdSlnfcLQdx8$#{?@eCj4cDm76oj zA{>#mzR5XTj&T91vbW6w8uMzSrtg$q)AVm|vdXKiTBfR!{7A%laZ z+t#sAQ3$lqr7%l{2XvbNNQ4UR&_UiN$rLBKFa;S%$8i)nIB7|(sbzJ>!~-k`rYBFN zReS+IXUlbxRi)0SZGj?ckZ0>O&4X`DYrDqYysM+!0xOj$%T`XgII6a*`o0f5M@27D z0eGx!p=X7y{jiF`H6&LjVQ!ujDpBNP%AQPsBBtkzdd^BeQhB-zSwX@m*eYVR1**&A zG{6L9e(Zn6pmAj(!S6L*HYKxrKl>J>Kt7h1WqAzakA0pd3v`#>JcNk+xY1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v`DM#!D5?Ug4w>z(htQ+wytEW=#@JTO4OzNUczy0I<* zl+K0Z9NEpS&_8~gWcK8jD>s{KJAnWZ^qVf4M01WSxhk&s!l*cAvFQ=wXOSzZ@mCB3 z?-2V}!_`B=j_lCDg;`u3A7xOoaRw&)^y%~M?PIi^f-dbGEO;-gkjuB4($v0)j9BN;Buha{u+$ziZp-zyA9_s7N-w++Mi!=l8#$r1STg=RJkkxq_>z{{zc$T7t3G2h#um N002ovPDHLkV1lL@mev3O literal 0 HcmV?d00001 diff --git a/tests/model/testimages/test_image.png b/tests/model/testimages/test_image.png new file mode 100644 index 0000000000000000000000000000000000000000..a95602a86d3d842e97ed84b7ec68ea089b1d7926 GIT binary patch literal 4423 zcmV-N5xDM&P)ExQj};**2-S_|F6CD)=PWobG+~%OOF&;RTvY1zd%11$v!L~hZt_$ zxS3u2+rRwNJkM2C^e}uVqT9EVjJl zEtf@8l-`zAQ>Hzw+jMU#Dp-Q&FcQb$!>??P8~SF?rkaIE+={W3DYhcdTU8fr-_=cH_jO*DZRM-g%2d@6 z$UP$LQ`Jql!+6$J)t2+d#TbzGb>oD6Yg1Cn>sFqbJ&vs^Jt?+wm)x?Hfr3r``}+DS z7k z(!Z>0VRSCNP1})^qzS>^i%);yb6u;C66RQt_eFdSlnfcLQdx8$#{?@eCj4cDm76oj zA{>#mzR5XTj&T91vbW6w8uMzSrtg$q)AVm|vdXKiTBfR!{7A%laZ z+t#sAQ3$lqr7%l{2XvbNNQ4UR&_UiN$rLBKFa;S%$8i)nIB7|(sbzJ>!~-k`rYBFN zReS+IXUlbxRi)0SZGj?ckZ0>O&4X`DYrDqYysM+!0xOj$%T`XgII6a*`o0f5M@27D z0eGx!p=X7y{jiF`H6&LjVQ!ujDpBNP%AQPsBBtkzdd^BeQhB-zSwX@m*eYVR1**&A zG{6L9e(Zn6pmAj(!S6L*HYKxrKl>J>Kt7h1WqAzakA0pd3v`#>JcNk+xY1UPcu7^@ zT0I^Ku}#w?*xZKaq@Ys`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