diff options
Diffstat (limited to 'pharo-mooc/tiny-blog/src/TinyBlog-Tests')
3 files changed, 112 insertions, 0 deletions
diff --git a/pharo-mooc/tiny-blog/src/TinyBlog-Tests/TBBlogTest.class.st b/pharo-mooc/tiny-blog/src/TinyBlog-Tests/TBBlogTest.class.st new file mode 100644 index 0000000..2b00d97 --- /dev/null +++ b/pharo-mooc/tiny-blog/src/TinyBlog-Tests/TBBlogTest.class.st @@ -0,0 +1,81 @@ +Class { + #name : 'TBBlogTest', + #superclass : 'TestCase', + #instVars : [ + 'blog', + 'post', + 'first', + 'previousRepository' + ], + #category : 'TinyBlog-Tests', + #package : 'TinyBlog-Tests' +} + +{ #category : 'running' } +TBBlogTest >> setUp [ + previousRepository := VORepository current. + VORepository setRepository: VOMemoryRepository new. + blog := TBBlog current. + first := TBPost title: 'A title' text: 'A text' category: 'First Category'. + blog writeBlogPost: first. + + post := (TBPost title: 'Another title' text: 'Another text' category: 'Second Category') beVisible +] + +{ #category : 'running' } +TBBlogTest >> tearDown [ + VORepository setRepository: previousRepository +] + +{ #category : 'tests' } +TBBlogTest >> testAddBlogPost [ + blog writeBlogPost: post. + self assert: blog size equals: 2 +] + +{ #category : 'tests' } +TBBlogTest >> testAllBlogPosts [ + blog writeBlogPost: post. + self assert: blog allBlogPosts size equals: 2 +] + +{ #category : 'tests' } +TBBlogTest >> testAllBlogPostsFromCategory [ + self assert: (blog allBlogPostsFromCategory: 'First Category') + size equals: 1 +] + +{ #category : 'tests' } +TBBlogTest >> testAllCategories [ + blog writeBlogPost: post. + self assert: blog allCategories size equals: 2 +] + +{ #category : 'tests' } +TBBlogTest >> testAllVisibleBlogPosts [ + blog writeBlogPost: post. + self assert: blog allVisibleBlogPosts size equals: 1 +] + +{ #category : 'tests' } +TBBlogTest >> testAllVisibleBlogPostsFromCategory [ + blog writeBlogPost: post. + self assert: (blog allVisibleBlogPostsFromCategory: 'First Category') size equals: 0. + self assert: (blog allVisibleBlogPostsFromCategory: 'Second Category') size equals: 1. +] + +{ #category : 'tests' } +TBBlogTest >> testRemoveAllBlogPosts [ + blog removeAllPosts. + self assert: blog size equals: 0 +] + +{ #category : 'tests' } +TBBlogTest >> testSize [ + self assert: blog size equals: 1 +] + +{ #category : 'tests' } +TBBlogTest >> testUnclassifiedBlogPosts [ + self assert: (blog allBlogPosts select: [ :p | p isUnclassified ]) size equals: 0 +] diff --git a/pharo-mooc/tiny-blog/src/TinyBlog-Tests/TBPostTest.class.st b/pharo-mooc/tiny-blog/src/TinyBlog-Tests/TBPostTest.class.st new file mode 100644 index 0000000..d9a2f78 --- /dev/null +++ b/pharo-mooc/tiny-blog/src/TinyBlog-Tests/TBPostTest.class.st @@ -0,0 +1,30 @@ +Class { + #name : 'TBPostTest', + #superclass : 'TestCase', + #category : 'TinyBlog-Tests', + #package : 'TinyBlog-Tests' +} + +{ #category : 'tests' } +TBPostTest >> testPostIsCreatedCorrectly [ + + | post | + post := TBPost + title: 'Welcome to TinyBlog' + text: 'TinyBlog is a small blog engine made with Pharo.' + category: 'TinyBlog'. + self assert: post title equals: 'Welcome to TinyBlog'. + self assert: post text equals: 'TinyBlog is a small blog engine made with Pharo.'. +] + +{ #category : 'tests' } +TBPostTest >> testWithoutCategoryIsUnclassified [ + + | post | + post := TBPost + title: 'Welcome to TinyBlog' + text: 'TinyBlog is a small blog engine made with Pharo.'. + self assert: post title equals: 'Welcome to TinyBlog'. + self assert: post isUnclassified. + self deny: post isVisible +] diff --git a/pharo-mooc/tiny-blog/src/TinyBlog-Tests/package.st b/pharo-mooc/tiny-blog/src/TinyBlog-Tests/package.st new file mode 100644 index 0000000..27356f6 --- /dev/null +++ b/pharo-mooc/tiny-blog/src/TinyBlog-Tests/package.st @@ -0,0 +1 @@ +Package { #name : 'TinyBlog-Tests' } |
