workarea-blog 3.4.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +20 -0
  3. data/.eslintignore +2 -0
  4. data/.eslintrc +24 -0
  5. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  6. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  7. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  8. data/.gitignore +16 -0
  9. data/.rspec +2 -0
  10. data/.scss-lint.yml +188 -0
  11. data/.tailor +180 -0
  12. data/.yardopts +1 -0
  13. data/CHANGELOG.md +1123 -0
  14. data/CODE_OF_CONDUCT.md +3 -0
  15. data/CONTRIBUTING.md +3 -0
  16. data/Gemfile +7 -0
  17. data/LICENSE +52 -0
  18. data/README.md +140 -0
  19. data/Rakefile +42 -0
  20. data/app/assets/images/workarea/admin/blog/content_block_types/blog_entry.svg +1 -0
  21. data/app/assets/images/workarea/admin/blog/icons/blog.svg +1 -0
  22. data/app/assets/images/workarea/admin/blog/icons/blog_entry.svg +1 -0
  23. data/app/assets/images/workarea/admin/blog/icons/blog_post_comment.svg +1 -0
  24. data/app/assets/javascripts/workarea/storefront/blog/modules/blog_comment_placeholder.js +33 -0
  25. data/app/assets/stylesheets/workarea/admin/blog/components/_blog_entry_card.scss +14 -0
  26. data/app/assets/stylesheets/workarea/storefront/blog/components/_blog_entry.scss +91 -0
  27. data/app/assets/stylesheets/workarea/storefront/blog/components/_blog_entry_summary.scss +74 -0
  28. data/app/assets/stylesheets/workarea/storefront/blog/components/_featured_entry_content_block.scss +22 -0
  29. data/app/controllers/workarea/admin/application_controller.decorator +5 -0
  30. data/app/controllers/workarea/admin/content_blog_comments_controller.rb +54 -0
  31. data/app/controllers/workarea/admin/content_blog_entries_controller.rb +70 -0
  32. data/app/controllers/workarea/admin/content_blogs_controller.rb +56 -0
  33. data/app/controllers/workarea/admin/create_content_blog_entries_controller.rb +69 -0
  34. data/app/controllers/workarea/storefront/blog_comments_controller.rb +14 -0
  35. data/app/controllers/workarea/storefront/blog_entries_controller.rb +48 -0
  36. data/app/controllers/workarea/storefront/blogs_controller.rb +19 -0
  37. data/app/helpers/workarea/admin/blogs_helper.rb +61 -0
  38. data/app/models/workarea/content/blog.rb +26 -0
  39. data/app/models/workarea/content/blog_comment.rb +67 -0
  40. data/app/models/workarea/content/blog_entry.rb +35 -0
  41. data/app/models/workarea/content/fields/blog_entry_id.rb +11 -0
  42. data/app/models/workarea/content/fields/blog_id.rb +8 -0
  43. data/app/models/workarea/search/admin/content_blog.rb +27 -0
  44. data/app/models/workarea/search/admin/content_blog_entry.rb +37 -0
  45. data/app/queries/workarea/metadata/content_blog.rb +6 -0
  46. data/app/queries/workarea/metadata/content_blog_entry.rb +6 -0
  47. data/app/queries/workarea/search/admin_blog_entries.rb +24 -0
  48. data/app/queries/workarea/search/admin_blogs.rb +20 -0
  49. data/app/seeds/workarea/blog_comments_seeds.rb +26 -0
  50. data/app/seeds/workarea/blog_entry_seeds.rb +73 -0
  51. data/app/seeds/workarea/blog_seeds.rb +53 -0
  52. data/app/services/workarea/search/queries/blog_admin.rb +20 -0
  53. data/app/services/workarea/search/queries/blog_entry_admin.rb +13 -0
  54. data/app/services/workarea/set_navigable.decorator +10 -0
  55. data/app/view_models/workarea/admin/blog_comments_view_model.rb +45 -0
  56. data/app/view_models/workarea/admin/blog_entries_view_model.rb +31 -0
  57. data/app/view_models/workarea/admin/blog_entry_view_model.rb +29 -0
  58. data/app/view_models/workarea/admin/blog_search_view_model.rb +6 -0
  59. data/app/view_models/workarea/admin/blog_view_model.rb +13 -0
  60. data/app/view_models/workarea/storefront/blog_entry_view_model.rb +43 -0
  61. data/app/view_models/workarea/storefront/blog_index_view_model.rb +17 -0
  62. data/app/view_models/workarea/storefront/blog_view_model.rb +83 -0
  63. data/app/view_models/workarea/storefront/content_blocks/blog_entry_content_block_view_model.rb +63 -0
  64. data/app/views/workarea/admin/activities/_content_blog_comment_create.html.haml +12 -0
  65. data/app/views/workarea/admin/activities/_content_blog_comment_destroy.html.haml +9 -0
  66. data/app/views/workarea/admin/activities/_content_blog_comment_update.html.haml +10 -0
  67. data/app/views/workarea/admin/activities/_content_blog_create.html.haml +12 -0
  68. data/app/views/workarea/admin/activities/_content_blog_destroy.html.haml +10 -0
  69. data/app/views/workarea/admin/activities/_content_blog_entry_create.html.haml +12 -0
  70. data/app/views/workarea/admin/activities/_content_blog_entry_destroy.html.haml +10 -0
  71. data/app/views/workarea/admin/activities/_content_blog_entry_update.html.haml +10 -0
  72. data/app/views/workarea/admin/activities/_content_blog_update.html.haml +10 -0
  73. data/app/views/workarea/admin/blog/_dashboard_navigation.html.haml +1 -0
  74. data/app/views/workarea/admin/blog/_menu.html.haml +13 -0
  75. data/app/views/workarea/admin/content_blocks/_blog_entry_id.html.haml +4 -0
  76. data/app/views/workarea/admin/content_blocks/_blog_id.html.haml +3 -0
  77. data/app/views/workarea/admin/content_blog_comments/_summary.html.haml +24 -0
  78. data/app/views/workarea/admin/content_blog_comments/edit.html.haml +60 -0
  79. data/app/views/workarea/admin/content_blog_comments/index.html.haml +49 -0
  80. data/app/views/workarea/admin/content_blog_entries/_aux_navigation.html.haml +4 -0
  81. data/app/views/workarea/admin/content_blog_entries/_cards.html.haml +113 -0
  82. data/app/views/workarea/admin/content_blog_entries/_summary.html.haml +10 -0
  83. data/app/views/workarea/admin/content_blog_entries/edit.html.haml +75 -0
  84. data/app/views/workarea/admin/content_blog_entries/index.html.haml +80 -0
  85. data/app/views/workarea/admin/content_blog_entries/index.json.jbuilder +5 -0
  86. data/app/views/workarea/admin/content_blog_entries/show.html.haml +20 -0
  87. data/app/views/workarea/admin/content_blog_entries/thumbnail_image.html.haml +55 -0
  88. data/app/views/workarea/admin/content_blogs/_aux_navigation.html.haml +2 -0
  89. data/app/views/workarea/admin/content_blogs/_cards.html.haml +58 -0
  90. data/app/views/workarea/admin/content_blogs/_summary.html.haml +6 -0
  91. data/app/views/workarea/admin/content_blogs/edit.html.haml +51 -0
  92. data/app/views/workarea/admin/content_blogs/index.html.haml +76 -0
  93. data/app/views/workarea/admin/content_blogs/index.json.jbuilder +4 -0
  94. data/app/views/workarea/admin/content_blogs/new.html.haml +33 -0
  95. data/app/views/workarea/admin/content_blogs/show.html.haml +19 -0
  96. data/app/views/workarea/admin/create_content_blog_entries/content.html.haml +28 -0
  97. data/app/views/workarea/admin/create_content_blog_entries/featured_products.html.haml +71 -0
  98. data/app/views/workarea/admin/create_content_blog_entries/publish.html.haml +51 -0
  99. data/app/views/workarea/admin/create_content_blog_entries/setup.html.haml +61 -0
  100. data/app/views/workarea/admin/create_content_blog_entries/thumbnail_image.html.haml +48 -0
  101. data/app/views/workarea/storefront/blog_comments/index.html.haml +31 -0
  102. data/app/views/workarea/storefront/blog_entries/_summary.html.haml +25 -0
  103. data/app/views/workarea/storefront/blog_entries/show.html.haml +85 -0
  104. data/app/views/workarea/storefront/blog_metadata/_publisher.html.haml +7 -0
  105. data/app/views/workarea/storefront/blogs/_blog_navigation.html.haml +7 -0
  106. data/app/views/workarea/storefront/blogs/index.html.haml +25 -0
  107. data/app/views/workarea/storefront/blogs/show.atom.builder +26 -0
  108. data/app/views/workarea/storefront/blogs/show.html.haml +31 -0
  109. data/app/views/workarea/storefront/content_blocks/_blog_entry.html.haml +20 -0
  110. data/app/workers/workarea/generate_content_metadata.decorator +15 -0
  111. data/bin/rails +18 -0
  112. data/config/initializers/appends.rb +26 -0
  113. data/config/initializers/content_block_types.rb +13 -0
  114. data/config/initializers/jump_to_navigation.rb +3 -0
  115. data/config/initializers/seeds.rb +5 -0
  116. data/config/initializers/workarea.rb +15 -0
  117. data/config/locales/en.yml +244 -0
  118. data/config/routes.rb +49 -0
  119. data/data/blog_thumbnails/thumbnail_1.png +0 -0
  120. data/data/blog_thumbnails/thumbnail_2.png +0 -0
  121. data/data/blog_thumbnails/thumbnail_3.png +0 -0
  122. data/lib/tasks/import_wordpress.rake +13 -0
  123. data/lib/tasks/import_wordpress_attachments.rake +18 -0
  124. data/lib/tasks/import_wordpress_pages.rake +21 -0
  125. data/lib/tasks/import_wordpress_posts.rake +25 -0
  126. data/lib/workarea/blog/engine.rb +8 -0
  127. data/lib/workarea/blog/import/wordpress/attachment.rb +40 -0
  128. data/lib/workarea/blog/import/wordpress/content_cleaner.rb +64 -0
  129. data/lib/workarea/blog/import/wordpress/entry.rb +76 -0
  130. data/lib/workarea/blog/import/wordpress/entry_parser.rb +64 -0
  131. data/lib/workarea/blog/import/wordpress/page.rb +69 -0
  132. data/lib/workarea/blog/import/wordpress/page_parser.rb +50 -0
  133. data/lib/workarea/blog/version.rb +5 -0
  134. data/lib/workarea/blog.rb +11 -0
  135. data/test/dummy/Rakefile +6 -0
  136. data/test/dummy/app/assets/config/manifest.js +4 -0
  137. data/test/dummy/app/assets/images/.keep +0 -0
  138. data/test/dummy/app/assets/javascripts/application.js +13 -0
  139. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  140. data/test/dummy/app/controllers/application_controller.rb +3 -0
  141. data/test/dummy/app/controllers/concerns/.keep +0 -0
  142. data/test/dummy/app/helpers/application_helper.rb +2 -0
  143. data/test/dummy/app/jobs/application_job.rb +2 -0
  144. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  145. data/test/dummy/app/models/concerns/.keep +0 -0
  146. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  147. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  148. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  149. data/test/dummy/bin/bundle +3 -0
  150. data/test/dummy/bin/rails +4 -0
  151. data/test/dummy/bin/rake +4 -0
  152. data/test/dummy/bin/setup +34 -0
  153. data/test/dummy/bin/update +29 -0
  154. data/test/dummy/config/application.rb +26 -0
  155. data/test/dummy/config/boot.rb +5 -0
  156. data/test/dummy/config/cable.yml +9 -0
  157. data/test/dummy/config/environment.rb +5 -0
  158. data/test/dummy/config/environments/development.rb +59 -0
  159. data/test/dummy/config/environments/production.rb +86 -0
  160. data/test/dummy/config/environments/test.rb +43 -0
  161. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  162. data/test/dummy/config/initializers/assets.rb +11 -0
  163. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  164. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  165. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  166. data/test/dummy/config/initializers/inflections.rb +16 -0
  167. data/test/dummy/config/initializers/mime_types.rb +4 -0
  168. data/test/dummy/config/initializers/new_framework_defaults.rb +18 -0
  169. data/test/dummy/config/initializers/session_store.rb +3 -0
  170. data/test/dummy/config/initializers/workarea.rb +3 -0
  171. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  172. data/test/dummy/config/locales/en.yml +23 -0
  173. data/test/dummy/config/puma.rb +47 -0
  174. data/test/dummy/config/routes.rb +5 -0
  175. data/test/dummy/config/secrets.yml +22 -0
  176. data/test/dummy/config/spring.rb +6 -0
  177. data/test/dummy/config.ru +5 -0
  178. data/test/dummy/db/seeds.rb +2 -0
  179. data/test/dummy/lib/assets/.keep +0 -0
  180. data/test/dummy/log/.keep +0 -0
  181. data/test/factories/blog.rb +33 -0
  182. data/test/factories/wordpress_import.rb +17 -0
  183. data/test/fixtures/test_wordpress.xml +493 -0
  184. data/test/integration/workarea/blog/admin_integration_test.rb +55 -0
  185. data/test/integration/workarea/blog/create_blog_entries_integration_test.rb +106 -0
  186. data/test/integration/workarea/blog/storefront_integration_test.rb +112 -0
  187. data/test/integration/workarea/blog/wordpress_import_integration_test.rb +26 -0
  188. data/test/lib/workarea/blog/import/wordpress/attachment_test.rb +20 -0
  189. data/test/lib/workarea/blog/import/wordpress/content_cleaner_test.rb +65 -0
  190. data/test/lib/workarea/blog/import/wordpress/entry_parser_test.rb +42 -0
  191. data/test/lib/workarea/blog/import/wordpress/entry_test.rb +61 -0
  192. data/test/lib/workarea/blog/import/wordpress/page_parser_test.rb +35 -0
  193. data/test/lib/workarea/blog/import/wordpress/page_test.rb +52 -0
  194. data/test/models/workarea/content/blog_comment_test.rb +57 -0
  195. data/test/models/workarea/content/blog_entry_test.rb +17 -0
  196. data/test/queries/workarea/metadata/content_blog_entry_test.rb +36 -0
  197. data/test/queries/workarea/metadata/content_blog_test.rb +36 -0
  198. data/test/support/workarea/blog/stub_wordpress_assets.rb +19 -0
  199. data/test/system/workarea/admin/blog_entries_system_test.rb +103 -0
  200. data/test/system/workarea/admin/blog_system_test.rb +93 -0
  201. data/test/system/workarea/admin/blog_taxonomy_system_test.rb +21 -0
  202. data/test/system/workarea/admin/blog_user_comments_system_test.rb +138 -0
  203. data/test/system/workarea/storefront/blog_content_block_system_test.rb +36 -0
  204. data/test/system/workarea/storefront/blog_system_test.rb +256 -0
  205. data/test/test_helper.rb +9 -0
  206. data/test/view_models/workarea/admin/blog_comments_view_model_test.rb +77 -0
  207. data/test/view_models/workarea/admin/blog_entries_view_model_test.rb +36 -0
  208. data/test/view_models/workarea/storefront/blog_entry_content_block_view_model_test.rb +100 -0
  209. data/test/view_models/workarea/storefront/blog_entry_view_model_test.rb +47 -0
  210. data/test/view_models/workarea/storefront/blog_view_model_test.rb +149 -0
  211. data/test/workers/workarea/generate_content_blog_metadata_test.rb +18 -0
  212. data/workarea-blog.gemspec +19 -0
  213. metadata +274 -0
@@ -0,0 +1,112 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Blog
5
+ class StorefrontIntegrationTest < Workarea::IntegrationTest
6
+ include Storefront::IntegrationTest
7
+
8
+ setup :user
9
+ setup :blog
10
+
11
+ def user
12
+ @user ||= create_user(
13
+ email: 'test@workarea.com',
14
+ password: 'w3bl1nc',
15
+ name: 'Ben Crouse'
16
+ )
17
+ end
18
+
19
+ def login_user
20
+ post storefront.login_path,
21
+ params: {
22
+ email: user.email,
23
+ password: 'w3bl1nc'
24
+ }
25
+ end
26
+
27
+ def blog
28
+ @blog ||= create_blog(
29
+ name: 'Test',
30
+ slug: 'test',
31
+ entries: [
32
+ { name: 'Entry 1', author: 'BC1' },
33
+ { name: 'Entry 2', author: 'BC2' }
34
+ ]
35
+ )
36
+ end
37
+
38
+ def test_can_show_an_atom_feed_of_the_blog
39
+ get storefront.blog_path(@blog, format: 'atom')
40
+
41
+ assert_includes(response.body, 'Entry 1')
42
+ assert_includes(response.body, 'BC1')
43
+ assert_includes(response.body, 'Entry 2')
44
+ assert_includes(response.body, 'BC2')
45
+ end
46
+
47
+ def test_can_create_a_comment_when_logged_in
48
+ login_user
49
+
50
+ entry = @blog.entries.first
51
+ post storefront.blog_entry_comment_path(entry), params: { body: 'test comment' }
52
+
53
+ assert_equal(1, entry.comments.count)
54
+ assert_equal(@user.id.to_s, entry.comments.first.user_id)
55
+ assert_equal('test comment', entry.comments.first.body)
56
+ assert(entry.comments.first.user_info.present?)
57
+ refute(entry.comments.first.approved?)
58
+ end
59
+
60
+ def test_updates_a_users_names
61
+ login_user
62
+ entry = @blog.entries.first
63
+
64
+ @user.update_attributes(first_name: nil, last_name: nil)
65
+
66
+ post storefront.blog_entry_comment_path(entry), params: {
67
+ body: 'test comment',
68
+ first_name: 'Foo',
69
+ last_name: 'Bar'
70
+ }
71
+
72
+ @user.reload
73
+ assert_equal('Foo', @user.first_name)
74
+ assert_equal('Bar', @user.last_name)
75
+ end
76
+
77
+ def test_raises_invalid_display_unless_the_entry_is_active
78
+ entry = @blog.entries.first
79
+
80
+ entry.update_attributes!(active: false)
81
+ assert_raises(InvalidDisplay) { get storefront.blog_entry_path(entry) }
82
+ end
83
+
84
+ def test_showing_content_on_blog_show
85
+ blog_content = Workarea::Content.for(blog)
86
+ blog_content.blocks.build(
87
+ area: :header_content,
88
+ type: :text,
89
+ data: { text: 'Test blog content' }
90
+ )
91
+ blog_content.save!
92
+
93
+ get storefront.blog_path(blog)
94
+ assert(response.body.include?('Test blog content'))
95
+ end
96
+
97
+ def test_uses_thumbnail_for_og_image
98
+ entry = @blog.entries.first
99
+ asset = create_asset
100
+ get storefront.blog_entry_path(entry)
101
+
102
+ assert_select 'meta[property="og:image"]', false
103
+
104
+ entry.update!(thumbnail_image: asset.id.to_s)
105
+ get storefront.blog_entry_path(entry)
106
+ view_model = Workarea::Storefront::BlogEntryViewModel.wrap(entry)
107
+
108
+ assert_select 'meta[property="og:image"]', true, content: view_model.thumbnail_image_url
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Blog
5
+ class WordpressImportIntegrationTest < Workarea::IntegrationTest
6
+ def test_creates_all_objects
7
+ return unless running_from_source?
8
+ Rails.application.load_tasks
9
+ Rake::Task['workarea:blog:import_wordpress'].invoke(wordpress_xml_path)
10
+
11
+ entries = Workarea::Content::BlogEntry.all
12
+ assert(entries.present?)
13
+ assert_equal(4, entries.count)
14
+ assert_equal(Workarea.config.wordpress_import[:blog_name], entries.first.blog.name)
15
+
16
+ pages = Workarea::Content::Page.all
17
+ assert(pages.present?)
18
+ assert_equal(2, pages.count)
19
+
20
+ assets = Workarea::Content::Asset.all
21
+ assert(assets.present?)
22
+ assert_equal(2, assets.count)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+ require 'workarea/blog/import/wordpress/attachment'
3
+
4
+ module Workarea
5
+ module Blog
6
+ module Import
7
+ module Wordpress
8
+ class AttachmentTest < TestCase
9
+ def test_creates_a_new_asset_from_url
10
+ url = 'https://testingwordpressexports.files.wordpress.com/2018/11/person-smartphone-office-table.jpeg'
11
+
12
+ asset = Workarea::Blog::Import::Wordpress::Attachment.new(url).save
13
+ assert_equal('-2018-11-person-smartphone-office-table', asset.name)
14
+ assert_equal(['Wordpress'], asset.tags)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,65 @@
1
+ require 'test_helper'
2
+ require 'workarea/blog/import/wordpress/content_cleaner'
3
+
4
+ module Workarea
5
+ module Blog
6
+ module Import
7
+ module Wordpress
8
+ class ContentCleanerTest < TestCase
9
+ setup :asset
10
+
11
+ def asset
12
+ @asset ||= create_asset(
13
+ name: '-test-asset',
14
+ file: product_image_file
15
+ )
16
+ end
17
+
18
+ def test_updates_asset_paths
19
+ @sample_post ||= {
20
+ wordpress_hostname: 'www.example.com',
21
+ content: "<h1>This is a heading</h1><img src='https://www.example.com#{@asset.url}'/>"
22
+ }
23
+
24
+ content = Workarea::Blog::Import::Wordpress::ContentCleaner.new(@sample_post[:content], @sample_post[:wordpress_hostname]).clean
25
+
26
+ refute_includes(content, 'https://www.example.com')
27
+ end
28
+
29
+ def test_rewrites_internal_links_as_relative_path
30
+ @sample_post ||= {
31
+ wordpress_hostname: 'www.example.com',
32
+ content: "<h1>This is a heading</h1><a href='https://www.example.com/test-post-2'>Test Link</a>"
33
+ }
34
+
35
+ content = Workarea::Blog::Import::Wordpress::ContentCleaner.new(@sample_post[:content], @sample_post[:wordpress_hostname]).clean
36
+
37
+ assert_includes(content, 'href="/test-post-2"')
38
+ end
39
+
40
+ def test_rewrites_links_without_scheme
41
+ @sample_post ||= {
42
+ wordpress_hostname: 'www.example.com',
43
+ content: "<h1>This is a heading</h1><a href='www.example.com/test-post-2'>Test Link</a>"
44
+ }
45
+
46
+ content = Workarea::Blog::Import::Wordpress::ContentCleaner.new(@sample_post[:content], @sample_post[:wordpress_hostname]).clean
47
+
48
+ assert_includes(content, 'href="/test-post-2"')
49
+ end
50
+
51
+ def test_does_not_rewrite_external_links
52
+ @sample_post ||= {
53
+ wordpress_hostname: 'www.example.com',
54
+ content: "<h1>This is a heading</h1><a href='https://www.external-site.com/test-post-2'>Test External Link</a>"
55
+ }
56
+
57
+ content = Workarea::Blog::Import::Wordpress::ContentCleaner.new(@sample_post[:content], @sample_post[:wordpress_hostname]).clean
58
+
59
+ assert_includes(content, 'href="https://www.external-site.com/test-post-2"')
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,42 @@
1
+ require 'test_helper'
2
+ require 'workarea/blog/import/wordpress/entry_parser'
3
+
4
+ module Workarea
5
+ module Blog
6
+ module Import
7
+ module Wordpress
8
+ class EntryParserTest < TestCase
9
+ setup :entries
10
+
11
+ def entries
12
+ doc = Nokogiri::XML(wordpress_xml)
13
+
14
+ @entries = Workarea::Blog::Import::Wordpress::EntryParser.new(doc).parse
15
+ end
16
+
17
+ def test_creates_array_of_entries
18
+ assert(@entries.present?)
19
+ assert_instance_of(Array, @entries)
20
+ assert_equal(4, @entries.count)
21
+ end
22
+
23
+ def test_entry_hash_is_complete
24
+ entry = @entries.first
25
+ assert(entry.present?)
26
+ assert_equal("p=3", entry[:guid_path])
27
+ assert_equal("https://testingwordpressexports.wordpress.com/2018/11/15/the-journey-begins/", entry[:url])
28
+ assert_equal("the-journey-begins", entry[:new_slug])
29
+ assert_equal("testingwordpressexports.wordpress.com", entry[:wordpress_hostname])
30
+ assert_equal(['Uncategorized'], entry[:tags])
31
+ assert_equal("Thanks for joining me! <blockquote>Good company in a journey makes the way seem shorter. — Izaak Walton</blockquote><img class=\"wp-image-7 size-full\" src=\"https://twentysixteendemo.files.wordpress.com/2015/11/post.png\" alt=\"post\" width=\"1000\" height=\"563\" />", entry[:content])
32
+ end
33
+
34
+ def test_uses_configured_value_for_author
35
+ entry = @entries.first
36
+ assert_equal(Workarea.config.wordpress_import[:author_name], entry[:author])
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,61 @@
1
+ require 'test_helper'
2
+ require 'workarea/blog/import/wordpress/entry'
3
+
4
+ module Workarea
5
+ module Blog
6
+ module Import
7
+ module Wordpress
8
+ class EntryTest < TestCase
9
+ setup :blog
10
+ setup :entry_via_import
11
+
12
+ def blog
13
+ @blog = create_blog
14
+ end
15
+
16
+ def entry_via_import
17
+ @post_hash = {
18
+ guid_path: 'https://www.example.com/?p=1',
19
+ title: 'Test Post Title',
20
+ url: 'https://www.example.com/path/to/test-post',
21
+ new_slug: 'test-post',
22
+ published?: true,
23
+ published_date: Time.now,
24
+ tags: ['Wordpress Tag', 'Uncategorized'],
25
+ author: Workarea.config.wordpress_import[:author_name],
26
+ content: "<h1>This is a heading</h1>",
27
+ wordpress_hostname: 'https://www.example.com'
28
+ }
29
+
30
+ @entry = Workarea::Blog::Import::Wordpress::Entry.new(@post_hash, @blog).save
31
+ end
32
+
33
+ def test_creates_the_entry
34
+ assert(@entry.present?)
35
+ assert_equal(@post_hash[:title], @entry.name)
36
+ end
37
+
38
+ def test_html_block_for_entry_is_created
39
+ model = Workarea::Content.for(@entry)
40
+
41
+ assert_equal(1, model.blocks.size)
42
+ assert_equal(:html, model.blocks.first.type_id)
43
+ end
44
+
45
+ def test_creates_a_redirect_for_the_entry
46
+ redirect = Workarea::Navigation::Redirect.find_by(path: '/path/to/test-post')
47
+
48
+ assert(redirect.present?)
49
+ assert_equal("/blog_entries/#{@post_hash[:new_slug]}", redirect[:destination])
50
+ end
51
+
52
+ def test_does_not_create_an_entry_if_one_exists
53
+ Workarea::Blog::Import::Wordpress::Entry.new(@post_hash, @blog).save
54
+
55
+ assert_equal(1, @blog.entries.size)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+ require 'workarea/blog/import/wordpress/page_parser'
3
+
4
+ module Workarea
5
+ module Blog
6
+ module Import
7
+ module Wordpress
8
+ class PageParserTest < TestCase
9
+ setup :pages
10
+
11
+ def pages
12
+ doc = Nokogiri::XML(wordpress_xml)
13
+
14
+ @pages = Workarea::Blog::Import::Wordpress::PageParser.new(doc).parse
15
+ end
16
+
17
+ def test_creates_array_of_pages
18
+ assert(@pages.present?)
19
+ assert_instance_of(Array, @pages)
20
+ assert_equal(2, @pages.count)
21
+ end
22
+
23
+ def test_page_hash_is_complete
24
+ page = @pages.first
25
+ assert(page.present?)
26
+ assert_equal("page_id=2", page[:guid_path])
27
+ assert_equal("https://testingwordpressexports.wordpress.com/contact/", page[:url])
28
+ assert_equal("contact", page[:new_slug])
29
+ assert_equal('[contact-form][contact-field label="Name" type="name" required="1"/][contact-field label="Email" type="email" required="1"/][contact-field label="Comment" type="textarea" required="1"/][/contact-form]', page[:content])
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,52 @@
1
+ require 'test_helper'
2
+ require 'workarea/blog/import/wordpress/page'
3
+
4
+ module Workarea
5
+ module Blog
6
+ module Import
7
+ module Wordpress
8
+ class PageTest < TestCase
9
+ setup :page_via_import
10
+
11
+ def page_via_import
12
+ @page_hash = {
13
+ guid_path: 'https://www.example.com/?page=1',
14
+ page_title: 'Test Page Title',
15
+ url: 'https://www.example.com/path/to/test-page',
16
+ new_slug: 'test-page',
17
+ published?: true,
18
+ content: "<h1>This is a heading</h1>"
19
+ }
20
+
21
+ @page = Workarea::Blog::Import::Wordpress::Page.new(@page_hash).save
22
+ end
23
+
24
+ def test_creates_the_page
25
+ assert(@page.present?)
26
+ assert_equal(@page_hash[:page_title], @page.name)
27
+ end
28
+
29
+ def test_html_block_for_page_is_created
30
+ model = Workarea::Content.for(@page)
31
+
32
+ assert_equal(1, model.blocks.size)
33
+ assert_equal(:html, model.blocks.first.type_id)
34
+ end
35
+
36
+ def test_creates_a_redirect_for_the_entry
37
+ redirect = Workarea::Navigation::Redirect.find_by(path: '/path/to/test-page')
38
+
39
+ assert(redirect.present?)
40
+ assert_equal("/pages/#{@page_hash[:new_slug]}", redirect[:destination])
41
+ end
42
+
43
+ def test_does_not_create_a_page_if_one_exists
44
+ Workarea::Blog::Import::Wordpress::Page.new(@page_hash).save
45
+
46
+ assert_equal(1, Workarea::Content::Page.count)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,57 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class Content::BlogCommentTest < TestCase
5
+ setup :blog
6
+
7
+ def blog
8
+ @blog ||= create_blog(name: 'Test Blog',
9
+ entries: [
10
+ { name: 'Entry 1', author: 'BC' }
11
+ ])
12
+ end
13
+
14
+ def test_self_sorts_includes_pending_sort_if_pending_comments_present
15
+ entry = blog.entries.first
16
+ entry.comments.create(
17
+ user_id: 'user1',
18
+ body: 'this is a test comment',
19
+ pending: true
20
+ )
21
+ entry.comments.create(
22
+ user_id: 'user2',
23
+ body: 'this is another test comment',
24
+ pending: false
25
+ )
26
+
27
+ assert_equal([Sort.pending, Sort.newest], Workarea::Content::BlogComment.sorts)
28
+ end
29
+
30
+ def test_self_sorts_excludes_pending_sort_if_pending_comments_absent
31
+ assert_equal([Sort.newest], Workarea::Content::BlogComment.sorts)
32
+ end
33
+
34
+ def test_update_count_updates_the_posts_comment_count
35
+ entry = blog.entries.first
36
+ entry.comments.create!(
37
+ user_id: 'user2',
38
+ body: 'this is another test comment',
39
+ pending: false,
40
+ approved: true
41
+ )
42
+
43
+ assert_equal(1, entry.comment_count)
44
+ end
45
+
46
+ def test_update_count_does_not_change_the_post_updated_at_value
47
+ entry = blog.entries.first
48
+ entry.comments.create!(
49
+ user_id: 'user2',
50
+ body: 'this is another test comment',
51
+ pending: false
52
+ )
53
+
54
+ assert_equal(entry.created_at, entry.updated_at)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class Content::BlogEntryTest < TestCase
5
+ setup :blog
6
+
7
+ def blog
8
+ @blog ||= create_blog(name: 'Test Blog')
9
+ end
10
+
11
+ def test_newest_sort
12
+ first = blog.entries.create!(name: 'One', author: 'BC', updated_at: Time.now + 1.day)
13
+ second = blog.entries.create!(name: 'Two', author: 'BC', updated_at: Time.now - 1.day)
14
+ assert_equal([first, second], blog.entries.newest.to_a)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,36 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class Metadata
5
+ class ContentBlogEntryTest < TestCase
6
+ setup :set_page_and_metadata
7
+
8
+ def set_page_and_metadata
9
+ @entry = create_blog_entry(blog: create_blog)
10
+ @content = Content.for(@entry)
11
+ @metadata = ContentBlog.new(@content)
12
+ end
13
+
14
+ def test_defaults_to_blog_title
15
+ assert_equal('Test Entry', @metadata.title)
16
+ end
17
+
18
+ def test_includes_parent_taxon_if_available
19
+ category = create_category(name: 'Bar')
20
+ taxon = create_taxon(name: 'Bar', navigable: category)
21
+ create_taxon(name: 'Foo', parent: taxon, navigable: @entry)
22
+
23
+ assert_equal('Test Entry - Bar', @metadata.title)
24
+ end
25
+
26
+ def test_defaults_to_text_extracted_from_content_blocks
27
+ @content.blocks.create!(
28
+ type: 'html',
29
+ data: { html: '<p>Lorem ipsum dolor</p>' }
30
+ )
31
+
32
+ assert_equal('Lorem ipsum dolor', @metadata.description)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class Metadata
5
+ class ContentBlogTest < TestCase
6
+ setup :set_page_and_metadata
7
+
8
+ def set_page_and_metadata
9
+ @blog = create_blog(name: 'Foo')
10
+ @content = Content.for(@blog)
11
+ @metadata = ContentBlog.new(@content)
12
+ end
13
+
14
+ def test_defaults_to_blog_title
15
+ assert_equal('Foo', @metadata.title)
16
+ end
17
+
18
+ def test_includes_parent_taxon_if_available
19
+ category = create_category(name: 'Bar')
20
+ taxon = create_taxon(name: 'Bar', navigable: category)
21
+ create_taxon(name: 'Foo', parent: taxon, navigable: @blog)
22
+
23
+ assert_equal('Foo - Bar', @metadata.title)
24
+ end
25
+
26
+ def test_defaults_to_text_extracted_from_content_blocks
27
+ @content.blocks.create!(
28
+ type: 'html',
29
+ data: { html: '<p>Lorem ipsum dolor</p>' }
30
+ )
31
+
32
+ assert_equal('Lorem ipsum dolor', @metadata.description)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ require 'webmock/minitest'
2
+
3
+ module Workarea
4
+ module Blog
5
+ module StubWordpressAssets
6
+ extend ActiveSupport::Concern
7
+
8
+ included { setup :stub_wordpress_assets }
9
+
10
+ def stub_wordpress_assets
11
+ stub_request(:get, 'https://testingwordpressexports.files.wordpress.com/2018/11/person-smartphone-office-table.jpeg')
12
+ .to_return(body: 'abc', headers: { 'Content-Type': /image\/.+/ })
13
+
14
+ stub_request(:get, 'https://testingwordpressexports.files.wordpress.com/2018/11/person-smartphone-office-table2.jpeg')
15
+ .to_return(body: 'abc', headers: { 'Content-Type': /image\/.+/ })
16
+ end
17
+ end
18
+ end
19
+ end