The quoted post states that for prime $p$, the order $k$ of any element $g$ of $\mathbb Z_p^*$ divides $p-1$. That is because $\mathbb Z_p^*$, or equivalently $\{1,\ldots,p-1\}$, is a group of $p-1$ elements under multiplication modulo $p$, and then a consequence of (one of) Lagrange's theorem.
If an element $g$ has order $k$ that divides $p-1$, then by definition of divides there is some (uniquely defined) integer $u\ge1$ such that $p-1=k\,u$. The element $g$ is of order $p-1$ if and only if that $u$ is $1$.
If $u$ is not $1$, then there is some prime $q$ dividing $u$ (thus $q$ dividing also $p-1)$, and some integer $v\ge1$ with $u=q\,v$, thus with $p-1=k\,q\,v$; and since $g$ has order $k$, it holds $g^k\bmod p=1$, therefore $\left(g^k\right)^v\bmod p=1$, therefore $g^{k\,v}\bmod p=1$, therefore $g^{(p-1)/q}\bmod p=1$.
Hence if $g$ is not of order $p-1$, then there is some prime $q$ dividing $p-1$ such that $g^{(p-1)/q}\bmod p=1$.
By contraposition, if for every prime $q$ dividing $p-1$ it holds $g^{(p-1)/q}\bmod p\ne1$, then $g$ is of order $p-1$.
Note: sometime, $p$ is chosen as a safe prime, meaning $p$ and $(p-1)/2$ are prime. A test that $g$ is a generator (that is, has the maximal order $p-1$) then boils down to $g^2\bmod p\ne1$ (equivalently, $g\bmod p\ne1$ and $g\bmod p\ne p-1$ ) and $g^{(p-1)/2}\bmod p\ne1$. For a test that $g$ has (prime) order $(p-1)/2$, replace that last test with $g^{(p-1)/2}\bmod p=1$.