Thanks to visit codestin.com
Credit goes to github.com

Skip to content

test: Phase 2 — Unit tests for Model/Poll, Feedback and Voter (#13)#17

Open
sabbir1991 wants to merge 13 commits into
developfrom
feature/issue-13-phase-2-model-tests
Open

test: Phase 2 — Unit tests for Model/Poll, Feedback and Voter (#13)#17
sabbir1991 wants to merge 13 commits into
developfrom
feature/issue-13-phase-2-model-tests

Conversation

@sabbir1991

@sabbir1991 sabbir1991 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • New: tests/Unit/Model/PollTest.php — 7 tests covering Poll::vote(): validation short-circuits (empty options, poll closed, login required), DB insert failure, success path, sensitive field stripping, and view-result confirmation with template rendering
  • Expanded: tests/Unit/Model/FeedbackTest.php — 8 new tests covering is_valid_poll_option(), get_settings(), get_data(), get_options(), get_response()
  • Expanded: tests/Unit/Model/VoterTest.php — 4 new tests covering get_user_agent(), Class B private IP range in is_local_ip(), Cloudflare CF-Connecting-IP header, and X-Forwarded-For ignored when proxy not trusted

All tests follow the established patterns from VotesTest.php: same $wpdb anonymous-class mock, same Brain\Monkey stubs in setUp(), same mock_poll_cache() helper for FeedbackManager::get() cache hits.

Test plan

  • composer test — 125 tests, 206 assertions, 0 failures
  • composer cs — PHPCS passes on all production code
  • No PHP warnings in any test (added status key to settings defaults to satisfy is_poll_closed())

Closes #13


Generated by Claude Code

Test in WP Playground

▶ Test in WP Playground

claude and others added 13 commits June 5, 2026 10:26
Regenerated by composer install after dev dependencies (Brain\Monkey,
wp-phpunit, phpunit polyfills) were resolved for the PHPUnit testing setup.

https://claude.ai/code/session_01H4AnuTdcudBToKnMKmQb54
…n trait (#12)

- Add POLLIFY_FILTER_SANITIZE_STRING, POLLIFY_PATH constants and require
  helpers/functions.php in tests/bootstrap.php
- tests/Unit/Helpers/FunctionsTest.php — covers all functions in
  includes/helpers/functions.php (country name, formatted votes,
  shorthand styles, border styles, block filtering, load template,
  filter input, nav, display IP)
- tests/Unit/FeedbackFactoryTest.php — covers constructor (array/object
  input), get() error cases (empty/unknown type), Poll instantiation,
  data hydration, get_class_map(), and filter-extended map via
  @runInSeparateProcess
- tests/Unit/Traits/SingletonTest.php — covers same-instance guarantee,
  init action fires once, action not fired on repeated calls, distinct
  instances for distinct classes

107 tests, 165 assertions — all passing

https://claude.ai/code/session_01H4AnuTdcudBToKnMKmQb54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: Phase 2 — Unit tests for Model/Poll.php and expansion of Feedback + Voter tests

2 participants